def doit(arr, *vals_at)
arr.each_slice(2)
.map {|s1,s2|
[s1.split.last.to_i,[s1.tr(' ','').to_sym, s2.scan(/\d+/).map(&:to_i)]]}
.to_h
.values_at(*vals_at)
.to_h
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
require 'set' | |
require 'benchmark/ips' | |
def process_old(list) | |
list.join(" ").split.uniq | |
end | |
def process_set(list) | |
unique = Set.new | |
list.each {|str| unique.merge(str.split) } |
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
require "benchmark/ips" | |
def falsetru(a) | |
rank = 1 | |
a.group_by {|x| x } | |
.map { |k,v| | |
ret = [rank] * v.size | |
rank += v.size | |
ret | |
}.flatten |
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
Calculating ------------------------------------- | |
falsetru 419 i/100ms | |
sawa 514 i/100ms | |
Jordan 1438 i/100ms | |
Iceman 57 i/100ms | |
------------------------------------------------- | |
falsetru 4232.8 (±2.5%) i/s - 21369 in 5.051639s | |
sawa 5032.0 (±3.5%) i/s - 25186 in 5.011681s | |
Jordan 15057.5 (±2.7%) i/s - 76214 in 5.065319s | |
Iceman 575.7 (±1.9%) i/s - 2907 in 5.051481s |
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
arr = [89, 52, 52, 36, 18, 18, 18, 7] | |
def rank_em(arr, accum=[], rank=0, run=0, last_head=nil) | |
head, *rest = arr | |
return accum if head.nil? | |
run += 1 | |
unless head == last_head | |
rank += run | |
run = 0 |
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
#!/usr/bin/env ruby | |
require "webrick" | |
server = WEBrick::HTTPServer.new(Port: 8080, DocumentRoot: Dir::pwd) | |
trap("INT") { server.shutdown } | |
server.start |
This CoffeeScript...
->
return if true
console.log "foo"
...compiles to...
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
class College < ActiveRecord::Base | |
scope :ranked_at_least, ->(rank_low=nil) { | |
# If no value is given just return self without adding any conditions | |
if rank.nil? then self | |
else where("us_news_ranking <= ?", rank_low) | |
end | |
} | |
scope :with_sat_composite { | |
# Using an array for select() instead of a string means we can can chain |
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
NoMethodError - undefined method `foo' for "bar":String: | |
(gem) rabl-rails-0.3.3/lib/rabl-rails/renderers/base.rb:68:in `block in render_resource' | |
(gem) rabl-rails-0.3.3/lib/rabl-rails/renderers/base.rb:64:in `each' | |
(gem) rabl-rails-0.3.3/lib/rabl-rails/renderers/base.rb:64:in `inject' | |
(gem) rabl-rails-0.3.3/lib/rabl-rails/renderers/base.rb:64:in `render_resource' | |
(gem) rabl-rails-0.3.3/lib/rabl-rails/renderers/base.rb:116:in `block in render_collection' | |
(gem) rabl-rails-0.3.3/lib/rabl-rails/renderers/base.rb:116:in `each' | |
(gem) rabl-rails-0.3.3/lib/rabl-rails/renderers/base.rb:116:in `map' | |
(gem) rabl-rails-0.3.3/lib/rabl-rails/renderers/base.rb:116:in `render_collection' | |
(gem) rabl-rails-0.3.3/lib/rabl-rails/renderers/base.rb:32:in `block in render' |
Original: https://github.com/starlock/vino/wiki/API-Reference
The one and only public documentation of Vine.app 1.0.3
user-agent: com.vine.iphone/1.0.3 (unknown, iPhone OS 6.1.0, iPhone, Scale/2.000000)
vine-session-id: -1231ed86-80a0-4f07-9389-b03199690f73