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
Greeter = Object.new | |
class << Greeter | |
def greet(name) | |
"HELLO, #{normalize(name)}!" | |
end | |
private | |
def normalize(name) |
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
'use strict'; | |
module.exports = function(grunt) { | |
// load all grunt tasks | |
require('matchdep').filterDev('grunt-*').forEach(grunt.loadNpmTasks); | |
// configurable paths | |
var paths = { |
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(chopstick). | |
-export([start/1, loop/2]). | |
start(Number) -> | |
spawn(chopstick, loop, [Number, nobody]). | |
loop(Number, Owner) -> | |
receive | |
{take, Owner} -> loop(Number, Owner); | |
{take, NewOwner} when Owner =:= nobody -> |
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
# Given a controller that looks like this | |
class ModelsController < ApplicationController | |
load_and_authorize_resource #CanCan | |
def show | |
if stale? @model | |
respond_to do |format| | |
format.json do | |
@model | |
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
defmodule Fun do | |
def arity(fun) do | |
case :erlang.fun_info(fun, :arity) do | |
{ :arity, arity } -> | |
arity | |
end | |
end | |
def adapt!(fun, 0) do | |
fn -> fun.([]) 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
/** | |
* Multipromise | |
* | |
* A jQuery.Deferred() - like promise implementation | |
* that supports adding multiple child promises to it. | |
* done / fail callbacks will trigger multiple times as child promises are resolved / rejected | |
* Useful for streaming promise-based data flows | |
* | |
* Example | |
* |
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
CREATE VIEW product_stats AS | |
SELECT organization_id, | |
SUM(CASE WHEN status = 'active' THEN 1 END) active_count, | |
SUM(CASE WHEN status = 'inactive' THEN 1 END) inactive_count | |
FROM products | |
GROUP BY organization_id |
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
#!/usr/bin/env bash | |
curl https://s3.amazonaws.com/heroku-jvm-buildpack-vi/vim-7.3.tar.gz --output vim.tar.gz | |
mkdir vim && tar xzvf vim.tar.gz -C vim | |
export PATH=$PATH:/app/vim/bin |
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
z = fn | |
f -> fn | |
x -> f.(fn y -> x.(x).(y) end) | |
end.(fn | |
x -> f.(fn y -> x.(x).(y) end) | |
end) | |
end | |
add_squares = z.(fn | |
f -> fn |
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
items = %w{foo bar baz goo gar gaz hoo har haz} | |
def recurse_array(ary, &block) | |
head, *tail = ary | |
head and block.call(head) | |
tail.any? and recurse_array(tail, &block) | |
end | |
puts "First the items in order:\n" | |
recurse_array items do |item| |