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
| # A sample Gemfile | |
| source "https://rubygems.org" | |
| # gem "rails" | |
| gem 'haml' |
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 SendAll | |
| def send_all(methods_and_args) | |
| return self if methods_and_args.empty? | |
| method_name, args = methods_and_args.pop | |
| result = send method_name, *args | |
| result.send_all result, query | |
| end | |
| end | |
| class ActiveRecord::Relation |
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
| # #fire | |
| # Takes: r (A-J),c (1-10) | |
| # Returns: MISS, HIT, SUNK, WIN, ()DUPE) | |
| # #place | |
| # Takes: r (A-J),c (1-10), Ship object | |
| # Returns success/failure as a boolean | |
| class Board | |
| ROWS = 'ABCDEFGHIJ'.split(//) |
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
| fns = | |
| '+': (a,b) -> a + b | |
| '*': (a,b) -> a * b | |
| parse = (input) -> | |
| JSON.parse(input.replace(/\s/g,",").replace(/\+|\*/g, '"$&"')) | |
| evaluate = (x)-> | |
| if (Array.isArray(x)) # x is an expression | |
| results = x.map (expression) -> evaluate(expression) |
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
| assert = require 'assert' | |
| _ = require 'lodash' | |
| globals = | |
| '+': (a,b) -> a + b | |
| '*': (a,b) -> a * b | |
| parse = (input) -> | |
| JSON.parse(input.replace(/\s/g,",").replace(/[a-z\+\*]+/g, '"$&"')) |
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
| class Array | |
| def frequencies(&block) | |
| block ||= ->(x) {x} | |
| Hash[group_by(&block).map {|k,v| [k, v.present? ? v.count : nil]} ] | |
| end | |
| end |
OlderNewer