Digest Gem Ruby 2.6

Digest gem on ruby 2.6 is part of standard library. No need to do “gem install digest” anymore ! Here is proof on NetBSD 9.

Sinatra Ruby web app server on NetBSD 9

To host sinatra ruby web application on NetBSD 9 we need to install apache http server, ruby, and passenger.

To install ruby 2.6, login as root and do pkgin install ruby. This will automatically install ruby version 2.6. After installed, install sinatra and your other gems using gem install sinatra.

Next is to install apache http server. On terminal execute pkgin install apache. Copy rc.d script from /usr/pkg/share/examples/rc.d/apache to /etc/rc.d folder (this step just following after install message). Edit /etc/rc.conf and add a line containing apache=YES to enable auto start of apache on system start up.

Install passenger module to apache by executing pkgin install ap24-ruby26-passenger. After install edit /usr/pkg/etc/httpd/httpd.conf and add as follow.

LoadModule passenger_module lib/httpd/mod_passenger.so
<IfModule mod_passenger.c>
  PassengerRoot /usr/pkg/lib/ruby/vendor_ruby/2.6.0/phusion_passenger/locations.ini
  PassengerRuby /usr/pkg/bin/ruby26
</IfModule>

Install sqlite3 gem

To install sqlite3 gem we need to install development package for ruby and sqlite3 it self because of the need to compile gem native extension.

On ubuntu/mint/debian do as follow :

apt-get install ruby-dev

apt-get install libsqlite3-dev

Dont forget to execute as root.

After that we can execute gem install sqlite3.

Thats all … Bye.

Happy chinesse new year 2570 !

Ruby interaction with command line

Ruby have a way to execute command line program using back tick. Enclosed our statement to be executed by command line using back tick.

Lets try using back tick on irb !

we can put the output to a variable to process it like sample below.

ls is a command to list content of your file system, if you wonder …

bye and good night …

Alternative Syntax of Ruby Hashes

Hashes variant 1

cars = { “car1” => “avanza”, “car2” => “innova”, “car3” => “mirage” }

Hashes variant 2

cars = {  :car1 => “avanza”,  :car2 => “innova”,  :car3 => “mirage” }

Hashes variant 3

cars = {  car1: “avanza”,  car2: “innova”,  car3: “mirage” }

 

These are as far as i know.

Bluefish editor for programming

If you a programmer you can use vi or vim or nano to code. Sometimes it just not enough feature or give comfort. I use an editor called bluefish. Install it from package like this :

For openbsd do pkg_add bluefish

If installing for openbsd dont forget to set your PKG_PATH env variable.

For Dragonfly BSD do pkg install bluefish

Bluefish have a good support for html tags and ruby language. See bluefish screenshot below.

Happy coding all !

 

Ruby Unique Feature – Block

Block is an interesting ruby languange feature. Block is statements enclosed together using do end or curly braces {}. We can find block in action at code that iterating  an array variable.

Lets try block on irb (interactive ruby)  !!!

Sample above creating variable x which is an array of string. Next command iterating the array using each method and a block passed to it. The block have a parameter named n and n will contain each array element passed to it by each method. Code inside block print output to screen.

Below is an example of block using curly braces.

That is simple examples of block in ruby language. It is an unique and usefull feature.

Bye for now !