Skip to content

Instantly share code, notes, and snippets.

# encoding: utf-8
module Mongoid #:nodoc:
module Associations #:nodoc:
module EmbeddedCallbacks
def _send_to_each_embedded_document(method, *args, &block)
self.class.associations.each_pair do |name, meta|
if meta.association == Mongoid::Associations::EmbedsMany
assoc = self.send(name)
@mcasimir
mcasimir / css_base.css
Created July 8, 2011 22:11
Yahoo CSS Reset + Yahoo Base (i've changed a little the default padding/margin with headings) + Minimal helpers: Clearfix (.cfix), Float (.fl, .fr, .clear), Horizontal Lists (ul.hl, ol.hl), List separator (li.sep, li.separator) helpers.
html{color:#000;background:#FFF}body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,code,form,fieldset,legend,input,button,textarea,select,p,blockquote,th,td{margin:0;padding:0}table{border-collapse:collapse;border-spacing:0}fieldset,img{border:0}address,button,caption,cite,code,dfn,em,input,optgroup,option,select,strong,textarea,th,var{font:inherit}del,ins{text-decoration:none}li{list-style:none}caption,th{text-align:left}h1,h2,h3,h4,h5,h6{font-size:100%;font-weight:normal}q:before,q:after{content:''}abbr,acronym{border:0;font-variant:normal}sup{vertical-align:baseline}sub{vertical-align:baseline}legend{color:#000}body{font:13px/1.231 arial,helvetica,clean,sans-serif;*font-size:small;*font:x-small}select,input,textarea,button{font:99% arial,helvetica,clean,sans-serif}table{font-size:inherit;font:100%}pre,code,kbd,samp,tt{font-family:monospace;*font-size:108%;line-height:100%}h1{font-size:138.5%}h2{font-size:123.1%}h3{font-size:108%}h1,h2,h3{padding:0 0 0.5em}h1,h2,h3,h4,h5,h6,strong,dt{font-weight:bold}optgroup
@mcasimir
mcasimir / grammar.pegjs
Created January 17, 2012 18:00
Passing parameters to PEG.js Parser
{
var thisParser = this;
function resolveSymbol(parser, sym){
return (parser.symbols || {})[sym];
}
function flatten(array){
var flat = [];
for (var i = 0, l = array.length; i < l; i++){
@mcasimir
mcasimir / README.md
Created May 7, 2012 17:19
FriendlyIdSchema is a micro gem for Ruby on Rails with which you can add permalinks to models with ActiveRecordSchema and FriendlyId

FriendlyIdSchema

FriendlyIdSchema is a micro gem that combines FriendlyId with ActiveRecordSchema

Usage

Call #permalink inside a model like this:

class Post
Gem::Specification.new do |s|
s.name = 'paperclip_schema'
s.summary = 'A Ruby Micro Gem for use Paperclip with ActiveRecordSchema and S3.'
s.version = '0.0.2'
s.platform = Gem::Platform::RUBY
s.files = %w(paperclip_schema.rb)
s.require_path = '.'
s.author = 'Maurizio Casimirri'
@mcasimir
mcasimir / tm_create_and_open.rb
Created May 19, 2012 10:18
Create and open file bundle for Textmate 2
#!/usr/bin/env ruby -wKU
# Create and open file bundle for Textmate 2
# Key equivalent: @N
$: << ENV['TM_SUPPORT_PATH'] + '/lib'
require "ui"
filename = TextMate::UI.request_string(:title => "Create and open file",
:prompt => "Enter the file name",
@mcasimir
mcasimir / google_fonts_helper.gemspec
Created May 24, 2012 00:01
Google fonts helper for Ruby on Rails
Gem::Specification.new do |s|
s.name = 'google_fonts_helper'
s.summary = 'Google fonts helper for Ruby on Rails'
s.version = '0.0.1'
s.platform = Gem::Platform::RUBY
s.files = %w(google_fonts_helper.rb)
s.require_path = '.'
s.author = 'Maurizio Casimirri'
@mcasimir
mcasimir / static_map_helper.rb
Created May 24, 2012 01:32
Google Maps Static map helper for Ruby on Rails
module StaticMapHelper
def static_map_for(location, options = {})
params = {
:center => [location.lat, location.lng].join(","),
:zoom => 15,
:size => "300x300",
:markers => [location.lat, location.lng].join(","),
:sensor => true
}.merge(options)
@mcasimir
mcasimir / default
Created June 19, 2012 10:09
Default apache2 vhost
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
@mcasimir
mcasimir / wp-new.sh
Created June 19, 2012 10:16
Wordpress blog setup script
#!/bin/bash
MyUSER="root" # USERNAME
MyPASS="spigola2" # PASSWORD
WpMySqlUser="wpuser"
WpMySqlPass="spigola2"
MyHOST="localhost" # Hostname