Skip to content

Instantly share code, notes, and snippets.

View jacobo's full-sized avatar

Jacob Burkhart jacobo

  • HOVER
  • San Francisco, CA
View GitHub Profile
@jacobo
jacobo / gist:73561
Created March 3, 2009 22:12
Apparent bug in Rack::Utils::Multipart.parse_multipart
require 'rubygems'
require 'rack'
multipartrequestbody = "------------XnJLe9ZIbbGUYtzPQJ16u1\r\nContent-Disposition: form-data; name=\"thing_one\"\r\n\r\none_1\r\n------------XnJLe9ZIbbGUYtzPQJ16u1\r\nContent-Disposition: form-data; name=\"thing_two\"; filename=\"hi_file.ini\"\r\nContent-Type: application/x-stl\r\nContent-Length: 3\r\n\r\n22\n\r\n------------XnJLe9ZIbbGUYtzPQJ16u1\r\nContent-Disposition: form-data; name=\"thing_three\"; filename=\"binaryfile500\"\r\nContent-Type: application/x-stl\r\nContent-Length: 500\r\n\r\n\005@\214h\303\300[\025k\301Sf\b@\330\177\303\300\310Wl\301\211\022\001@+\225\277\300\000\000X\341Y>\334-=\277\222\245#\277\310Wl\301\211\022\001@+\225\277\300\306\212j\301\325/\371?\204\313\273\300\025\313l\301\032\031\366?\244f\274\300\000\000Y`\241>z>*\277\320S-\277\354\036n\301\347}\005@\214h\303\300\310Wl\301\211\022\001@+\225\277\300\262wn\301=\350\375?2\205\300\300\000\000\211\244\241>\325k;\277\300\205\032\277\310Wl\301\211\022\001@+\225\277\300\025\313l\301\032\031\366?\2
@jacobo
jacobo / gist:73894
Created March 4, 2009 16:20
500 in irb, 502 in script/console.... WHY!
"\005@\214h\303\300[\025k\301Sf\b@\330\177\303\300\310Wl\301\211\022\001@+\225\277\300\000\000X\341Y>\334-=\277\222\245#\277\310Wl\301\211\022\001@+\225\277\300\306\212j\301\325/\371?\204\313\273\300\025\313l\301\032\031\366?\244f\274\300\000\000Y`\241>z>*\277\320S-\277\354\036n\301\347}\005@\214h\303\300\310Wl\301\211\022\001@+\225\277\300\262wn\301=\350\375?2\205\300\300\000\000\211\244\241>\325k;\277\300\205\032\277\310Wl\301\211\022\001@+\225\277\300\025\313l\301\032\031\366?\244f\274\300\262wn\301=\350\375?2\205\300\300\000\000\005\350\315>c\026(\277\241Y#\277\262wn\301=\350\375?2\205\300\300\025\313l\301\032\031\366?\244f\274\300\271\263n\301\337\325\361?\335\265\275\300\000\000\263\311Y>9+M\277L\031\017\277\306\212j\301\325/\371?\204\313\273\300\324\027k\301/X\356?\364S\270\300\025\313l\301\032\031\366?\244f\274\300\000\000\307\t\232>\027,=\277\240T\032\277\025\313l\301\032\031\366?\244f\274\300\324\027k\301/X\356?\364S\270\3007\027m\301\211;\353??^\271\300\000\000Y\301\217>gDZ\277a\245\341\276\324\027
buckets = {}
index = 1
File.open "../test_syslogs/test.syslog.log" do |fp|
fp.each_line do |line|
line =~ / ([^ ]+) ([^ ]+)\[(\d+)\]: (.*)/
next if $2.nil? or $2 == 'newsyslog'
pid = $3
bucket = [$1, $2, $3].join '-'
paths = []
traversal = Proc.new do |basepath|
Dir.new(basepath).each do |filename|
unless filename[0,1] == "."
new_path = File.join(basepath, filename)
if File.directory?(new_path)
traversal.call(new_path)
else
paths << new_path
end
define_field "Birthday (day/month/year)" do
|child, value|
if value == ""
child.birthdate = nil;
elsif value =~ /(\d+)\/(\d+)\/(\d+)/
#15/12/1997 -- which needs to be reversed to 12/15/1997 in order to be imported
child.birthdate = value.gsub(/(\d+)\/(\d+)\/(\d+)/) do | s |
year = $3;
if year.length == 2
if year[0..0] == 0
@jacobo
jacobo / gist:136179
Created June 25, 2009 21:30
jQuery should have build function
//define this:
jQuery.fn.build = function(htmlElem, attributes){
if(!attributes){ attributes = ""; }
this.append("<"+htmlElem+" "+attributes+"></"+htmlElem+">");
return this.children(":last");
}
//and then you can do things like this:
#Routes:
ActionController::Routing::Routes.draw do |map|
# restful routes
map.resources :users
# default routes
map.connect ':controller/:action/:id'
map.connect ':controller/:action/:id.:format'
end
#Routes:
ActionController::Routing::Routes.draw do |map|
# The workaround for http://gist.github.com/157553
map.connect ':controller/:action/:id',
:action => /(s(?!how)|u(?!pdate)|d(?!estroy)|e(?!dit)|n(?!ew)|c(?!reate)|i(?!ndex)|([^sudenci0-9]{1}))[^0-9]+/
# restful routes
map.resources :users
Next steps:
mkdir tryingtoremembertheimportcommands
cd tryingtoremembertheimportcommands
git init
touch README
git add README
git commit -m 'first commit'
git remote add origin [email protected]:jacobo/tryingtoremembertheimportcommands.git
git push origin master
rvm 0.1.5 by Wayne E. Seguin ([email protected]) [http://rvm.beginrescueend.com/]
system:
uname: "Darwin jacob.mmm.com 10.2.0 Darwin Kernel Version 10.2.0: Tue Nov 3 10:37:10 PST 2009; root:xnu-1486.2.11~1/RELEASE_I386 i386"
ruby:
interpreter: "ruby"
version: "1.8.7"
date: "2009-12-24"