Skip to content

Instantly share code, notes, and snippets.

@eqdw
eqdw / gist:965159
Created May 10, 2011 19:09
pre-commit
#!/usr/bin/env ruby
result = `grep -rls "debugger" *`
if result != "" && result !~ /^log\/development\.log$/
puts "NEVER DO THIS AGAIN. THERE ARE DEBUG STATEMENTS IN THE CODEBASE"
puts "grep results: #{result}"
exit(1)
end
@eqdw
eqdw / stefanize.rb
Created April 21, 2011 19:11
An extension that stef should always include
module Stefanize
def method_missing(method_sym, *arguments, &block)
if method_sym.to_s =~ /^(.*)_to_me$/
send($1.to_sym, *arguments, &block)
else
super
end
end
end
int i = 10;
while(i --> 0){
printf("%d\n", i);
}
#define MSG_FORMAT "%s cannot be authenticated.\n"
void incorrect_password(const char *user)
{
// user names are restricted to 256 characters (or less)
static const char *msg_format = MSG_FORMAT;
size_t len = strlen(user) + sizeof(MSG_FORMAT);
char *msg = (char *)malloc(len);
if (msg)
{
int ret = snprintf(msg, len, msg_format, user);
@eqdw
eqdw / evo
Created February 12, 2011 00:48
demonstration of genetic evolution with a string
Initial Word: ksjfhed
on iter 0
New word kspfhed on iteration 21
New word kspfied on iteration 43
New word kspfied on iteration 57
New word pspfied on iteration 68
New word pspfieo on iteration 69
New word pspfieo on iteration 93
New word pepfieo on iteration 99
on iter 100
#
#
# WOULD THIS WORK, OR WOULD IT BREAK STUFF?
#
#
##OLD WAY
item(:field, :formatter => Proc.new{|derp| herp(derp)})
##NEW WAY
def change_description(cl)
Kernel.const_get(cl.model).describe_change(cl)
end
## DOES THIS MAKE SENSE / IS VALID
class Foo < ActiveRecord::Base
has_many :bar
has_many :baz, :through => :bar
end
class Bar < ActiveRecord::Base
belongs_to :baz
end
@eqdw
eqdw / wip_gcal.rb
Created January 23, 2011 19:16
[WIP] GData Calendar Scraping
require 'gdata'
require 'json' #parsing
cal = GData::Client::Calendar.new
cal.source = "innovatis_gdata_test"
cal.clientlogin("[email protected]", "YOUR_PASSWORD")
#now authenticated
#pull list of calendars which the currently logged in user can access. in json
feed = cal.get("https://www.google.com/calendar/feeds/default/allcalendars/full?alt=jsonc")
(function(){
var inner_private_var;
window.set_ipv = function(){
ipv = "herpaderp";
}