This file contains 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 sign_in(user) | |
cookies.permanent.signed[:remember_token] = [user.id, user.salt] | |
current_user = user | |
# self.current_user = user will work though | |
raise "#sign_in --> @current_user is still nil" unless @current_user == user | |
# gross hack; otherwise the method returns nil since raise would be last line | |
user | |
end |
This file contains 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
let rec elem x xs = | |
match xs with | |
| [] -> false | |
| y :: ys -> x = y || elem x ys | |
let rec uniques l = | |
let rec helper l acc = | |
match l with | |
| [] -> acc | |
| x :: xs -> |
This file contains 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
# | |
# Adding Python-ish decorations to Ruby! | |
# | |
# Usage: | |
# | |
# class Foo | |
# extend WithDecorations | |
# | |
# decorate :bar do |b| | |
# puts "Do something here before bar gets invoked!" |
This file contains 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
Monads are composed of three ingredients. | |
First, for a given monad m, there are monadic values of type m a, for some type | |
variable a. In Haskell, if a variable x has type t, we write x :: t. | |
Here's a picture of a monadic value of type m a. | |
+--------\ | |
| | \ | |
| m | a > :: m a |
This file contains 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
import Control.Monad (mapM_) | |
main :: IO () | |
main = printSolutions 24 [1,3,4,6] "+-*/" | |
data BareTree a = BLeaf a | BBranch (BareTree a) (BareTree a) deriving Show | |
type Op = Char | |
toOp :: (Fractional a) => Op -> (a -> a -> a) |
This file contains 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
;; Beginner's attempt at adding list comprehensions to Common Lisp. | |
;; Examples: | |
;; (for ((x '(1 2 3))) (* x x)) # => (1 4 9) | |
;; (for ((x '(1 2)) (y '(a b))) (list x y)) # => ((1 a) (1 b) (2 a) (2 b)) | |
(defun foldr (f z xs) | |
(cond ((null xs) z) | |
(t (funcall f (car xs) (foldr f z (cdr xs)))))) |
This file contains 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
$(function() { | |
var Template = Backbone.Model.extend({ | |
url: function() { | |
return 'templates/' + this.get('name'); | |
}, | |
isReady: function() { | |
return this.get('src'); | |
}, |
This file contains 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
SM = function(options) { | |
console.log(options); | |
options || (options = {}); | |
this.current = (options['start'] || this.current || 'start'); | |
this._transitions = {}; | |
this._leaves = {}; | |
this._enters = {}; | |
this._allowed = {}; | |
}; |
This file contains 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
(defrecord Tree [id pid children]) | |
(def comments [{:id 1 :pid 0} | |
{:id 2 :pid 1} | |
{:id 3 :pid 1} | |
{:id 4 :pid 3} | |
{:id 5 :pid 3} | |
{:id 6 :pid 3} | |
{:id 7 :pid 2} | |
{:id 8 :pid 7}]) |
This file contains 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
import json | |
import urllib | |
import urllib2 | |
url = "https://api.github.com/gists" | |
data = {'description': 'gistin from a script', | |
'public': True, | |
'files': { | |
'foobarbaz.txt' : {'content': 'foo bar baz' } | |
}} |
OlderNewer