This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var ApplicationHelpers = { | |
/** | |
* Note: requires Underscore.js | |
* | |
* Enable a (sencha touch) form to have a link between | |
* model and form (ie. MyModel.some_attribute <=> textfield.some_attribute) | |
* AND allow for POST / PUT submission in the rails-friendly namespaced format | |
* (ie. {my_model[some_attribute] : "some value"}). | |
* | |
* To get above behavior, treate model and forms in normal fashion and use |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Application helpers | |
* requires Underscore.js | |
*/ | |
var ApplicationHelpers = { | |
/** | |
* Railsify object's keys to play nice with default Rails controller setup. | |
* Rails default controller setup expects params submitted via PUT / POST as: | |
* | |
* (POST) {'my_model[attr1]' : 'value1', ... etc. } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Sencha | |
module NestedListMenu | |
class << self | |
# Sencha Touch nested list menu requires json in the form of: | |
# | |
# {"text": "some identifier", | |
# "children": ["text": "child identifier", "other": "info", "leaf": "true"], | |
# [ ... ] | |
# }, | |
# { ... } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def add(a, b) | |
a + b | |
end | |
def say(what, *people) | |
people.each { |person| puts "#{person}: #{what}" } | |
end | |
say "Hello!", "Bob", "Alice" | |
# Bob: Hello! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* PaceCar makes it easy to test how fast (or slow) you js runs | |
* | |
* Example Usage: | |
* | |
* // get a PaceCar ready | |
* var p = new PaceCar(); | |
* // start your engines | |
* p.start(); | |
* // some sample code you want to test performance of. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'bundler' | |
Bundler.require | |
require './app1' | |
require './app2' | |
map '/app1' do | |
run App1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module MakeTimeAgoable | |
extend ActiveSupport::Concern | |
included do | |
# code goes here that should be run on the actual include | |
# or just leave it blank. no one cares. where's my cake? | |
end | |
module ClassMethods | |
attr_reader :_time_agoable |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Mongoid | |
module CounterCache | |
extend ActiveSupport::Concern | |
module ClassMethods | |
# Use Case: | |
# | |
# keep a cached count of embedded collections in the parent collection(s) | |
# | |
# for example, if a Post embeds many Comments, and there have been 2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'bundler' | |
Bundler.require | |
require './application' | |
namespace :assets do | |
desc 'compile assets' | |
task :compile => [:compile_js, :compile_css] do | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# simulation to calculate an answer to the question: | |
# | |
# "In a country in which people only want boys, every family continues to have children until they have a boy. If they | |
# have a girl, they have another child. If they have a boy, they stop. What is the proportion of boys to girls in the | |
# country?" | |
# | |
# !/usr/bin/env ruby | |
# usage: ./family-sim.rb [trials] | |
# | |
# sample output: |