Skip to content

Instantly share code, notes, and snippets.

View marcosanson's full-sized avatar

Marco Sanson marcosanson

View GitHub Profile
require 'garner'
module Mongoid
module Document
module ClassMethods
# Find instances by ID or crtieria in the same order as the IDs provided.
# TODO: this can be done with an $or until MongoDB 2.6, see https://jira.mongodb.org/browse/SERVER-14083
def find_ordered(ids, criteria = nil)
return [] if ids.empty?
instances = criteria || self.find(ids)
@marcosanson
marcosanson / online divs count
Created October 10, 2012 08:32
how to count divs with one line of code (Ruby)
puts Nokogiri::HTML(open("http://example.com/example")).css("div.example").count
@marcosanson
marcosanson / Podfile
Created October 10, 2012 07:43
Podfile including library fork
platform :ios, :deployment_target => '5.0'
pod 'RestKit', '~> 0.10.3'
pod 'SDWebImage', '~> 2.7'
pod 'Facebook-iOS-SDK', '~> 3.1.1'
pod do |spec|
spec.name = 'KGNoise'
spec.version = '1.0.1'
spec.summary = 'Forked library to create gradient'
spec.author = { 'Marco Sanson' => 'marco.sanson@d-still.com' }
# unicorn_rails -c /data/github/current/config/unicorn.rb -E production -D
rails_env = ENV['RAILS_ENV'] || 'production'
# 16 workers and 1 master
worker_processes (rails_env == 'production' ? 16 : 4)
# Load rails+github.git into the master before forking workers
# for super-fast worker spawn times
preload_app true
WORDS = [ [ "husband", "wife" ], [ "brother", "sister"], [ "uncle", "nephew" ] ]
class String
def opposite
WORDS[WORDS.flatten.index(self)/2][WORDS.flatten.index(self)%2 == 0 ? 1 : 0]
end
end