Skip to content

Instantly share code, notes, and snippets.

(function () {
try{
if(!google.doodle)google.doodle = {};
var a = 200, g = -200, j = -200, k, l, m, n = 0, o = 0, p = 0, q = 35, r, s = [], t, u, v;
google.doodle.init = function () {
if(!v&&window.location.href.indexOf("#") = = -1){
v = true;
if(t = document.getElementById("hplogo")){
google.j&&google.j.en&&w(100, x, function () {
return google.rein&&google.dstr});
@skilldrick
skilldrick / saveRestore.js
Created November 25, 2010 00:00
No more pesky context.save() and context.restore() - use this handy sandwich function instead!
function saveRestore(ctx, func) {
ctx.save();
func(ctx);
ctx.restore();
}
//Usage
saveRestore(context, function (ctx) {
ctx.fillStyle = 'black';
ctx.fillRect(0, 0, width, height);
@skilldrick
skilldrick / gist:888344
Created March 26, 2011 14:56
jsautotest not resetting runner
#This happens after saving src/request.js
2011-03-26 14:54:19 Running GetRequestTest,ReadyStateHandlerTest,RequestTest,PostRequestTest
Chrome: Runner reset.
................
Total 16 tests (Passed: 16; Fails: 0; Errors: 0) (6.00 ms)
Chrome 10.0.648.133 Linux: Run 16 tests (Passed: 16; Fails: 0; Errors 0) (6.00 ms)
@skilldrick
skilldrick / gist:1034242
Created June 19, 2011 12:49
SICP craziness in JS
function segments(agenda) {
return agenda.segments;
}
function someThingElse(agenda) {
var segments = segments(agenda);
}
@skilldrick
skilldrick / gist:1034238
Created June 19, 2011 12:45
SICP craziness
;;segments is a function that takes an agenda and returns its segments
(define (segments agenda) (cdr agenda))
;;Then, inside another function:
(let ((segments (segments agenda)))
;;In this let, segments is the return value of segments. WTF.
)
@skilldrick
skilldrick / clipdirs.sh
Created June 29, 2011 14:21
Bash script for cygwin to save list of dirs to clipboard
find . -maxdepth 1 -type d | ruby -pe 'gsub(/^\.\/?/, "")' | grep '.' > /dev/clipboard
class User < ActiveRecord::Base
# ...
def method_missing method, *args
if method.to_s.starts_with? 'find'
reading_lists.find *args
else
super
@skilldrick
skilldrick / demeter.rb
Created July 4, 2011 21:55
Avoiding Demeter violations in Rails
class Example < ActiveRecord::Base
# The rest of the class .....
def get_object_and_method method_name
assoc_methods = [
:push,
:concat,
:build,
class Person < ActiveRecord::Base
has_many :friends
demeter_mate :friends, :with => :find, :create
end
# This gives:
# :find_friend, :create_friend
# as well as the other variations of inflection and order