Skip to content

Instantly share code, notes, and snippets.

Robin Ward eviltrout

Block or report user

Report or block eviltrout

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View gist:118062
def make_new(obj, hash)
new_ob = type.new
# Two approaches - 1st: You can use the array notation [] on an activerecord to use it like a hash
hash.each do {|key, value| new_ob[key] = value }
# Or you can send to the method using period:
hash.each do {|key, value| new_ob.send("#{key.to_s}=", value) }
end
View gist:745835
Account.transaction do
david.withdrawal(100)
mary.deposit(100)
end
View gist:2493434
{{#each suggestedUsers}}
<li>
{{selectedUser}}
<a href='#' {{action completeUser}} {{bindAttr data-username="this"}}>{{this}}</a>
</li>
{{/each}}
@eviltrout
eviltrout / gist:3835764
Created Oct 4, 2012
#unboundIf and #unboundUnless in Ember
View gist:3835764
Ember.Handlebars.registerHelper 'unboundIf', (property, options) ->
context = (options.contexts && options.contexts[0]) || this
normalized = Ember.Handlebars.normalizePath(context, property, options.data)
if (Ember.get(normalized.root,normalized.path,options))
return options.fn(context,property)
else
return options.inverse(context,property)
Ember.Handlebars.registerHelper 'unboundUnless', (property, options) ->
@eviltrout
eviltrout / nntp_connection.rb
Created Dec 19, 2012
NNTP Connection Class in Ruby
View nntp_connection.rb
#
# Example usage:
#
# require 'rubygems'
# require 'date'
# require 'socket'
# require 'celluloid'
# require 'nntp_connection'
#
# nntp = NNTPConnection.new('news.supernews.com', 119, 'username', 'password')
View race_condition.rb
# Keep everything in a database transaction
Player.transaction do
# Find the player's current goal
goal = player.current_goal
# Make sure we don't reward goals that have been already been completed
unless goal.completed?
goal.update_column :completed, true
player.score += goal.score
View welcome.yml
en:
try_discourse:
system_messages:
usage_tips:
text_body_template: |
WELCOME TO TRY OMG!!!?!?!!?!?
This private message has a few quick tips to get you started:
View additional_providers.rb
gem "omniauth-appnet"
gem "omniauth-box"
gem "omniauth-clef"
gem "omniauth-deviantart"
gem "omniauth-dropbox"
gem "omniauth-ebay"
gem "omniauth-flickr"
gem "omniauth-fitbit"
gem "omniauth-flattr"
gem "omniauth-foursquare"
View gist:5338573
Discourse.debouncePromise = function(func, wait) {
var timeout = null;
return function() {
var context = this;
var args = arguments;
// Return a promise that is never executed
if (timeout) return Ember.Deferred.create();
View gist:5957785
It's hard to answer these in a tweet :)
You can't pass arguments to computed properties unless you are creating custom setters, but that's a whole different topic!
What you probably want to do here is use an itemController for each row you are displaying (with the button.)
{{#each thing in things itemController="thing"}}
<button {{bindAttr disabled=thing.disabled}}>button</button>
{{/each}}
You can’t perform that action at this time.