-
Deleting a `git commit`
Simple methods for deleting both local and remote git commits.
-
Installing Nginx with Lua Module
Or run the following command:
bash < <(curl -s https://gist.github.com/jmervine/5407622/raw/nginx_w_lua.bash)
Note: This script has been tested on
Ubuntu 12.04.2 LTSbut should work on just about any unix based distro, as everything is compiled from source.Requires wget and basic build essentials.
What's it do?
- Download LuaJIT 2.0.1
- Install LuaJIT 2.0.1
- Download Nginx Development Kit (NDK)
- Download lua-nginx-module
- Download Nginx 1.2.8
-
configureNginx with lua-nginx-module - Install Nginx
Binary Results:
/opt/nginx/sbin/nginx/usr/local/bin/lua/usr/local/bin/luajit
Lib Results:
/usr/local/lib/*lua*
Include Results:
/usr/local/include/luajit-2.0/*
Starting Nginx
LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH /opt/nginx/sbin/nginx -c /path/to/nginx.confUpdate existing Nginx init:
Stop Nginx:
sudo /etc/init.d/nginx stopPatch
/etc/init.d/nginxlike so:13,14c13,18 < PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin < DAEMON=/usr/sbin/nginx --- > export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH > > # ensure default configuration location > test "$DAEMON_OPTS" || DAEMON_OPTS="-c /etc/nginx/nginx.conf" > PATH=/opt/nginx/sbin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin > DAEMON=/opt/nginx/sbin/nginx`
Note: the above may not be the best way, but it's what I had to do to get it to work and I didn't have a ton of time to mess with it.
-
Install MySQL on CentOS 6
A simple script to install MySQL on CentOS 6.
#!/usr/bin/bash # # sudo bash < <(curl -s https://gist.github.com/jmervine/5373441/raw/) set -x cd /tmp wget http://dev.mysql.com/get/Downloads/MySQL-5.6/MySQL-shared-5.6.10-1.el6.x86_64.rpm/from/http://cdn.mysql.com/ wget http://dev.mysql.com/get/Downloads/MySQL-5.6/MySQL-client-5.6.10-1.el6.x86_64.rpm/from/http://cdn.mysql.com/ wget http://dev.mysql.com/get/Downloads/MySQL-5.6/MySQL-server-5.6.10-1.el6.x86_64.rpm/from/http://cdn.mysql.com/ wget http://dev.mysql.com/get/Downloads/MySQL-5.6/MySQL-devel-5.6.10-1.el6.i686.rpm/from/http://cdn.mysql.com/ rpm -qa | grep mysql-libs && yum remove -y mysql-libs yum install -y MySQL-shared-5.6.10-1.el6.x86_64.rpm yum install -y MySQL-client-5.6.10-1.el6.x86_64.rpm yum install -y MySQL-server-5.6.10-1.el6.x86_64.rpm yum install -y MySQL-devel-5.6.10-1.el6.i686.rpm
-
HTTPerf.rb Example
Here's an example of a simple script using HTTPerb.rb. It's a quick and dirty script used for getting quick differences between changes.
-
HTTPerf.rb 0.3.11 Released
Adding
teesupport, which will print any httperf (both STDOUT and STDERR) output to STDOUT while running the process. -
Using curl to Test HTTPS with Self Signed Certs
$ curl https://<domain>/path/to.html --insecure
Also see: HTTPS: Creating Slef-signed Certs.
-
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.
-
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.
-
LA Ruby Conf
I'll be there, say "Hello"!
-
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/6.2/\$basearch/Extras/RPMS/ enabled=0 gpgcheck=1 gpgkey=http://downloads.naulinux.ru/pub/NauLinux/RPM-GPG-KEY-linux-ink ' > /etc/yum.repos.d/naulinux-extras.repo" sudo yum --enablerepo=naulinux-extras install nodejs
-
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 -
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.

-
'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
-
Killing Caps Lock on Ubuntu
-
Create
xmodmapfile:$ xmodmap -pke > ~/.xmodmap
-
Edit the newly created
~/.xmodmapfile, changing the line starting withkeycode 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
-
Load your new map, disabling Caps Lock:
xmodmap ~/.xmodmap
-
(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=
-
-
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. -
Alternatives to OpenStruct
OpenStruct is bad. Here are two quick alternatives.
-
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 $knownhostsIn your ~/.ssh/config
HashKnownHosts no
-
Dilbert: Cloudwash

from Dilbert Daily Strip http://dilbert.com/.
-
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
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
What is Thin?
-
Rails script/server Unicorn Replacement
A script to replace
script/serverin Rails, which runs Unicorn over Webrick, because it's faster. This script is designed for development only! -
Minimum Version Checking with BASH/ZSH
The following line will print
zshversion 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
-
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.
-
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
-
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.
- Open your grub config:
sudo vi /etc/default/grub. -
Update the line containing
GRUB_CMDLINE_LINUX_DEFAULT, addingacpi_backlight=vendorto 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" # ...
Save and update grub with
sudo update-grub.- 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.
- Open your grub config:
-
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:
- Do not use
rvm pkg install readline. - "1.9.3-p194" is an example, should work with most versions.
- Do not use
