Skip to content

Instantly share code, notes, and snippets.

View ntalbott's full-sized avatar
💻
Writing and Coding

Nathaniel Talbott ntalbott

💻
Writing and Coding
View GitHub Profile
class WeatherBot
def name; self.class.name; end
def play(last=nil)
if !last or last == '' then 'r'
else @always_play ||= beats(last) end
end
def beats(play)
if paper?(play) then 's'
elsif rock?(play) then 'p'
else 'r' end
def manager(&lam)
SNMP::Manager.open(@manager_config, &lam)
end
def walk_table(table, &block)
manager do |m|
m.walk(table) { |row| yield row.collect{ |vb| vb.value.to_s } }
end
end
@ntalbott
ntalbott / gist:36841
Created December 16, 2008 22:11 — forked from mikehale/gist:36462
def parse_headers
request = "GET /remote/path/img.gif HTTP/1.1\r\nAccept-Language: en-us,en;q=0.5\r\nCache-Control: max-age=0\r\nIf-None-Match: \"58dc30c-216-3d878fe2\"-gzip\r\nX-Forwarded-For: 127.0.0.1\r\nAccept: image/png,image/*;q=0.8,*/*;q=0.5\r\nConnection: Keep-Alive\r\nX-Forwarded-Server: www.example.com\r\nAccept-Encoding: gzip,deflate\r\nUser-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.0.4) Gecko/2008102920 Firefox/3.0.4\r\nCookie: cookie1=YWJj; cookie2=ZGVm\r\nReferer: http://www.example.com/posts/\r\nAccept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7\r\nHost: localhost:4001\r\nX-Forwarded-Host: www.example.com\r\nIf-Modified-Since: Tue, 17 Sep 2002 20:26:10 GMT\r\n\r\n"
request.split("\r\n")[1..-1].inject({}) do |h,e|
k,v = e.split(': ') # Concern - could this ever split in to 3 or more elements?
h[k] = v
h
}
end
# Copyright 2009 Michael Ivey, released to public domain
# Disqus guts lifted from http://github.com/squeejee/disqus-sinatra-importer/tree/master
# I wanted it to run from MySQL and command line, instead of a Sinatra app
require 'rubygems'
require 'feed_tools'
require 'rest_client'
require 'json'
require 'sequel'
#!/usr/bin/env ruby
command = '/usr/bin/passenger-memory-stats'
memory_limit = 200 # megabytes
def running?(pid)
begin
return Process.getpgid(pid) != -1
rescue Errno::ESRCH
return false
ntalbott@joshua:~/git/spreedly-gem$ rake
(in /Users/ntalbott/git/spreedly-gem)
/opt/local/bin/ruby -w -Ilib:ext:bin:test -e 'require "rubygems"; require "test/unit"; require "test/spreedly_gem_test.rb"'
/opt/local/lib/ruby/gems/1.8/gems/thoughtbot-shoulda-2.10.1/lib/shoulda/context.rb:4: warning: method redefined; discarding old contexts
Loaded suite -e
Started
..............
Finished in 0.007244 seconds.
14 tests, 36 assertions, 0 failures, 0 errors
--- old/scripts/mysqld_safe.sh 2009-09-02 04:10:39.000000000 -0400
+++ new/scripts/mysqld_safe.sh 2009-09-02 04:52:55.000000000 -0400
@@ -383,7 +383,7 @@
fi
USER_OPTION=""
-if test -w / -o "$USER" = "root"
+if test -w /sbin -o "$USER" = "root"
then
if test "$user" != "root" -o $SET_USER = 1
ntalbott@joshua:~/git$ git clone http://github.com/basho/riak.git
Initialized empty Git repository in /Users/ntalbott/git/riak/.git/
error: Unable to get pack file http://github.com/basho/riak.git/objects/pack/pack-bc28dcec80b56d5d9e4ad7d53d73e63f624124f0.pack
transfer closed with 4843832 bytes remaining to read
error: Unable to find feb0d638ccb0db5fc8d0d6717bfa30f9dbd7ecdf under http://github.com/basho/riak.git
Cannot obtain needed commit feb0d638ccb0db5fc8d0d6717bfa30f9dbd7ecdf
while processing commit d8d5feb066b93f00f49e1427beed705d9efd8540.
fatal: Fetch failed.
1) User should not store the password
Failure/Error: User.destroy_all
# /Users/ntalbott/.rvm/gems/ree-1.8.7-2010.02/bundler/gems/ripple-25276b0e293e83429b4d0d3a8430fd01aebde6e5-a6374f66012f1f87afda83cb16bf2165a820df1d/riak-client/lib/riak/client/curb_backend.rb:52:in `perform'
# /Users/ntalbott/.rvm/gems/ree-1.8.7-2010.02/bundler/gems/ripple-25276b0e293e83429b4d0d3a8430fd01aebde6e5-a6374f66012f1f87afda83cb16bf2165a820df1d/riak-client/lib/riak/client/curb_backend.rb:52:in `http_get'
# /Users/ntalbott/.rvm/gems/ree-1.8.7-2010.02/bundler/gems/ripple-25276b0e293e83429b4d0d3a8430fd01aebde6e5-a6374f66012f1f87afda83cb16bf2165a820df1d/riak-client/lib/riak/client/curb_backend.rb:52:in `send'
# /Users/ntalbott/.rvm/gems/ree-1.8.7-2010.02/bundler/gems/ripple-25276b0e293e83429b4d0d3a8430fd01aebde6e5-a6374f66012f1f87afda83cb16bf2165a820df1d/riak-client/lib/riak/client/curb_backend.rb:52:in `perform'
# /Users/ntalbott/.rvm/gems/ree-1.8.7-2010.02/bundler/gems/ripple-25276b0e293e83429b4d0d3a8430fd01ae
@ntalbott
ntalbott / active_subscriber_counter.rb
Created June 30, 2010 18:28
An example script that counts the active subscribers in a Spreedly site using the transaction history.
SITE = ARGV[0]
TOKEN = ARGV[1]
require 'rubygems'
require 'nokogiri'
def next_transactions(since=0)
puts "Requesting transactions since #{since}"
doc = Nokogiri::XML(`curl -s -S -u #{TOKEN}:X https://spreedly.com/api/v4/#{SITE}/transactions.xml?since_id=#{since}`)
(doc/'transaction').collect do |t|