Skip to content

Instantly share code, notes, and snippets.

@ches
ches / embedded_callbacks.rb
Created December 30, 2010 13:22 — forked from zerobearing2/embedded_callbacks.rb
bubble down callbacks to embedded associations with mongoid
# encoding: utf-8
module Mongoid #:nodoc:
module Associations #:nodoc:
module EmbeddedCallbacks
# bubble callbacks to embedded associations
def run_callbacks(kind, *args, &block)
# now bubble callbacks down
self.associations.each_pair do |name, meta|
if meta.association == Mongoid::Associations::EmbedsMany

SciPy, PyQt and Matplotlib on OS X Snow Leopard

The squeeky-clean way with homebrew and pip/virtualenv.

$ easy_install pip
$ pip install virtualenvwrapper mercurial
$ brew install gfortran && brew install pyqt
# Have a nice long coffee break -- compiling Qt took 67 minutes on my

quad-core i7 MBP, PyQt another 8.

@ches
ches / tags_input.rb
Created January 16, 2011 18:08
simple_form input builder for use with my mongoid_taggable fork
# Example simple_form input builder to render tags from an Array field,
# for use with my fork of mongoid_taggable:
#
# https://github.com/ches/mongoid_taggable
#
# Once you've configured your app to load this, use it in forms thusly:
#
# <%= f.input :tags, :as => :tags %>
#
module SimpleForm
@ches
ches / post-checkout
Created February 7, 2011 13:17
post-checkout git hook to intelligently run `bundle` if Gemfile was changed
#!/bin/sh
# Via http://tbaggery.com/2011/02/07/bundle-while-you-git.html
# Save as http://.git/hooks/post-checkout in your project and `chmod +x`
# See the post for how to tell Git you want this in new/newly cloned repos
if [ $1 = 0000000000000000000000000000000000000000 ]; then
# Special case for initial clone: compare to empty directory.
old=4b825dc642cb6eb9a060e54bf8d69288fbee4904
else
@ches
ches / rvm-prompt.sh
Created February 20, 2011 16:02
An example of a bash prompt showing RVM Ruby version and active gemset
RED="\[\033[01;31m\]"
GREEN="\[\033[01;32m\]"
COLOR_NONE="\[\033[0m\]"
function ruby_version {
if [[ -f ~/.rvm/bin/rvm-prompt ]]; then
local system=$(~/.rvm/bin/rvm-prompt s)
local interp=$(~/.rvm/bin/rvm-prompt i)
if [[ ! -n $system ]]; then
# Don't show interpreter if it's just MRI
@ches
ches / gist:836095
Created February 20, 2011 16:52
Get Started with Ruby Hacking using RVM
# Getting Started with Ruby Development Using RVM
#
# You may need to first install curl and git -- on Ubuntu:
#
# sudo apt-get install curl git-core
#
# On OS X curl should already be present. You can install Git from a binary
# installer, or using Homebrew, for the enlightened.
#
# The output of RVM installation will give you some useful information, such
@ches
ches / multi_parameter_attributes.rb
Created March 3, 2011 19:05
Monkey patch Mongoid multi-parameter attribute handling for validates_timeliness
# This monkey patches Mongoid's multi-parameter attribute handling in the same
# way that the enable_multiparameter_extension! option of validates_timeliness
# does for ActiveRecord -- to enable it to gracefully return errors to the user
# when they enter a date like February 30th.
#
# This is not thoroughly tested yet, but appears to work for Date fields at
# least. Last tested with (I think) Mongoid 2.0.0.beta20
module Mongoid #:nodoc:
module MultiParameterAttributes #:nodoc:
@ches
ches / pow
Created April 14, 2011 07:43
A quick script to switch between running Pow and Apache on OS X
#!/bin/sh -e
#/ Usage: pow [on|off]
#/ Toggle between running Pow (http://pow.cx) and Apache on Mac OS X.
# Show Usage
function usage {
grep '^#/' "$0" | cut -c4-
exit 2
}
[ -z "$1" -o "$1" = "--help" ] && usage
@ches
ches / configure
Created April 15, 2011 07:37
attempt to install duo_unix-1.5 on Ubuntu
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /bin/mkdir -p
checking for gawk... no
checking for mawk... mawk
checking whether make sets $(MAKE)... yes
checking whether to enable maintainer-specific portions of Makefiles... no
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
checking for gcc... gcc
diff --git a/Library/Formula/pms.rb b/Library/Formula/pms.rb
index f5d8d13..66a748c 100644
--- a/Library/Formula/pms.rb
+++ b/Library/Formula/pms.rb
@@ -5,12 +5,18 @@ class Pms <Formula
homepage 'http://pms.sourceforge.net'
md5 '8ebd65c5e6e33cd0ca79817a5e823805'
+ depends_on 'pkg-config' => :build
depends_on 'glib'