Skip to content

Instantly share code, notes, and snippets.

@wxmn
wxmn / embedded_documents.rb
Created November 6, 2010 20:04
Examples of Atomic Operations on Embedded Documents in MongoMapper
#Stories are embedded docs in a Feed
class Feed
include MongoMapper::Document
many :stories
end
class Story
include MongoMapper::EmbeddedDocument
key :title, String
@wxmn
wxmn / smart_worker.rb
Created March 21, 2011 23:57
Slight improvements to Simple Worker base class
class SmartWorker < SimpleWorker::Base
merge "../../vendor/some_gem/lib/some_gem.rb"
def initialize(args={})
args.each do |k, v|
instance_variable_set "@#{k.to_s}", v
instance_eval "class << self; attr_accessor :#{k.to_s}; end"
end
end
@wxmn
wxmn / popular.rb
Created March 24, 2011 19:52
How to Extend Your Models in Rails
@wxmn
wxmn / redis_helper.rb
Created March 31, 2011 13:23
How to Build a Fast News Feed in Redis and Rails
module RedisHelper
# decode Redis value back to Ruby object
def self.decode(json)
self.new(ActiveSupport::JSON.decode(json)["#{self.name.downcase}"])
end
# encode Ruby object for Redis
def encoded
self.updated_at = nil
self.to_json
@wxmn
wxmn / gist:1010292
Created June 6, 2011 13:47
brew install geos errors (10.7)
# brew doctor output
We couldn't detect gcc 4.0.x. Some formulae require this compiler.
/usr/bin is in your PATH before Homebrew's bin. This means that system-
provided programs will be used before Homebrew-provided ones. This is an
issue if you install, for instance, Python.
Consider editing your .bashrc to put:
/usr/local/bin
@wxmn
wxmn / gist:1161154
Created August 21, 2011 20:57
Growl Notifications with Campfire / Fluid
// ==UserScript==
// @name Growl Notifications with messages for campfire and fluid
// @namespace http://tim.theenchanter.com/
// @description If your name is mentioned in a message, a growl notification shows what was said.
// @author Tim Harper
// @homepage http://tim.theenchanter.com/
// @include *.campfirenow.com/room*
// ==/UserScript==
try { if ( typeof(Campfire) != "undefined" ) {
defaults: &defaults
autocreate_indexes: false
allow_dynamic_fields: false
include_root_in_json: true
parameterize_keys: true
persist_in_safe_mode: true
raise_not_found_error: false
reconnect_time: 3
# slaves:
# - host: slave1.local
-----> Heroku receiving push
-----> Removing .DS_Store files
-----> Ruby/Rails app detected
/usr/local/lib/ruby/1.9.1/fileutils.rb:243:in `mkdir': Permission denied - /mnt/slug-compiler/language_packs/ruby/vendor (Errno::EACCES)
from /usr/local/lib/ruby/1.9.1/fileutils.rb:243:in `fu_mkdir'
from /usr/local/lib/ruby/1.9.1/fileutils.rb:217:in `block (2 levels) in mkdir_p'
from /usr/local/lib/ruby/1.9.1/fileutils.rb:215:in `reverse_each'
from /usr/local/lib/ruby/1.9.1/fileutils.rb:215:in `block in mkdir_p'
from /usr/local/lib/ruby/1.9.1/fileutils.rb:201:in `each'
from /usr/local/lib/ruby/1.9.1/fileutils.rb:201:in `mkdir_p'
@wxmn
wxmn / mongoid.yml
Created October 25, 2011 13:38
MongoHQ Replicate Set Config
defaults: &defaults
autocreate_indexes: false
allow_dynamic_fields: false
include_root_in_json: true
parameterize_keys: true
persist_in_safe_mode: true
raise_not_found_error: false
reconnect_time: 3
# slaves:
# - host: slave1.local
@wxmn
wxmn / config.log
Created December 3, 2011 20:11
Homebrew postgres 9.1 errors in config.log
This file contains any messages produced by compilers while
running configure, to aid debugging if configure makes a mistake.
It was created by PostgreSQL configure 9.1.1, which was
generated by GNU Autoconf 2.63. Invocation command line was
$ ./configure --disable-debug --prefix=/usr/local/Cellar/postgresql/9.1.1 --enable-thread-safety --with-bonjour --with-gssapi --with-krb5 --with-openssl --with-libxml --with-libxslt --with-ossp-uuid --datadir=/usr/local/Cellar/postgresql/9.1.1/share/postgresql --docdir=/usr/local/Cellar/postgresql/9.1.1/share/doc/postgresql
## --------- ##
## Platform. ##