Skip to content

Instantly share code, notes, and snippets.

View jbinto's full-sized avatar

Jesse Buchanan jbinto

View GitHub Profile
@jbinto
jbinto / gist:5142953
Created March 12, 2013 13:44
Demonstrates the concept of class variables vs. instance variables in Ruby.
class Dog
attr_accessor :breed, :color, :description
def Dog.description
# Return @@description, unless it's nil, in that case return a fixed string.
@@description ||= "All dogs are 4 legged animals that bark."
end
def Dog.description=(new_description)
@@description = new_description
@jbinto
jbinto / gist:5254785
Created March 27, 2013 14:51
Setting factory_girl as the fixtures replacement. Add to your Rails config/application.rb file.
# So we can run "rails generate" from the command line to create factories
config.generators do |g|
g.fixture_replacement :factory_girl
end
@jbinto
jbinto / gist:5301893
Last active December 15, 2015 18:09
A practical example of closures in JavaScript: creating custom loggers.
function getLogger(prefix) {
return function(message) {
console.log(prefix + ": " + message);
}
}
// Video component
(function() {
log = getLogger("video");
log("initialized");
@jbinto
jbinto / gist:5421013
Created April 19, 2013 15:13
Procs vs Lambdas
# You can return from a lambda, and it will behave as expected.
write_two_words = lambda { |x, y| return "#{x} #{y}" }
puts write_two_words.call("hi", "there") # => hi there
def foo
# If you *explicitly* return from a Proc, you will actually return from the caller.
# Note that if you omit the "return" keyword, it behaves just like a lambda.
write_two_words = Proc.new { |x, y| return "#{x} #{y}" }
puts write_two_words.call("hi", "there")
@jbinto
jbinto / heroku.log
Created May 1, 2013 13:15
Heroku H12 request timeouts, PG::Error SSL SYSCALL error: EOF detected
2013-05-01T00:56:21.278781+00:00 app[web.1]: Started GET "/register" for 204.93.223.151 at 2013-04-30 20:56:21 -0400
2013-05-01T00:56:21.300491+00:00 app[web.1]: Rendered users/new.haml within layouts/application (7.6ms)
2013-05-01T00:56:21.300491+00:00 app[web.1]: Rendered shared/_form_errors.haml (0.1ms)
2013-05-01T00:56:21.300491+00:00 app[web.1]: Rendered layouts/shared/_messages.haml (0.1ms)
2013-05-01T00:56:21.300491+00:00 app[web.1]: Processing by UsersController#new as */*
2013-05-01T00:56:21.300491+00:00 app[web.1]: Rendered layouts/shared/_nav.haml (0.9ms)
2013-05-01T00:56:21.300491+00:00 app[web.1]: Rendered layouts/shared/_carousel.haml (0.4ms)
2013-05-01T00:56:21.300491+00:00 app[web.1]: Completed 200 OK in 12ms (Views: 12.1ms | ActiveRecord: 0.0ms)
2013-05-01T00:56:21.307102+00:00 heroku[router]: at=info method=HEAD path=/register host=www.puckpicks.ca fwd="204.93.223.151" dyno=web.1 connect=11ms service=33ms status=200 bytes=0
2013-05-01T00:57:51.101327+00:00 app[web.1]: Started GET "
@jbinto
jbinto / howto-recover-google-authenticator-keys.txt
Created February 8, 2014 04:20
Recovering Google Authenticator keys from Android device for backup
### Last tested February 7 2014 on a Galaxy S3 (d2att) running Cyanogenmod 11 nightly, with Google Authenticator 2.49.
### Device with Google Authenticator must have root.
### Computer requires Android Developer Tools and SQLite 3.
### Connect your device in USB debugging mode.
$ cd /tmp
$ adb root
$ adb pull /data/data/com.google.android.apps.authenticator2/databases/databases
@jbinto
jbinto / gist:9620922
Created March 18, 2014 14:16
'yo angular foo' hangs at jpegtran-bin, bower asking a question
# See https://github.com/yeoman/generator-angular/issues/505
# Below: output from 'yo angular foo' (or what was left in scrollback buffer)
npm http 200 https://registry.npmjs.org/grunt-karma/-/grunt-karma-0.8.2.tgz
npm http 200 https://registry.npmjs.org/load-grunt-tasks/-/load-grunt-tasks-0.2.1.tgz
npm http 200 https://registry.npmjs.org/grunt/-/grunt-0.4.4.tgz
npm http 200 https://registry.npmjs.org/time-grunt/-/time-grunt-0.2.10.tgz
npm http 200 https://registry.npmjs.org/grunt-autoprefixer/-/grunt-autoprefixer-0.4.2.tgz
npm http GET https://registry.npmjs.org/globule
npm http GET https://registry.npmjs.org/google-cdn
@jbinto
jbinto / gist:9621435
Created March 18, 2014 14:41
npm zsh completion broken
% npm egrep: empty (sub)expression 1 ↵
\"\$\{COMP_WORDS\[@\]\}\"
\"\$\{words\[@\]\}\"
\#
\#\#\#-begin-npm-completion-\#\#\#
\#\#\#-end-npm-completion-\#\#\#
\$\(COMP_CWORD=\$\(\(CURRENT-1\)\)
\$\?
\&\>/dev/null\;
@jbinto
jbinto / gist:9663989
Created March 20, 2014 13:43
thinkster.io chapter 4 fixes - Firebase not installed, JS files not included

While walking through Thinkster.io's AngularJS tutorial chapter 4 (Three-way data binding with a real-time server), I encountered some problems.

The tutorial advises us to:

  • run bower install angularfire --save
  • add firebase to the list of required modules
  • add a constant FIREBASE_URL to our app

After implementing the posts functionality, I tried it in the browser and got the following error (in Chrome console):

@jbinto
jbinto / gist:9665977
Created March 20, 2014 15:11
Make Sublime Text not search through JS vendor/generated code (e.g. typical yeoman project)

In Preferences.sublime-settings (press CMD + , on OS X), add the following:

"folder_exclude_patterns": [".svn", ".git", ".hg", ".sass-cache", ".tmp", "node_modules", "dist", "bower_components"]