Skip to content

Instantly share code, notes, and snippets.

View jridgewell's full-sized avatar
😬

Justin Ridgewell jridgewell

😬
  • New York, NY
  • 14:26 (UTC -04:00)
View GitHub Profile
@jridgewell
jridgewell / Delegator.php
Created January 20, 2015 23:35
A Delegator Class to extend from
<?php
class Delegator {
private $obj;
public static function from($array) {
return array_map(function($obj) {
return new Delegator($obj);
}, $array);
}
@jridgewell
jridgewell / index.js
Created February 4, 2015 23:42
requirebin sketch
var metal = require('backbone-metal');
metal.deprecate('test');
@jridgewell
jridgewell / gist:0a8cc627e65b3d24a8b9
Last active August 29, 2015 14:16 — forked from danapplegate/gist:98209b1eb2721ca7365c
The `$userVote` Problem

The userVote Problem

We are struggling to find a way to efficiently and cleanly implement the following common use case in our code base:

  • There is an object that can be voted on
    • Project
    • Discussion
    • Comment
  • We have an array of these objects
  • We would like to know if a user has voted on each of these objects
@jridgewell
jridgewell / view.patch
Last active August 29, 2015 14:24
Defining root Backbone element in template
diff --git a/backbone.js b/backbone.js
index b16499a..f484f19 100644
--- a/backbone.js
+++ b/backbone.js
@@ -1170,7 +1170,7 @@
var View = Backbone.View = function(options) {
this.cid = _.uniqueId('view');
_.extend(this, _.pick(options, viewOptions));
- this._ensureElement();
+ if (!this.templateEl) this._ensureElement();
var doc = $(new DOMParser().parseFromString(response.responseText.replace(/\&taglist\=/g,'&amp;taglist='), 'text/xml'));
@jridgewell
jridgewell / applescript_service
Created August 7, 2011 22:34
Open file/folder in MacVim. Preceded by get Finder Selection
on run {input, parameters}
repeat with i in input
tell application "MacVim"
open (POSIX path of i)
end tell
end repeat
tell application "MacVim"
activate
end tell
return input
#!/usr/bin/env ruby
###########################################################################
# Script to be called as an Xcode 4 behaviour which will attempt to
# uncrustify all source files in the open project.
#
# (c) Copyright 2012 David Wagner.
#
# Complain/commend: http://noiseandheat.com/
#
#*************************************************************************#
@jridgewell
jridgewell / Bookmarklet.js
Created April 2, 2013 22:24
Search 1Password Bookmarklet for iOS
javascript:d=window.location.hostname.split('.');window.location='onepassword://search/'+((d.length>2)?d[1]:d[0]);
@jridgewell
jridgewell / adblock.diff
Created June 1, 2013 21:22
Patch Safari Adblock to only blacklist sites.
diff --git a/background.js b/background.js
index f55a9ac..8e2160a 100644
--- a/background.js
+++ b/background.js
@@ -295,6 +295,11 @@
try_to_unwhitelist = function(url) {
url = url.replace(/#.*$/, ''); // Whitelist ignores anchors
var custom_filters = get_custom_filters_text().split('\n');
+ var domain = parseUri(url).hostname.match(/[^.]+\.[^.]+$/);
+ custom_filters[0] += "|~" + domain;
@jridgewell
jridgewell / models.rb
Last active December 18, 2015 09:19
Polymorphic select
class Catch < ActiveRecord::Base
belongs_to :animal, :polymorphic => true
end
class Bird < ActiveRecord::Base
attr_accessible :name
has_one :catch, :as => :animal
end
class Fish < ActiveRecord::Base