1. HTTPerf.rb 0.3.11 Released

    Adding tee support, which will print any httperf (both STDOUT and STDERR) output to STDOUT while running the process.

    Continue reading

    Published on in Gems by RubyOps, Httperf, HTTPerf.rb, Ruby

    Comment


  2. Using curl to Test HTTPS with Self Signed Certs

    $ curl https://<domain>/path/to.html --insecure
    

    Also see: HTTPS: Creating Slef-signed Certs.

    Published on in Hacks, Linux

    Comment


  3. Comparing Load Balancing Options: Nginx vs. HAProxy vs. AWS ELB

    Recently I've done a bit of research on the differences between Nginx, HAProxy and AWS ELB when being used as a Load Balancer. I put together a line by line comparison for a friend of mine and thought I would share my results. Pretty interesting for us as our Web Design Agency in Nottingham tends to work with some pretty big clients who require this.

    Continue reading

    Published on

    Comment


  4. HTTPS: Creating Slef-signed Certs

    Occasionally, I need to create self-signed certs when testing application through https. This isn't really the best way to do it, as it will require anyone visiting to confirm a security exception, but it's useful in a pinch.

    Continue reading

    Published on in Linux

    Comment


  5. LA Ruby Conf

    LA Ruby Conf

    I'll be there, say "Hello"!

    Published on in Ruby

    Comment


  6. Installing Node.js on CentOS

    I wrote the following script to install Node.js on CentOS to handle a Rails missing a JavaScript runtime environment error.

    #!/usr/bin/env bash
    set -ue
    sudo echo "Ensure sudo access."
    sudo touch /etc/yum.repos.d/naulinux-extras.repo
    sudo sh -c "echo '[naulinux-extras]
    name=NauLinux Extras
    baseurl=http://downloads.naulinux.ru/pub/Naulinux.html6.2/\$basearch/Extras/RPMS/
    enabled=0
    gpgcheck=1
    gpgkey=http://downloads.naulinux.ru/pub/Naulinux.htmlRPM-GPG-KEY-linux-ink
    ' > /etc/yum.repos.d/naulinux-extras.repo"
    sudo yum --enablerepo=naulinux-extras install nodejs
    

    Published on in Linux

    Comment


  7. Securing Redis via IPTables

    Here's a simple script to secure Redis via IPTables (tested on CentOS 6.3):

    #!/usr/bin/env bash
    # redis_secure.sh
    # this script will add an ip address to iptables
    # allowing the ip address to connect to redis
    # should be run with localhost first
    IPADDRESS="$1"
    if ! test "$IPADDRESS"; then
        echo "Please enter the IP Address you want to be able to connection to Redis."
        exit 1
    fi
    sudo iptables -A INPUT -s $IPADDRESS -p tcp -m tcp --dport 6379 -j ACCEPT
    sudo bash -c 'iptables-save > /etc/sysconfig/iptables'
    

    Then run as follows:

    $ ./redis_secure.sh localhost
    $ ./redis_secure.sh 555.555.555.555 # < your ip goes here
    

    Published on in Linux

    Comment


  8. Ready Player One

    Ready Player One

    If you're reading this blog, you're most likely a geek like me. Read this book, you won't regret it.

    ready player one

    Published on

    Comment


  9. 'starts_with?', 'end_with?' and 'include?' vs. RegExp

    A co-worker of mine pointed out today that using Ruby's native methods for string matching is actually faster then using regular expressions. This was hard for me to believe to so I benchmarked them.

    Setup the Benchmark

    [1] pry(main)> require 'benchmark'
    => true
    [2] pry(main)> test_string = "/foo/bar/bah/bing"
    => "/foo/bar/bah/bing"
    

    String#starts_with?

    [3] pry(main)> Benchmark.realtime { (1..10000).to_a.each { %r{^/foo}.match(test_string) } }
    => 0.009987447
    [4] pry(main)> Benchmark.realtime { (1..10000).to_a.each { test_string.start_with?("foo") } }
    => 0.003103276
    

    String#end_with?

    [5] pry(main)> Benchmark.realtime { (1..10000).to_a.each { %r{bing$}.match(test_string) } }
    => 0.015837275
    [6] pry(main)> Benchmark.realtime { (1..10000).to_a.each { test_string.end_with?("bing") } }
    => 0.005633547
    

    String#include?

    [7] pry(main)> Benchmark.realtime { (1..10000).to_a.each { %r{^.*bar.*$}.match(test_string) } }
    => 0.025630178
    [8] pry(main)> Benchmark.realtime { (1..10000).to_a.each { test_string.include?("bar") } }
    => 0.010360719
    

    Published on in Benchmarking in Ruby, Ruby

    Comment


  10. Killing Caps Lock on Ubuntu

    1. Create xmodmap file:

       $ xmodmap -pke > ~/.xmodmap
      
    2. Edit the newly created ~/.xmodmap file, changing the line starting with keycode 66 = to map to a key of your choice. Here's an example where I'm mapping Caps Lock to the Escape key:

       keycode  66 = Escape NoSymbol Escape
      
    3. Load your new map, disabling Caps Lock:

       xmodmap ~/.xmodmap
      
    4. (optionally) You can set this to autostart when you launch Unity by creating the following file:

       $ cat .config/autostart/xmodmap.desktop
       [Desktop Entry]
       Type=Application
       Exec=xmodmap ~/.xmodmap
       Hidden=false
       NoDisplay=false
       X-GNOME-Autostart-enabled=true
       Name[en_US]=xmodmap
       Name=xmodmap
       Comment[en_US]=
       Comment=
      

    Published on in Hacks, Linux

    Comment


  11. Quick Benchmarking One Liner

    This is useful when you're quickly trying to decide between two methods of performing an action.

    [1] pry(main)> u = "/foo/bar/"
    => "/foo/bar/"
    [2] pry(main)> Benchmark.realtime { u.split("/").join("::") } > Benchmark.realtime { u.gsub("/", "::").gsub(/::$/, "") }
    => false
    [3] pry(main)> u.split("/").join("::")
    => "::foo::bar"
    [4] pry(main)> u.gsub("/", "::").gsub(/::$/, "")
    => "::foo::bar"
    

    As you can see, the first method u.split("/").join("::") is faster.

    Published on in Benchmarking in Ruby, Ruby

    Comment


  12. Alternatives to OpenStruct

    OpenStruct is bad. Here are two quick alternatives.

    Continue reading

    Published on in Ruby

    Comment


  13. Fast Hostname Completion with ZSH

    Credit goes to this post for this: http://nion.modprobe.de/blog/archives/521-hostname-completion-with-zsh.html

    In your ~/.zshrc

    local knownhosts
    knownhosts=( ${${${${(f)"$(<$HOME/.ssh/known_hosts)"}:#[0-9]*}%%\ *}%%,*} )
    zstyle ':completion:*:(ssh|scp|sftp):*' hosts $knownhosts
    

    In your ~/.ssh/config

    HashKnownHosts no
    

    Published on in Hacks, Linux, ZSH

    Comment


  14. Dilbert: Cloudwash

    Dilbert: Cloudwash

    from Dilbert Daily Strip http://dilbert.com/.

    Published on in Humor

    Comment


  15. Thin Wrapper Script

    Their may be others, there may be better, but this is mine.

    # file: APP_ROOT/thin.sh
    #
    #!/usr/bin/env bash
    # source config if present
    test -f ./config/thinrc && source ./config/thinrc
    # set up primary defaults
    test "$RACK_ENV"  || RACK_ENV="development"
    test "$THIN_PORT" || THIN_PORT="4321"
    test "$THIN_PID"  || THIN_PID="./log/listener.pid"
    test "$THIN_LOG"  || THIN_LOG="./log/listener.log"
    test "$DEBUG"     && set -x
    if ! test "$1"
    then
        echo "Usage: listener start|stop|restart"
        echo " "
        echo "Takes the following overides as environemnt variables:"
        echo " "
        echo "  RACK_ENV  :: default $RACK_ENV"
        echo "  THIN_PORT :: default $THIN_PORT"
        echo "  THIN_PID  :: default $THIN_PID"
        echo "  THIN_LOG  :: default $THIN_LOG"
        echo " "
        echo "Takes config file as './config/thinrc' with overides above. "
        echo " "
        exit 0
    fi
    RACK_ENV=$RACK_ENV thin --port $THIN_PORT --pid $THIN_PID --log $THIN_LOG --daemonize $1
    # vim: set filetype=sh
    

    gist


    And if you need external configs...

    # file: APP_ROOT/config/thinrc
    #
    # Directory pathing context should be that of the thin
    # init script sourcing this file, not this file itself.
    #
    # allow for overides as such
    test "$RACK_ENV"  || RACK_ENV="production"
    test "$THIN_PORT" || THIN_PORT="4321"
    test "$THIN_PID"  || THIN_PID="./log/listener.pid"
    test "$THIN_LOG"  || THIN_LOG="./log/listener.log"
    # force defaults as such
    #RACK_ENV="development"
    #THIN_PORT="4321"
    #THIN_PID="./log/listener.pid"
    #THIN_LOG="./log/listener.log"
    # vim: set filetype=sh
    

    gist

    What is Thin?


    Published on in Hacks, Ruby

    Comment


  16. Rails script/server Unicorn Replacement

    A script to replace script/server in Rails, which runs Unicorn over Webrick, because it's faster. This script is designed for development only!

    Continue reading

    Published on in Hacks, Ruby

    Comment


  17. Minimum Version Checking with BASH/ZSH

    The following line will print zsh version information if the version is greater then or equal to 4.3.17, otherwise it will return blank:

    zsh --version | awk '{print $2}' | awk -F'.' ' ( $1 > 4 || ( $1 == 4 && $2 > 3 ) || ( $1 == 4 && $2 == 3 && $3 >= 17 ) ) '
    

    An example usage would be something like:

    #!/usr/bin/env bash
    if test "$( zsh --version | awk '{print $2}' | awk -F'.' ' ( $1 > 4 || ( $1 == 4 && $2 > 3 ) || ( $1 == 4 && $2 == 3 && $3 >= 17 ) ) ' )"
    then
        # do someting that only higher zsh versions support
    else
        # do something else for low versions
    fi
    

    Published on in Hacks, Linux, ZSH

    Comment


  18. VIM Tips and Tricks

    These are basically my notes on VIM, and some of the things I've found along the way. I expect that this will be something that continues to grow over time.

    Continue reading

    Published on in vim

    Comment


  19. vim-gist is cool!

    Just came across this VIM plugin which is too cool not to share. I gives you the ability to post and edit gists right from VIM. Check it out!

    mattn/gist-vim

    Published on in vim

    Comment


  20. Fixing Backlight on the HP Folio 13 when using Linux

    This is something I ran in to when origionally setting up my Folio, which I did not post on. However, today a co-worker asked me how to solve this problem, so I thought I should jot it down for future reference.

    1. Open your grub config: sudo vi /etc/default/grub.
    2. Update the line containing GRUB_CMDLINE_LINUX_DEFAULT, adding acpi_backlight=vendor to the end. It should look something like this when you're done:

       # file: /etc/default/grub
       # ...
       GRUB_CMDLINE_LINUX_DEFAULT="quiet splash acpi=on acpi_backlight=vendor"
       # ...
    3. Save and update grub with sudo update-grub.

    4. Reboot and you should have a display.

    Note: You will need to use an external monitor or drop in to grub's preboot command line and add the above to be able to see your screen before adding the above option.

    Published on in Linux

    Comment


  21. RVM, irb, readline and Ubuntu

    It's as easy as:

    sudo apt-get install libreadline-gplv2-dev
    rvm remove ruby-1.9.3-p194
    rvm install ruby-1.9.3-p194
    

    Done.

    Notes:

    1. Do not use rvm pkg install readline.
    2. "1.9.3-p194" is an example, should work with most versions.

    Published on in Linux, Ruby

    Comment


  22. Web Pasting with "gistcli"

    Found this simple Python script which allows for cli gist posts -- (thanks to pranavk).

    You can install it like so

    $ mkdir ~/bin
    $ echo "export PATH=~/bin:$PATH" >> ~/.zshrc
    $ cd ~/bin
    $ wget https://raw.github.com/pranavk/gist-cli/master/gistcli
    $ chmod 755 gistcli
    $ source ~/.zshrc
    

    Usage examples

    # simple echo to gist
    echo "test gist" | gistcli
    # file to gist
    gistcli -f myfile.txt
    # private
    echo "ssssh, don't tell anyone!" | gistcli -p
    # from tty, EOF from '.' on it's own line
    gistcli -
    Foo, bar bah bing!
    .
    

    Note: There's also a slightly more mature Ruby gist cli tool at github.com/defunkt/gist but I had issues getting it to work with my RMV setup.

    Published on in Hacks, Linux

    Comment


  23. Syntax Highlighting on Nesta

    I recently went through setting up syntax highlighting on Nesta for this site. I started with "Setting up rack-codehighlighter" from the Nesta site, but wasn't loving what Coderay had to offer. Looking at 'rack-codehighlighter' and it's other formatter options and decided to use Ultraviolet.

    While this is geared towards Nesta, this will also work for all Rack applications, especially those built on Sinatra.

    Continue reading

    Published on in Nesta, Rack, Ruby, Sinatra

    Comment


  24. Hack: Deploying with git

    Add the following to your Rakefile

    ENV['PRODUCTION_HOST'] ||= "www.yourhost.com"
    task :deploy do
      system("ssh #{PRODUCTION_HOST} 'set -x; cd /path/to/app/install && git pull && bundle'")
    end
    desc "restart production" 
    task :restart do
      system("ssh #{PRODUCTION_HOST} 'set -x; cd /path/to/app/install && RACK_ENV=#{ENV['RACK_ENV']} bundle exec rake unicorn:restart --trace'")
    end
    

    Then run

    $ RACK_ENV=production PRODUCTION_HOST=www.foohost.com bundle exec rake deploy restart
    

    or just

    $ RACK_ENV=production PRODUCTION_HOST=www.foohost.com bundle exec rake deploy
    

    Note -- This assumes the following:

    • You've checked out your repo on your remote host.
    • You've setup your app and it's running on your remote server.
    • You're using using Unicorn.
    • You're using Bundler.

    Published on in Hacks, Rake, Ruby

    Comment


  25. Hack: Generating gh-pages

    With rake

    Add the following to your Rakefile

    desc "generate and update gh-pages"
    task :pages do
      system(" set -x; bundle exec rspec ") or abort
      system(" set -x; bundle exec yardoc --protected ./lib/**/*.rb ") or abort
      system(" set -x; mv -v ./doc /tmp ") or abort
      system(" set -x; mv -v ./coverage /tmp ") or abort
      system(" set -x; git checkout gh-pages ") or abort
      system(" set -x; rm -rf ./doc ./coverage ") or abort
      system(" set -x; mv -v /tmp/doc . ") or abort
      system(" set -x; mv -v /tmp/coverage . ") or abort
      system(" set -x; git add . ") or abort 
      system(" set -x; git commit --all -m 'updating doc and coverage' ") or abort
      system(" set -x; git checkout master ") or abort
      puts "don't forget to run: git push origin gh-pages"
    end
    

    Then run

    $ bundle exec rake pages
    $ git push gh-pages
    

    Or less ugly, with bash...

    Create scripts/pages

    #!/usr/bin/env bash
    set -xue 
    bundle exec rspec 
    bundle exec yardoc --protected ./lib/**/*.rb
    mv -v ./doc /tmp 
    mv -v ./coverage /tmp 
    git checkout gh-pages
    rm -rf ./doc ./coverage 
    mv -v /tmp/doc .
    mv -v /tmp/coverage . 
    git add .
    git commit --all -m 'updating doc and coverage'
    git checkout master
    echo "don't forget to run: git push origin gh-pages"
    

    Then run

    $ chmod 755 ./scripts/pages
    $ ./scripts/pages
    

    Note -- I opted for the rake method because I use rake in my projects.

    Published on in Hacks, Rake, Ruby

    Comment