Skip to content

Instantly share code, notes, and snippets.

module IsContentChunk
def self.included(base)
base.class_eval do
named_scope :by_association, lambda{ |key| {:conditions => ['association = ?', key] } }
named_scope :regional_and_or_default, lambda{ |key| {
:include => [:region],
:conditions => ['association = ? AND ( region_id = ? OR region_id = ? )', key, self.current_region, Region.default],
:order => "FIELD(region_id, #{id_or_null( self.current_region )}, #{id_or_null( Region.default )})"
@gvarela
gvarela / gist:640963
Created October 22, 2010 17:05 — forked from tmm1/gist:329682
require 'rubygems'
require 'eventmachine'
require 'em-http' # gem install em-http-request
require 'yajl' # gem install yajl-ruby
class String
def bold
"\033[1m#{self}\033[0m"
end
end
@gvarela
gvarela / .cook
Created November 29, 2010 20:03
default developer image
{
"imagemagick": {"ghostscript": true},
"redis": {"launchd": true},
"rbenv": {"versions": ["1.9.3-p194"]},
"basic_brew": {"formulae": [
"bash-completion",
"wget"
]},
"cookbooks": ["https://github.com/modeset/osx-cookbooks/tarball/master", "https://github.com/gvarela/osx-cookbooks-ext/tarball/master"],
# include gems
gem 'pg'
gem 'haml-rails'
gem 'jquery-rails'
gem 'has_scope'
gem 'will_paginate'
gem 'simple_form'
gem 'utensils', github: 'modeset/utensils'
gem 'unicorn'
@gvarela
gvarela / nginx.conf
Created April 19, 2011 16:05
ssl proxy with nginx
server {
listen 443 ssl;
server_name sg-wholesale.dev;
ssl on;
ssl_certificate ssl/sg-wholesale.dev.crt;
ssl_certificate_key ssl/sg-wholesale.dev.key;
keepalive_timeout 60;
@gvarela
gvarela / Gemfile
Created May 5, 2011 16:30
web sockets with eventmachine and redis pub/sub
# A sample Gemfile
source "http://rubygems.org"
gem "redis"
gem 'eventmachine', :git => 'git://github.com/eventmachine/eventmachine.git'
gem "em-hiredis"
# gem "em-synchrony"
gem "em-websocket"
@gvarela
gvarela / spork
Created August 4, 2011 17:45
manage spork easily
#!/usr/bin/env bash
if [ $@ == 'start' ]
then
bundle exec spork &
rspec_pid=$!
bundle exec spork cucumber &
cuke_pid=$!
echo "$rspec_pid $cuke_pid" > tmp/spork.pids
exit
Then /^the following fields should be required:$/ do |fields|
fields.rows_hash.each do |field, custom_message|
node = find('input[type="submit"]', :message => "Unable to locate the submit button to click on")
node.click
Then %{the "#{field}" field should have the error "#{custom_message.presence || "can't be blank"}"}
end
end
@gvarela
gvarela / bindable.coffee
Created February 7, 2012 22:50
Light weight DI for client side components in CoffeScript..
class window.Bindable
constructor: (context=$('body'), @dataKey='bindable')->
@bindables = $("[data-#{@dataKey}]", context)
@instanceKey = "#{@dataKey}-instance"
bindAll: ->
@bind(el) for el in @bindables
@gvarela
gvarela / principleofcompletesurprise.coffee
Created May 31, 2012 21:44
principleofcompletesurprise.coffee
class MyButton
constructor: () ->
#do stuff....
@buildElement()
return @element # <-- never ever do this
build: ->