Skip to content

Instantly share code, notes, and snippets.

View semarco's full-sized avatar

Marco Sehrer semarco

View GitHub Profile
@icebreaker
icebreaker / mongoid-cheatsheet.md
Created February 15, 2011 09:11
Mongoid cheat sheet
@them0nk
them0nk / rspec_rails_cheetsheet.rb
Created March 23, 2012 03:39
Rspec Rails cheatsheet (include capybara matchers)
#Model
@user.should have(1).error_on(:username) # Checks whether there is an error in username
@user.errors[:username].should include("can't be blank") # check for the error message
#Rendering
response.should render_template(:index)
#Redirecting
response.should redirect_to(movies_path)
anonymous
anonymous / README.md
Created June 6, 2012 15:31
HSTORE exist function

exist function

The second parameter of exist has to be an string, and the quote has to be escaped as ''.

For example, where not exist(data, '''a''')

Full example

example_db=# create table something (id serial primary key, data hstore);
@ayosec
ayosec / utc-times.rb
Created July 11, 2012 13:28
Force UTC times
class Hash
def times_with_utc
dup.tap do |new_hash|
each_key do |key|
value = self[key]
if value.is_a?(ActiveSupport::TimeWithZone)
new_hash[key] = value.utc
end
end
end
@semarco
semarco / utc-times.rb
Created July 11, 2012 13:50 — forked from ayosec/utc-times.rb
Force UTC times
class Hash
def times_with_utc
dup.tap do |new_hash|
each_key do |key|
value = self[key]
if ActiveSupport::TimeWithZone === value
new_hash[key] = value.utc
elsif Array === value || Hash === value
new_hash[key] = value.times_with_utc
end
anonymous
anonymous / t.rb
Created July 20, 2012 08:00
require 'ruote'
dboard = Ruote::Dashboard.new(Ruote::Worker.new(Ruote::HashStorage.new))
dboard.register_participant 'toto' do |workitem|
p [ :pa, workitem.participant_name, workitem.wfid ]
end
class Listener
def initialize(context, opts={})
@clintongormley
clintongormley / gist:4095280
Created November 17, 2012 12:00
Using synonyms in Elasticsearch

We create an index with:

  • two filters: synonyms_expand and synonyms_contract
  • two analyzers: synonyms_expand and synonyms_contract
  • three text fields:
    • text_1 uses the synonyms_expand analyzer at index and search time
    • text_2 uses the synonyms_expand analyzer at index time, but the standard analyzer at search time
    • text_3 uses the synonyms_contract analyzer at index and search time

.

@wongyouth
wongyouth / mongoid3_id_monkey_patch.rb
Created February 3, 2013 08:03
This is a workaround for Mongoid3 and Emberjs or Backbonejs. Make `to_json` return id key the same value as _id which will be used as a primary key for ember-data.
module Mongoid
module Serialization
def serializable_hash_with_id(options = nil)
json = serializable_hash_without_id options
json['id'] = json['_id'] if json.has_key? '_id'
json
end
alias_method_chain :serializable_hash, :id
end
end
@semarco
semarco / dev-tools.md
Last active December 17, 2015 14:39
misc Dev Tools & Resources