Skip to content

Instantly share code, notes, and snippets.

View elecnix's full-sized avatar

Nicolas Marchildon elecnix

View GitHub Profile
#!/usr/bin/perl
#
# Feeds ganglia with web server error rate information.
#
# The latest version can be found on GitHub:
#
# http://gist.github.com/14352
#
# This script can be called by Apache by setting up a special logger:
#
require 'rubygems'
require 'mechanize'
postal_codes = File.open("postal_codes.txt").read.split("\n")
# randomize to make the pattern slightly harder to see in logs
postal_codes = postal_codes.sort_by {|e| rand(10_000)}
@agent = WWW::Mechanize.new do |a|
a.user_agent_alias = 'Mac Safari'
a.max_history = 1
require 'rubygems'
require 'mechanize'
# Generates a CVS list: Postal Code, District ID, District Name
# Use like this:
# $~/postal_codes/A$ ruby /path/to/extract_elections_ca 2>/dev/null >> districts.csv
postal_codes = File.open("postal_codes.txt").read.split("\n")
postal_codes.each do |postcode|
postcode.sub! ' ', ''
@elecnix
elecnix / bash-git-prompt
Created November 25, 2008 22:31
Displays the current git branch name and the dirty state in your Bash shell prompt
#!/bin/bash
#
# Displays the current git branch name and the dirty state in your Bash shell
# prompt. Add a line like this to your ~/.bashrc file:
#
# . ~/path/to/gist/bash-git-prompt
#
# To use this, you must enable "enable programmable completion features".
# Look at your ~/.bashrc for something like:
#
@elecnix
elecnix / get-all-railscasts.rb
Created November 27, 2008 02:28
Download railscasts.com archive
require 'rubygems'
require 'mechanize'
require 'net/http'
agent = WWW::Mechanize.new do |a|
a.user_agent_alias = 'Mac Safari'
end
archive = agent.get("http://railscasts.com/episodes/archive")
episodes = archive.links.select do |link|
@elecnix
elecnix / get-all-podcasts.rb
Created November 27, 2008 02:43
Downloads podcast.rubyonrails.org audio archive.
require 'rubygems'
require 'mechanize'
require 'net/http'
agent = WWW::Mechanize.new do |a|
a.user_agent_alias = 'Mac Safari'
end
archive = agent.get("http://podcast.rubyonrails.org/programs/1/transcripts")
episodes = archive.links.select do |link|
@elecnix
elecnix / git-travel-test.sh
Created November 28, 2008 02:59
Keep two huge disks in sync with git
# Read carefully. This script is mostly useless.
# It demonstrates how git could help keep two huge disks in sync, one bigger than the other.
# Execute like this:
# bash -xf git-travel-test
set -e
echo "suppose we build a really really big repo"
mkdir repo1
cd repo1
@elecnix
elecnix / get-nfjs-podcasts.rb
Created November 29, 2008 01:07
Downloads Podcasts from nofluffjuststuff.com
#!/usr/bin/ruby
# Downloads Podcasts from www.nofluffjuststuff.com
require 'rubygems'
require 'mechanize'
agent = WWW::Mechanize.new do |a|
a.user_agent_alias = 'Mac Safari'
end
@elecnix
elecnix / convert-video-for-iaudio-u3.sh
Created November 29, 2008 05:37
Convert FLV to AVI with mencoder
mencoder in.flv -quiet -oac pcm -ovc xvid -ofps 15 -vf scale=160:-2 -xvidencopts bitrate=256:vhq=4:me_quality=4:max_bframes=0 -o tmp.avi && transcode -i tmp.avi -P1 -b 0,1 -o out.avi
@elecnix
elecnix / get-grails-podcasts.rb
Created November 29, 2008 17:10
Downloads podcasts from grailspodcast.com
#!/usr/bin/ruby
# Downloads podcasts from http://www.grailspodcast.com
# Creates files named like this example:
# grails_podcast_episode_17 - Interview with Jason Rudolph.mp3
require 'rubygems'
require 'mechanize'
agent = WWW::Mechanize.new do |a|
a.user_agent_alias = 'Mac Safari'