Skip to content

Instantly share code, notes, and snippets.

View jacegu's full-sized avatar
🦖
Juggling shipping and parenting

Javier Acero jacegu

🦖
Juggling shipping and parenting
View GitHub Profile
class Key
attr_reader :value
def initialize(value)
@value = value
end
end
k1 = Key.new('foo')
k2 = Key.new('foo')
class Key
include Comparable
attr_reader :value
def initialize(value)
@value = value
end
def <=>(other_key)
class Key
attr_reader :value
def initialize(value)
@value = value
end
def eql?(other_key)
value == other_key.value
end
@jacegu
jacegu / typoeus_vs_em.rb
Created August 17, 2012 07:06
Some Benchmarks
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
@jacegu
jacegu / issue_json.rb
Created September 11, 2012 08:06
What's wrong with this?
#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",
@jacegu
jacegu / link_header
Created September 20, 2012 09:46
LINK header api.github.com
@jacegu
jacegu / functional_gol.rb
Created December 9, 2012 19:38
Functional take on Conway's Game of Life
module Cell
def cell
{ state: :alive, neighbours: [] }
end
def dead_cell
{state: :dead, neighbours: []}
end
def neighbours_of(cell, neighbour_info)
@jacegu
jacegu / jacegu.zsh-theme
Created December 9, 2012 21:38
My theme for Oh My Zsh
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%})"
@jacegu
jacegu / lambda_syntax.rb
Created March 14, 2013 14:18
Weird behavior between ruby versions with ->{ } proc syntax. Any explanation?
#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 { ->{} }
@jacegu
jacegu / roman_numerals.erl
Created April 15, 2013 14:39
Roman numeral kata in erlang. Wondering if there is a better/more idiomatic way to approach the problem.
-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(_) -> "".