Skip to content

Instantly share code, notes, and snippets.

View stephenjudkins's full-sized avatar

Stephen Judkins stephenjudkins

View GitHub Profile
Hello world!
require 'csspool'
require 'pp'
site = Scraper.scrape "http://www.aboutus.org"
doc = site.front_page.doc
style = RealInternet.get('http://www.aboutus.org/support/style.css').body
sac = CSS::SAC::Parser.new
css = sac.parse(style)
a = doc.search("a.logo").first
require 'electric_sheep/whois/parser_wrapper'
require 'dm_test'
class Contact
include DataMapper::Resource
property :page_id, Integer, :key => true
property :address, String
property :city, String
property :state, String
def self.group_by(method_name)
define_method :"group_by_#{method_name}" do
inject([]) do |_, v|
k = yield(v)
if _.empty? || !_.last.send(method_name, k)
_ << [v]
else
_.last << v
end
_
@stephenjudkins
stephenjudkins / gist:116269
Created May 22, 2009 17:56
the most beautiful ruby code ever produced.
MW_PARSER_VERSION = "1.6.1"
RLH_FOR_UPDATE = 1
OT_HTML = 1
OT_WIKI = 2
OT_MSG = 3
OT_PREPROCESS = 4
SFH_NO_HASH = 1
STRIP_COMMENTS = "HTMLCommentStrip"
HTTP_PROTOCOLS = "http:\\/\\/|https:\\/\\/"
EXT_LINK_URL_CLASS = "[^][<>\"\\x00-\\x20\\x7F]"
location /Special/graphic_protection {
proxy_intercept_errors on;
rewrite ^/Special/graphic_protection/(.*)$ /$1 break;
proxy_pass http://au-graphic-protection.s3.amazonaws.com;
error_page 404 = $uri;
}
jruby --fast --server -J-Djruby.objectspace.enabled=false -J-Xmx1024m -J-Xms1024m -J-Xmn512m
>> ids = [25859692, 25859705, 25859728, 25859747, 25859763, 25859767, 25859788, 25859789, 25859802, 25859813, 25859819, 25859827, 25859828, 25859830, 25859838, 25859844, 25859856, 25859857, 25859874, 25859904, 25859969, 25859999, 25860016, 25860028, 25860034, 25860040, 25860048, 25860049, 25860067, 25860139, 25860143, 25860146, 25860147, 25860149, 25860162, 25860164, 25860174, 25860178, 25860182, 25860190, 25860197, 25860201, 25860209, 25860215, 25860246, 25860251, 25860270, 25860276, 25860307, 25860319, 25860326, 25860336, 25860337, 25860352, 25860358, 25860372, 25860380, 25860383, 25860385, 25860401, 25860404, 25860414, 25860418, 25860421, 25860422, 25860433, 25860437, 25860451, 25860464, 25860466, 25860470, 25860484, 25860486, 25860499, 25860516, 25860528, 25860532, 25860541, 25860552, 25860554, 25860560, 25860587, 25860592, 25860605, 25860612, 25860616, 25860620, 25860634, 25860637, 25860648, 25860655, 25860702, 25860738, 25860796]
>> actions = Action.all :conditions => {:id => ids}
>> times = actions.c
CREATE TABLE `lists` (
`id` int(11) NOT NULL auto_increment,
`uid` varchar(255) NOT NULL,
`casespace_key` text,
`created_at` datetime default NULL,
`updated_at` datetime default NULL,
`title` varchar(255) default NULL,
`description` text,
PRIMARY KEY (`id`),
UNIQUE KEY `index_lists_on_uid` (`uid`)
module Enumerable
def permutations
Enumerable::Enumerator.new(self, :each_permutation)
end
def each_permutation
each do |item|
others = select {|other| item != other}