Author Archives: admin

Ruby Array

Was curious which is faster.

Rehearsal ----------------------------------------------
<<           0.099701   0.017560   0.117261 (  0.117427)
push         0.110768   0.007844   0.118612 (  0.118719)
------------------------------------- total: 0.235873sec

                 user     system      total        real
<<           0.063531   0.002646   0.066177 (  0.066220)
push         0.099184   0.004992   0.104176 (  0.104228)

Code:

require 'benchmark'

Benchmark.bmbm(10) do |bm|
  bm.report('<<') do
    a = []
    1000000.times do
      a << 'foo'
    end
  end

  bm.report('push') do
    a = []
    1000000.times do
      a.push 'foo'
    end
  end
end

My Language Ranking Based on Coolness

With so many sites measuring programming language popularity, here’s the coolness, not popularity ranking of languages ranking by me. This is my PERSONAL opinion.

1. Ruby – need I say more? 😉
2. Objective-C
3. Go
4. C, not C++
5. Coffeescript – yes, I said it, ok?
6. Haskell
7. R
8. Swift

Install Ruby 2.3.1 from Source on Ubuntu 16.04

Execute this as the root user. If not, you can always add sudo. Here’s the script:


#!/bin/bash

set -e

apt-get update
apt-get install -y curl build-essential libreadline-dev \
libffi-dev zlib1g-dev openssl vim \
libncurses5-dev libcurl4-openssl-dev \
libgdbm-dev libqdbm-dev libssl-dev
apt-get autoremove && apt-get autoclean
curl -O https://cache.ruby-lang.org/pub/ruby/2.3/ruby-2.3.1.tar.gz
tar xvzf ruby-2.3.1.tar.gz
cd ruby-2.3.1
./configure
make && make install
cd ..
rm -rf ruby-2.3.1*
echo "gem: --no-ri --no-rdoc
install: --no-ri --no-rdoc
update: --no-ri --no-rdoc" > /usr/local/etc/gemrc

gem install bundler pry interactive_editor

Simple Web Server with Ruby or Python

I was developing a Javascript app and wanted to run a web server pointing to current directory.

Using Ruby

A simple script to start a WEBrick server. You can modify the root directory to a subfolder if you’d like. I named this script “server” with chmod +x so I can run it with ./server

#!/usr/bin/env ruby

require 'webrick'

server = WEBrick::HTTPServer.new(Port: 8000, DocumentRoot: ".")
Signal.trap('INT') { server.shutdown }
server.start

Python

A simple command using python -m SimpleHTTPServer