This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'nokogiri' | |
require 'open-uri' | |
require 'cgi' | |
require 'ostruct' | |
# YQL - Yahoo! Query Language | |
# http://developer.yahoo.com/yql/console/ | |
class YQL | |
BASE_URL = 'http://query.yahooapis.com/v1/public/yql?format=xml&q=' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
REMOTE_HOST='whatever' | |
USERNAME='whatever' | |
git push origin master && ssh ${REMOTE_HOST} "cd /home/${USERNAME}/www/rails;git pull origin master;chown -R ${USERNAME}:${USERNAME} *" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby | |
# Fetch Jakob Nielsen's Alertbox and turn it into a basic RSS feed | |
%w{rubygems hpricot open-uri rss/maker}.each { |l| require l } | |
puts "Content-type: text/xml\n\n" | |
feed = RSS::Maker.make("2.0") do |rss| | |
rss.channel.title = "Jakob Nielsen's Alertbox" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Test a Wordpress blog for compliance with /feed, /feed/ and | |
# similar requests from normal Feed clients and FeedBurner | |
# == HELPERS | |
require 'net/http' | |
# Fetch a URL without processing redirects and return status code and body | |
def get_url(url, agent) | |
iurl = URI.parse(url) | |
req = Net::HTTP::Get.new(iurl.path, { "User-Agent" => agent }) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Monitor HTTP requests being made from your machine with a one-liner.. | |
# Replace "en1" below with your network interface's name (usually en0 or en1) | |
sudo tcpdump -i en1 -n -s 0 -w - | grep -a -o -E "Host\: .*|GET \/.*" | |
# OR.. to be able to use as "httpdump" from anywhere, drop this into ~/.bash_profile: | |
# (again replace "en1" with correct network interface name) | |
alias httpdump="sudo tcpdump -i en1 -n -s 0 -w - | grep -a -o -E "Host\: .*|GET \/.*"" | |
# All the above tested only on OS X. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# urlmonitor - print out the URLs requested system wide on the main network interface | |
# Accept a network interface name as an optional argument | |
iface = ARGV.first | |
# No interface specified? Try to guess which one is king.. | |
unless iface | |
`ifconfig -l`.split.each do |iface| | |
next if iface =~ /^lo/ | |
break if `ifconfig #{iface}` =~ /inet (0|1|2)/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Basic Ruby event driven "chat" server | |
# Heavily based on example code at http://rev.rubyforge.org/rdoc/ | |
# Works on Ruby 1.9.1 - not tested on 1.8. | |
require 'rev' | |
# Configuration | |
HOST = 'localhost' | |
PORT = 1234 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# runas - Run another program under the privileges of a specified user and group. | |
# This is necessary because sudo demands a password, as we need it to be hands off. | |
# A poor man's suexec basically. | |
require 'etc' | |
user, group, cmd = ARGV |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Get the 50/20 week means of markets | |
# Sloppy ass coding that was a quick hack one night many moons ago.. | |
# Easily changed to do 50/20 days instead, not posting that one :) | |
require 'fastercsv' | |
require 'open-uri' | |
class Array; def sum; inject( nil ) { |sum,x| sum ? sum+x : x }; end; def mean; sum.to_f / size; end; end | |
fifty_weeks_ago = Time.now - 30240000 |