- GitHub Staff
- https://www.georgebrock.com
- @georgebrock
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Lazily load models via XHR in MVC-style JavaScript | |
var Model = function(params) {}; | |
Model.load_and_retry = function(id, controller, controller_variable) { | |
var controller_method = this.load_and_retry.caller; | |
var data_loaded_callback = function(data) { | |
controller[controller_variable] = new Model(data); | |
controller_method.apply(controller); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Get a warning when jQuery finds no matches for a selector | |
Handy for debugging, although I wouldn't want it in production | |
*/ | |
jQuery.oldFind = jQuery.find; | |
jQuery.find = function(sel) { | |
var result = jQuery.oldFind.apply(jQuery, arguments); | |
if(typeof(sel) == "string" && result.length == 0) { | |
console.warn("Nothing matches selector: ", sel); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# A secure S3 storage engine for Paperclip. | |
# Usage: | |
# | |
# require "paperclip/storage/s3secure" | |
# has_attached_file :image, :storage => :S3secure, :s3_permissions => :private, … | |
module Paperclip::Storage::S3secure | |
def self.extended base | |
base.extend(Paperclip::Storage::S3) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Hash | |
def hash_map() | |
self.inject({}) do |hash, (k, v)| | |
hash.merge(k => yield(k, v)) | |
end | |
end | |
end | |
{:a => 1, :b => 2}.hash_map {|k,v| v**2 } # => {:a => 1, :b => 4} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace :deploy do | |
PRODUCTION_APP = 'myapp' | |
STAGING_APP = 'myapp-staging' | |
def run(*cmd) | |
system(*cmd) | |
raise "Command #{cmd.inspect} failed!" unless $?.success? | |
end | |
def confirm(message) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module JavaScriptHelper | |
# Call this in your views to indicate that a feature needs to be initialised | |
def use_javascript_for(feature) | |
@javascript_features ||= [] | |
@javascript_features << feature | |
end | |
# Use this in your layout to add a list of classes to add to the body so that the JavaScript knows which features to initialised | |
def javascript_feature_classes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
javascript:if(%20!window.goviasGrid%20){window.goviasGrid%20=%20document.createElement(%22div%22);document.getElementsByTagName(%22body%22)[0].appendChild(window.goviasGrid);window.goviasGrid.style.background%20=%20%22url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAA8AAAAABCAYAAAARiscXAAAACXBIWXMAAA3XAAAN1wFCKJt4AAAAa0lEQVRIDe3XsQ2AIBhE4WMMF3A0mQlHcxmlPxO4YGUeCc2fR8FXkFAkbX2P1619HP2naGe7vrxNPSp+C6D4LeD1o/jhlwjw/iVa3uLnJskEv0TLW/zcJJngl2h5i5+bJBP8Eq2Xtmjq//YAvUkuG1WPHY0AAAAASUVORK5CYII=)%20repeat-y%2050%%200%22;window.goviasGrid.style.width%20=%20%22960px%22;window.goviasGrid.style.margin%20=%20%220%20auto%22;window.goviasGrid.style.height%20=%20%22100%%22;window.goviasGrid.style.position%20=%20%22fixed%22;window.goviasGrid.style.top%20=%20%220%22;window.goviasGrid.style.bottom%20=%20%220%22;window.goviasGrid.style.left%20=%20%220%22;window.goviasGrid.style.right%20=%20%220%22;window.goviasGrid.style.display%20=%20%22none%22;window.goviasGrid.style.zIndex%20=%20%2299999%22;window.goviasGrid.onclick%20=%20fun |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// jQuery extension to bind events that depend on an AJAX request. | |
// | |
// As soon as the event is bound it will start preloading the data from the server. | |
// If the event occurs while the data is still loading, your callback will be called | |
// as soon as the data finishes loading. | |
// | |
// Example: | |
// $('a.more').bindWithPreload('click', '/foo.json', function(data) { | |
// alert(data.message); | |
// }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# The name of the wireless network has changed between versions of OS X, so we | |
# need to find the right name: | |
service=`networksetup -listallnetworkservices | grep -Ei 'wi-fi|airport'` | |
networksetup -setsocksfirewallproxy $service localhost 9000 | |
networksetup -setsocksfirewallproxystate $service on | |
echo 'Connecting to proxy.' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
date=`git log -n1 --pretty=format:%ai` | |
cd ../activerecord-deprecated_finders | |
git checkout `git rev-list -n1 --before="$date" master` | |
cd ../rails | |
unset AR_DEPRECATED_FINDERS | |
grep active_record_deprecated_finders Gemfile && export AR_DEPRECATED_FINDERS=../activerecord-deprecated_finders | |
export JOURNEY=../journey |
OlderNewer