Skip to content

Instantly share code, notes, and snippets.

View brianjolly's full-sized avatar

Brian Jolly brianjolly

View GitHub Profile
@brianjolly
brianjolly / hog_killer.rb
Created March 3, 2011 21:51
Emergency script to kill out of control Rails processes. Thanks to /dev/urandom :(
grep_output = `ps aux | grep Rails`
kill_list = []
any_rails = grep_output.scan(/^www-480\s+(\d+)\s+(\d+.\d+).*Rails/)
any_rails.each do |process|
pid = process[0]
cpu = process[1]
if cpu.to_f > 95.0
kill_list << process
@brianjolly
brianjolly / sshtest.rb
Created June 7, 2011 02:06
Quick net-ssh example
#!/usr/bin/env ruby
#gem install net-ssh
require 'rubygems'
require 'net/ssh'
HOST = '192.168.1.1'
USER = 'me'
PASS = 'secret'
@brianjolly
brianjolly / vagrant.org
Created July 18, 2011 22:01 — forked from zellyn/vagrant.org
Setting up a CentOS 5.4 base box for Vagrant
# Built-in python HTTP Server
python -m SimpleHTTPServer 8888
@brianjolly
brianjolly / binary
Created August 22, 2011 21:42
Print 0-50 in binary
for (i=0; i<51; i++) { console.log(i+"\t"+i.toString(2)); }
require 'nokogiri'
doc = Nokogiri::XML(File.open("deploy/data/BundleData.xml")) do |config| config.noblanks end
puts "Default Price:"
doc.xpath("//DefaultPrice/Choice").each { |p| puts "id: #{p['id']} price: #{p.content}" }
puts "ExistingCustPrice Price:"
doc.xpath("//ExistingCustPrice/Choice").each { |p| puts "id: #{p['id']} price: #{p.content}" }
@brianjolly
brianjolly / gist:1378120
Last active September 28, 2015 03:37
omniture sniffer
#!/usr/bin/env ruby
require 'uri'
require 'cgi'
require 'iconv'
require 'date'
require 'rubygems'
require 'colorize'
device = 'en3'
@brianjolly
brianjolly / letters_counter_spec.rb
Created March 9, 2012 05:50
Number words letter counter
class LettersCounter
def count word
word.gsub(/\s|-/, '').length
end
def sum_from_list words
lengths = words.map { |word| count word }
lengths.inject(:+)
end
end
@brianjolly
brianjolly / gist:4076096
Created November 15, 2012 01:39
cpu logger
#!/usr/local/bin/ruby
log_file = "/var/log/cpu_stats"
date = `date`.rstrip
cpu_stats = `uptime`.split
output = ""
if Dir[log_file] == []
output << "date,\t 1min,\t 5min,\t 15min\n"
@brianjolly
brianjolly / gist:4076102
Created November 15, 2012 01:39
memory logger
#!/usr/local/bin/ruby
log_file = "/var/log/mem_stats"
date = `date`.rstrip
mem_stats = `free -k`.split
output = ""
if Dir[log_file] == []
output << "date,\t total memory,\t used memory,\t free memory\n"