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 Key | |
attr_reader :value | |
def initialize(value) | |
@value = value | |
end | |
end | |
k1 = Key.new('foo') | |
k2 = Key.new('foo') |
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 Key | |
include Comparable | |
attr_reader :value | |
def initialize(value) | |
@value = value | |
end | |
def <=>(other_key) |
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 Key | |
attr_reader :value | |
def initialize(value) | |
@value = value | |
end | |
def eql?(other_key) | |
value == other_key.value | |
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
require 'em-http-request' #gem install em-http-request | |
require 'typhoeus' #gem install typhoeus | |
ENDPOINT = 'https://api.github.com/repos/rails/rails/issues' | |
ISSUE_PAGES = 6 | |
def benchmark(message, &code) | |
start_time = Time.now | |
code.call | |
end_time = Time.now |
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
#encoding: utf-8 | |
require 'json' | |
curl_json = `curl "https://api.github.com/repos/rails/rails/issues/7311"` | |
literal_json = %q{ | |
{ | |
"title": "Authentication With Token Problem", | |
"html_url": "https://github.com/rails/rails/issues/7311", |
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
⌘ ~ > curl "https://api.github.com/repos/rails/rails/issues?page=5&per_page=100" -I | |
HTTP/1.1 200 OK | |
Server: nginx | |
Date: Thu, 20 Sep 2012 09:42:30 GMT | |
Content-Type: application/json; charset=utf-8 | |
Connection: keep-alive | |
Status: 200 OK | |
X-Content-Type-Options: nosniff | |
X-GitHub-Media-Type: github.beta | |
Vary: Accept |
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 Cell | |
def cell | |
{ state: :alive, neighbours: [] } | |
end | |
def dead_cell | |
{state: :dead, neighbours: []} | |
end | |
def neighbours_of(cell, neighbour_info) |
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
PROMPT='%{$fg_bold[black]%}⌘ %{$reset_color%}%~ $(git_prompt_info)%{$fg[black]%}❯ %{$reset_color%}' | |
ZSH_THEME_GIT_PROMPT_PREFIX="%{$reset_color%}(➥ %{$reset_color%}%{$fg[cyan]%}" | |
ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%} " | |
ZSH_THEME_GIT_PROMPT_DIRTY=" %{$reset_color%}%{$fg[red]%}✗%{$reset_color%})" | |
ZSH_THEME_GIT_PROMPT_CLEAN=" %{$reset_color%}%{$fg[green]%}✓%{$reset_color%})" |
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
#ruby 1.9.2-p320 | |
BasicObject.new.instance_eval { ->{} } | |
#NoMethodError: undefined method `lambda' for #<BasicObject:0x007f97eb198590> | |
# from (irb):6:in `block in irb_binding' | |
# from (irb):6:in `instance_eval' | |
# from (irb):6 | |
# from /Users/jacegu/.rbenv/versions/1.9.2-p320/bin/irb:12:in `<main>' | |
#ruby 1.9.3-p392 | |
BasicObject.new.instance_eval { ->{} } |
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(kata). | |
-include_lib("eunit/include/eunit.hrl"). | |
to_roman(Arabic) when Arabic >= 50 -> string:concat("L", to_roman(Arabic - 50)); | |
to_roman(Arabic) when Arabic >= 10 -> string:concat("X", to_roman(Arabic - 10)); | |
to_roman(Arabic) when Arabic >= 5 -> string:concat("V", to_roman(Arabic - 5)); | |
to_roman(Arabic) when Arabic =:= 4 -> string:concat("IV", to_roman(Arabic - 4)); | |
to_roman(Arabic) when Arabic >= 1 -> string:concat("I", to_roman(Arabic - 1)); | |
to_roman(_) -> "". |