Skip to content

Instantly share code, notes, and snippets.

View jamesmoriarty's full-sized avatar
🔮
0xc0000005

James Moriarty jamesmoriarty

🔮
0xc0000005
View GitHub Profile
@jamesmoriarty
jamesmoriarty / vpn_assigned_dns_overide.rb
Created December 22, 2010 08:29
Vpn assigned dns override script.
#!/usr/bin/env ruby
require 'pty'
require 'optparse'
unless ENV['USER'].eql?("root")
puts "Must be run as root.\nFailed."
exit
end
options = {}
@jamesmoriarty
jamesmoriarty / threading_cpu_bound.rb
Created December 22, 2010 08:31
Cpu bound task threading benchmark.
require 'benchmark'
N_OPS = 100_000_000
N_THREADS = 10
BM_LABEL_WIDTH = 15
def func(n_ops)
(1..n_ops).each { 1 + 1 }
end
before "newrelic:server_monitor:install", "newrelic:server_monitor:uninstall"
namespace :newrelic do
namespace :server_monitor do
task :install, :roles => :web do
run "curl -o ~/newrelic-sysmond-1.1.2.124-linux.tar.gz http://download.newrelic.com/server_monitor/release/newrelic-sysmond-1.1.2.124-linux.tar.gz"
run "tar xzvf ~/newrelic-sysmond-1.1.2.124-linux.tar.gz"
sudo "cp ~/newrelic-sysmond-1.1.2.124-linux/daemon/nrsysmond.x64 /usr/local/bin/nrsysmond"
sudo "cp ~/newrelic-sysmond-1.1.2.124-linux/scripts/nrsysmond-config /usr/local/bin"
sudo "mkdir -p /etc/newrelic /var/log/newrelic"
sudo "chmod 1777 /etc/newrelic /var/log/newrelic"
@jamesmoriarty
jamesmoriarty / .bash_profile
Created March 5, 2012 01:41
git branch name in prompt
##
# Bash customizations
##
export CLICOLOR=1 # Enable color shell
export LSCOLORS=ExFxCxDxBxegedabagacad # Define colors
export COLOR_RED="\e[0;31m"
export COLOR_PINK="\e[35;1m"
export COLOR_NORMAL="\e[m"
command W w !sudo tee % > /dev/null
@jamesmoriarty
jamesmoriarty / irb.rb
Created March 16, 2012 08:54
render erb template
1.9.2p290 :013 > render_erb("Hey, <%= first_name %> <%= last_name %>", :first_name => "James", :last_name => "Moriarty")
=> "Hey, James Moriarty"
@jamesmoriarty
jamesmoriarty / irb.rb
Created March 27, 2012 02:31
Ruby Object Configuration Block
1.9.2p290 :083 > MyObject.configure do |config|
1.9.2p290 :084 > config.logger = STDOUT
1.9.2p290 :085?> end
=> MyObject
1.9.2p290 :190 > MyObject.new
=> #<MyObject:0x000001009ae268 @logger=#<IO:<STDOUT>>>
1.9.2p290 :191 > MyObject.new(:logger => nil)
=> #<MyObject:0x000001009a6928 @logger=nil>
@jamesmoriarty
jamesmoriarty / hack.sh
Created April 1, 2012 02:05 — forked from erikh/hack.sh
OSX For Hackers
#!/usr/bin/env sh
##
# This is script with usefull tips taken from:
# https://github.com/mathiasbynens/dotfiles/blob/master/.osx
#
# install it:
# curl -sL https://raw.github.com/gist/2108403/hack.sh | sh
#
class Vector2
# A 2 coordinate vector.
# http://en.wikipedia.org/wiki/Coordinate_vector
# @param x The x coordinate of the vector
# @param y The y coordinate of the vector
constructor:(@x = 0, @y = 0) ->
# Add 2 vectors.
# @param vector A vector
# @return vector
javascript:document.body.contentEditable='true'; document.designMode='on'; void 0