Skip to content

Instantly share code, notes, and snippets.

@rrichards
rrichards / rhino_template.rb
Created April 7, 2009 23:47
rails template for skeleton app, haml, sass, shoulda, factory_girl, jquery
# Set up git repository
git :init
# Copy database.yml for distribution use
run "cp config/database.yml config/database.yml.example"
# Set up .gitignore files
run %{find . -type d -empty | xargs -I xxx touch xxx/.gitignore}
file '.gitignore', <<-END
.DS_Store
@ghoseb
ghoseb / redis_memo.clj
Created January 1, 2010 11:31 — forked from purcell/redis_memo.clj
Clojure Memoize to Redis
(ns redis-memo
(:require redis)
(:import (java.net URLEncoder)))
;; --------------------------------------------------------------------------------
;; Default connection params
;; --------------------------------------------------------------------------------
(def memo-server {:host "localhost" :port 6379 :db 14})
;;
;; NS CHEATSHEET
;;
;; * :require makes functions available with a namespace prefix.
;;
;; * :use makes functions available without a namespace prefix
;; (i.e., refers functions to the current namespace).
;;
;; * :import refers Java classes to the current namespace.
;;
class HexNum < Numeric
# Create a new instance from an int or String.
def initialize(val)
case val
when String
@i = parse_string(val)
@s = val.frozen? ? val : val.dup.freeze
when Numeric
@i = val.to_i
;annotation syntax
(import [java.lang.annotation Retention RetentionPolicy Target ElementType]
[javax.xml.ws WebServiceRef WebServiceRefs])
(definterface Foo (foo []))
;annotation on type
(deftype ^{Deprecated true
Retention RetentionPolicy/RUNTIME
javax.annotation.processing.SupportedOptions ["foo" "bar" "baz"]
@wagenet
wagenet / model.js
Created May 13, 2010 19:41
SproutCore Rails DataSource
MyApp.MyModel.mixin({
resourcePathFor: function(action, storeKey, item) {
var id, path;
id = storeKey ? MyApp.store.idFor(storeKey) : null;
switch(action) {
case 'fetch':
case 'create':
path = 'items';
require 'peach'
[1,2,3,4].peach{ |n| n + 1 } #Spawns 4 threads
[1,2,3,4].pmap{ |x| f(x) } #Spawns 4 threads, returns => [f(1),f(2),f(3),f(4)]
[1,2,3,4].pselect{ |x| x > 2 } #Spawns 4 threads, returns => [3,4]
@devn
devn / Destructuring Examples.clj
Created June 15, 2010 09:27
Destructuring Examples
;;; All Kinds of Destructuring ;;;
(let [foo 1] foo)
; => 1
(let [[foo bar] [1 2 3]] [foo bar])
; => [1 2]
(let [[foo bar & baz] [1 2 3]] [foo bar baz])
; => [1 2 (3)]
class AppBuilder < Rails::AppBuilder
include Thor::Actions
include Thor::Shell
def test
append_test_gems
rspec
cucumber
jasmine
end
source :rubygems
gem 'rails'
# Or find something else that returns true
# locally, but false on heroku
if RbConfig::CONFIG['host_os'] =~ /darwin/
group :test do
# heroku fails hard on this gem
gem 'specjour'