Skip to content

Instantly share code, notes, and snippets.

@jamster
jamster / github_hire_scraper.rb
Created April 1, 2011 18:54
How many fucking people have gitub hired?
require 'rubygems'
require 'activesupport'
require 'bad_ass_extensions'
require 'nokogiri'
require 'open-uri'
class GitHubber
attr_accessor :header, :name, :date, :date_string, :links, :post
def initialize(hash, post)
@jamster
jamster / git_commit_parser.rb
Created March 22, 2011 17:32
quick script to parse git logs and turn them to a data structure
# Usage:
# git log | ruby git_commit_parser.rb
# https://gist.github.com/881641
# By: Jason Amster
# jayamster@gmail.com
require 'rubygems'
require 'pp'
logs = STDIN.read
logs = logs.split("commit ")
@jamster
jamster / rack-cloud-converter.rb
Created March 9, 2011 21:18
Rackspace Cloud Monthly Cost Calculator
header = "RAM Disk Price/Hour Price/Month"
x = DATA.read.split("\n").map do |x|
arr = x.split("\t")
monthly = arr.last[1..-1].to_f * 24 * 30
arr << "$#{monthly}"
arr.join("\t")
end.join("\n")
puts header
@jamster
jamster / gist:834455
Created February 18, 2011 21:35
IP Tables commands to allow web traffic, ssh traffic and port 4000 traffic
sudo iptables -A INPUT -i lo -j ACCEPT
sudo iptables -A INPUT -i ! lo -d 127.0.0.0/8 -j REJECT
sudo iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
sudo iptables -A OUTPUT -j ACCEPT
sudo iptables -A INPUT -p tcp --dport 80 -j ACCEPT
sudo iptables -A INPUT -p tcp --dport 443 -j ACCEPT
sudo iptables -A INPUT -p tcp --dport 4000 -j ACCEPT
sudo iptables -A INPUT -p tcp -m state --state NEW --dport 22 -j ACCEPT
sudo iptables -A INPUT -p icmp -m icmp --icmp-type 8 -j ACCEPT
sudo iptables -A INPUT -j REJECT
@jamster
jamster / gist:833791
Created February 18, 2011 15:11
Change timezone on CentOS
mv /etc/localtime /etc/localtime.bak
cp /usr/share/zoneinfo/US/Eastern /etc/localtime
@jamster
jamster / install_gems.rb
Created January 12, 2011 16:34
Script to install the gems that I have installed as of 1/12/11
gems = <<-GEMS
abstract (1.0.0)
actionmailer (3.0.3, 2.3.10)
actionpack (3.0.3, 2.3.10)
activemodel (3.0.3)
activerecord (3.0.3, 2.3.10)
activeresource (3.0.3, 2.3.10)
activesupport (3.0.3, 2.3.10)
addressable (2.2.2)
arel (2.0.6, 2.0.4)
@jamster
jamster / to_csv.rb
Created January 7, 2011 16:07
simple way to create a csv (or tsv) of AR records
def to_csv(array_of_ar_objects, delim=",")
keys = array_of_ar_objects.first.attributes.keys
puts keys.join(delim)
array_of_ar_objects.map do |item|
keys.map{|key| item.send(key)}.join(delim)
end.join("\n")
end
# I have this data
sample <- c(0, 1, 1, 2, 2, 2, 4, 6, 7, 7, 7, 7, 7, 7, 8, 8, 8, 9, 9, 9, 9)
# I already grouped and counted it
vals <- c(0,1,2,4,6,7,8,9)
freqs <- c(1,2,3,1,1,6,3,4)
# I want to use this, to do a histogram instead of on the original values
# Not hist(sample)
# but hist( vals, freas)
curl -s -XGET 'http://localhost:9200/_cluster/state?pretty=true'
{
"cluster_name" : "default",
"master_node" : "539080ef-fc83-49e9-be3a-458a90367386",
"blocks" : {
},
"nodes" : {
"539080ef-fc83-49e9-be3a-458a90367386" : {
"name" : "Werewolf by Night",
"transport_address" : "inet[/192.168.2.15:9300]",
[jasonamster]:~$ curl -s -XGET 'http://localhost:9200/_cluster/state?pretty=true'
{
"cluster_name" : "default",
"master_node" : "539080ef-fc83-49e9-be3a-458a90367386",
"blocks" : {
},
"nodes" : {
"539080ef-fc83-49e9-be3a-458a90367386" : {
"name" : "Werewolf by Night",
"transport_address" : "inet[/192.168.2.15:9300]",