Nextjournal / Dec 16 2019
Ruby Environment
Default environment for Ruby
This notebook describes and creates the default Ruby environment in Nextjournal. Check out the showcase if you want to see what the environment contains. To see how it’s built, see setup.
Nextjournal's Ruby environment uses the iRuby kernel, and has Ruby v2.6.3 installed via ruby-install v0.7.0, as well as the latest versions of packages in sciruby-full.
Showcase
Plotting
Gnuplot
require 'gnuplot'Gnuplot::Plot.new do |plot| plot.xrange '[-0.5:0.5]' plot.title 'Example plot' plot.ylabel 'x' plot.xlabel 'sin(1/x)' plot.samples 10000 plot.data << Gnuplot::DataSet.new('sin(1/x)') do |ds| ds.with = 'lines' ds.linewidth = 2 endend0.4s
Ruby Test (Ruby 2.6.3)
Ruby
Gnuplot::SPlot.new do |plot| plot.title 'Spiral' plot.nokey plot.parametric plot.hidden3d plot.view '80,50' plot.isosamples '60,15' plot.xrange '[-8:8]' plot.yrange '[-8:8]' plot.zrange '[-8:8]' plot.urange '[-2*pi:2*pi]' plot.vrange '[-pi:pi]' plot.data << Gnuplot::DataSet.new('cos(u)*(cos(v)+3), sin(u)*(cos(v)+3), sin(v)+u') do |ds| ds.with = 'lines' endend0.2s
Ruby Test (Ruby 2.6.3)
Ruby
Rubyvis
require 'rubyvis' Rubyvis::Panel.new do width 150 height 150 bar do data [1, 1.2, 1.7, 1.5, 0.7, 0.3] width 20 height {|d| d * 80} bottom(0) left {index * 25} endend1.2s
Ruby Test (Ruby 2.6.3)
Ruby
require 'daru'df = Daru::DataFrame.new({ a: Array.new(100) {|i| i}, b: 100.times.map{rand}})plot = df.plot type: :scatter, x: :a, y: :bplot.export_html("/results/out.html")0.3s
Ruby Test (Ruby 2.6.3)
Ruby
cat NJ__REF_0.8s
Ruby Test (Bash in Ruby 2.6.3)
Ruby
Setup
Install Ruby
Install dependencies.
apt-get -qq updateDEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends \ libyaml-dev libgdbm-dev libgsl-dev libsqlite3-dev libatlas-base-dev \ libmagick++-dev imagemagick \ bison gnuplot-nox apt-get cleanrm -r /var/lib/apt/lists/*ln -sf /usr/bin/libtoolize /usr/bin/libtool38.6s
Ruby (Bash)
Download ruby-install.
FILENAME="ruby-install-${RUBYINST_VERSION}.tar.gz"FILEURL="https://github.com/postmodern/ruby-install/archive/v${RUBYINST_VERSION}.tar.gz"wget --progress=dot -O /results/$FILENAME $FILEURL1.2s
Ruby (Bash)
Install ruby-install.
tar -xzvf NJ__REF_cd ruby-install-${RUBYINST_VERSION}/sudo make install1.0s
Ruby (Bash)
Install our version of Ruby.
ruby-install ruby ${RUBY_VERSION}410.8s
Ruby (Bash)
Link our version to the PATH setting.
ln -fs /opt/rubies/ruby-${RUBY_VERSION}/bin /opt/rubies/0.2s
Ruby (Bash)
Update gem list.
gem update --no-document --system6.3s
Ruby (Bash)
Building sciruby-full fails now, so install the full gem list from it but with no version restrictions. Do rbczmq first because it needs special flags.
CPPFLAGS='-Wno-error=deprecated-declarations' \ gem install --no-document rbczmqgem install --no-document \ ai4r algorithms awesome_print bibsync bibtex-ruby bio classifier-reborn ctioga2 daru darwinning decisiontree distribution extendmatrix gga4r gimuby gnuplot gnuplotrb gruff gsl hamster histogram integration iruby liblinear-ruby measurable mikon minimization nmatrix nyaplot parallel phys-units plotrb pry rb-libsvm rserve-client ruby-fann ruby-minisat rubyvis sciruby statsample statsample-bivariate-extension statsample-glm statsample-timeseries tioga unit \ ffi-rzmq narray # narray added for gsl564.9s
Ruby (Bash)
iruby register0.4s
Ruby (Bash)
du -hsx /jupyter kernelspec list4.8s
Ruby (Bash)
Test
class Hello def initialize(greet) @greet = greet end def say() puts "Hello, #{@greet}" endendHello.new("world").say()0.4s
Ruby Test (Ruby 2.6.3)
Ruby