Skip to content

Instantly share code, notes, and snippets.

View pier-oliviert's full-sized avatar

Pier-Olivier Thibault pier-oliviert

View GitHub Profile
ip_address_whitelist:
- 127.0.0.1
- 1.2.3.4
- 5.6.7.8
whitelisted_pages:
- /assets/.*
- /
- /login
class Ticket::GrouperValidator < ActiveModel::Validator
def validate(record)
record.errors.add :grouper, 'has already occurred!' if record.grouper.full?
record.errors.add :grouper, 'has already occurred!' if record.grouper.past?
end
end
@pier-oliviert
pier-oliviert / test.rb
Last active December 26, 2015 21:28 — forked from anonymous/gist:7215813
class User < ActiveRecord::Base
include Redis::Objects
counter :reminders_to_send
def purge
@@redis_objects = {}
end
end
class Foo
has_many :tags
has_many :states
# q is hash: { "tags" => "ruby", "states" => "open" }
def self.search(q)
# wat do?
end
end
NoMethodError in ElectionsController#update
undefined method `each' for "#<Candidate:0x000000046fb310>":String
Rails.root: /home/jonblack/projects/mcet
Application Trace | Framework Trace | Full Trace
app/controllers/elections_controller.rb:50:in `block in update'
app/controllers/elections_controller.rb:49:in `update'
<select id="individual">
{{range .EMPLOYEES}}
{{ if .Selected }}
<option value="{{.ID}}" selected>{{.Name}}</option>
{{ else }}
<option value="{{.ID}}">{{.Name}}</option>
{{ end }}
{{else}}
<option value="nil">----</option>
{{end}}
@memberships = current_user.memberships
project_ids = @memberships.collect {|m| m.project.id}
@events = Event.select("id, name, description, start_at, end_at, all_day, project_id").where("project_id IN ?", project_ids).to_json
class @GroupActionMenuHandler
bind: ->
$(document).on 'click', '.group-action-menu a', this.selectMenuItem
selectMenuItem: (event) ->
id = $(e.target).data('id')
alert 'hello'
false
@pier-oliviert
pier-oliviert / hash.rb
Created December 19, 2011 14:00 — forked from cmer/hash.rb
Object#value_at_keypath
class Object
# Returns the value at the specified path.
# For example, "foo.bar.baz" as a path would return the
# value at self[:foo][:bar][:baz]. If self doesn't contain one of
# the keys specified in path, It will return the farthest object found (will return self if it couldn't find anything).
#
# @param String keypath A path composed of keys separated with "." specifying a deep-nested path
# @return Object the value object
class Object
@pier-oliviert
pier-oliviert / hash.rb
Created December 19, 2011 03:25 — forked from cmer/hash.rb
Hash#value_at_path
class Hash
# Returns the value at the specified path.
# For example, [:foo, :bar, :baz] as a path would return the
# value at self[:foo][:bar][:baz]. If self doesn't contain one of
# the keys specified in path, nil is returned.
#
# This method is useful as it simplifies statements such as:
# value = h[:a][:b][:c][:d] if h[:a] && h[:a][:b] && h[:a][:b][:c]
# to
# value = h.value_at_path([:a, :b, :c, :d])