Skip to content

Instantly share code, notes, and snippets.

@fcoury
fcoury / mongomapper_polymorphic.rb
Created July 19, 2009 08:25
Example of polymorphic one to many association using mongomapper
require 'mongomapper'
class Media
include MongoMapper::EmbeddedDocument
key :file, String
end
class Video < Media
key :length, Integer
end
@alexg0
alexg0 / Rakefile
Created April 16, 2010 18:02
for chef-repo - load and dump data bags
# ...
# append following lines
Dir[ File.join(File.dirname(__FILE__), 'tasks', '*.rake') ].sort.each do |f|
load f
end
@skojin
skojin / irb_require_without_bundler_hack.rb
Created January 25, 2011 13:33
workaround to load irb specific gem (loaded in .irbrc) in bundler environment, like rails3 console
# Add all gems in the global gemset to the $LOAD_PATH so they can be used in rails3 console with bundler
if defined?(::Bundler)
$LOAD_PATH.concat Dir.glob("#{ENV['rvm_path']}/gems/#{ENV['rvm_ruby_string']}@global/gems/*/lib")
end
@rheaton
rheaton / tracker_csv_export_to_pdf.rb
Created March 30, 2011 15:38
takes a csv file from tracker and makes story cards. be careful of the order when you are cutting them up.
#!/usr/bin/env ruby
# Script to generate PDF cards suitable for planning poker
# from Pivotal Tracker [http://www.pivotaltracker.com/] CSV export.
# Inspired by Bryan Helmkamp's http://github.com/brynary/features2cards/
# Example output: http://img.skitch.com/20100522-d1kkhfu6yub7gpye97ikfuubi2.png
require 'rubygems'
@leotsem
leotsem / default.vcl.pl
Created September 27, 2011 23:07 — forked from rinaldifonseca/default.vcl.pl
A good varnish config for a Rails app
# https://www.varnish-cache.org/docs/2.1/tutorial/vcl.html
# https://www.varnish-cache.org/trac/wiki/VCLExamples
# Summary
# 1. Varnish will poll the backend at /health_check to make sure it is
# healthy. If the backend goes down, varnish will server stale content
# from the cache for up to 1 hour.
# 2. Varnish will pass X-Forwarded-For headers through to the backend
# 3. Varnish will remove cookies from urls that match static content file
# extensions (jpg, gif, ...)
@practicingruby
practicingruby / 1_rcat_tests.rb
Last active September 27, 2015 15:47
Implementing a clone of UNIX cat in Ruby
# Task: Implement the rcat utility and get these tests to pass on a system
# which has the UNIX cat command present
# To see Gregory Brown's solution, see http://github.com/elm-city-craftworks/rcat
# Feel free to publicly share your own solutions
rrequire "open3"
working_dir = File.dirname(__FILE__)
gettysburg_file = "#{working_dir}/data/gettysburg.txt"
config.model PagePart do
edit do
field :content, :text do
ckeditor do
true
end
end
end
end
@rstacruz
rstacruz / index.md
Last active November 3, 2023 09:56
Rails models cheatsheet

Rails Models

Generating models

$ rails g model User

Associations

belongs_to

has_one

@pamelafox
pamelafox / bootstrap.datepicker.js
Created February 8, 2012 05:12
jQuery/Zepto Bootstrap Datepicker
/* ===========================================================
* bootstrap-datepicker.js v1.3.0
* http://twitter.github.com/bootstrap/javascript.html#datepicker
* ===========================================================
* Copyright 2011 Twitter, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
@NewAlexandria
NewAlexandria / rbenv_ree_install.sh
Created February 13, 2012 21:11
Installing Ruby Enterprise Edition into rbenv
########
# This file script wil show you how to install Ruby Enterprise Edition (REE) 1.8.7-2011-12 with
# rbenv, rails 3 and homebrew. Bundler is also used.
########
#setup the installer environment
brew install wget
wget -q http://rubyenterpriseedition.googlecode.com/files/ruby-enterprise-1.8.7-2011.12.tar.gz
tar xzf ruby-enterprise-1.8.7-2011.12.tar.gz