Skip to content

Instantly share code, notes, and snippets.

View pjhyett's full-sized avatar

PJ Hyett pjhyett

View GitHub Profile
lines = `git log --oneline`.split("\n")
lines.map! do |line|
sha, *msg = line.split
msg = msg.join(' ') # unused
color = '#' + sha[0..-2]
%{<div class="box" style="background:#{color}"></div>}
end
File.open('colors.html', 'w') do |f|
f.puts <<-HTML
USER = 'github'
require 'open-uri'
user_id = open("http://twitter.com/followers/ids/#{USER}.xml").read.scan(/\d+/).sort_by { rand }.first
user_name = open("http://twitter.com/users/show.xml?user_id=#{user_id}").read[/screen_name>(\w+)/, 1]
puts user_name
`open http://twitter.com/#{user_name}`
alias gb='for k in `git branch|perl -pe s/^..//`;do echo -e `git show --pretty=format:"%Cblue%cr%Creset" $k|head -n 1`\\t$k;done'
# Output
# ------
# ~/Development/github(master)$ gb
# 4 weeks ago config-gem
# 9 days ago dropdown
# 5 weeks ago faucet
# 3 weeks ago health
# http://www.jamesbritt.com/2007/12/18/sending-mail-through-gmail-with-ruby-s-net-smtp
# http://d.hatena.ne.jp/zorio/20060416
require "openssl"
require "net/smtp"
Net::SMTP.class_eval do
private
def do_start(helodomain, user, secret, authtype)
raise IOError, 'SMTP session already started' if @started
~$ gem list -r -s http://gems.rubyforge.org | wc -l
4760
~$ gem list -r -s http://gems.github.com | wc -l
4766
@pjhyett
pjhyett / cache-down.rb
Created May 20, 2009 18:27
Experiment to create a read-only version of GitHub during migrations and what not. Doesn't work because Google throttles hits to their cache to prevent people from doing exactly what this does.
require 'rubygems'
require 'sinatra'
require 'open-uri'
def strip_header(text)
prefix = %{
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<base href="http://github.com/"<div style="width"<!DOCTYPE
}
text.sub(/.+<!DOCTYPE/m, prefix)
class Numeric
def commify
to_s.gsub(/(\d)(?=\d{3}+(\.\d*)?$)/, '\1,')
end
end
Numeric.new.commify(500000)
class Fixnum
{"years" => 31536000,"weeks" => 604800,"days" => 86400,"hours" => 3600,"minutes" => 60, "seconds" => 1}.each do |key,val|
define_method key do
self * val
end
end
%w(year week day hour minute second).each do |method|
define_method method do
1.send("#{method}s".to_sym)
@pjhyett
pjhyett / memory_profiler.rb
Created April 27, 2009 20:00
Simple ruby memory profiler
# simple memory profiler
# can't remember where I found it (thanks whomever wrote it)
class MemoryProfiler
DEFAULTS = {:delay => 10, :string_debug => false}
def self.start(opt={})
opt = DEFAULTS.dup.merge(opt)
Thread.new do
@pjhyett
pjhyett / yc_top.user.js
Created March 10, 2009 07:48
Install GreaseKit / GreaseMonkey and go to town
// ==UserScript==//
// @name Hacker News Top Bar Colorer
// @description Change the top bar color to whatever you want
// @include http://news.ycombinator.com/*
// ==/UserScript==
document.getElementsByTagName('td')[0]["bgColor"] = '#f6f6ef'