Skip to content

Instantly share code, notes, and snippets.

View semarco's full-sized avatar

Marco Sehrer semarco

View GitHub Profile
@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

.

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={})
@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
@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
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);
@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)
@icebreaker
icebreaker / mongoid-cheatsheet.md
Created February 15, 2011 09:11
Mongoid cheat sheet