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
# List comprehension | |
# Haskell | |
[x*2 | x <- [1..10]] #=> [2,4,6,8,10,12,14,16,18,20] | |
# Ruby | |
(1..10).map { |x| x*2 } #=> [2, 4, 6, 8, 10, 12, 14, 16, 18, 20] | |
# List comprehension with condition | |
# Haskell | |
[x*2 | x <- [1..10], x*2 >= 12] #=> [12,14,16,18,20] |
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 FastBeustSequence | |
class << self | |
def find_all(max) | |
@listener = [] | |
zero = Digit.new(nil, 0) | |
one = zero.next | |
start = Time.now | |
(1..10).each {|length| find(one, zero, length, 0, max, @listener)} | |
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
diff --git a/dygraph.js b/dygraph.js | |
index 3d3326e..374c355 100644 | |
--- a/dygraph.js | |
+++ b/dygraph.js | |
@@ -1521,8 +1521,18 @@ Dygraph.prototype.drawGraph_ = function(data) { | |
for (var i = 1; i < data[0].length; i++) { | |
if (!this.visibility()[i - 1]) continue; | |
+ // Reduce the resolution of the dataset if necessary. | |
+ var data_length = data.length |
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/local/bin/ruby | |
print "Input /^\\d \\d [NSEW] [LMR]+$/: " | |
raise "Bad input" unless input = gets.chomp.match(/^(\d+)\s(\d+)\s([NSEW])\s([LMR]+)$/) | |
x, y, direction, moves = input[1].to_i, input[2].to_i, input[3], input[4] | |
compass = %w{ N E S W } | |
i = compass.index(direction) | |
fns = lambda { y+=1 }, lambda { x+=1 }, lambda { y-=1 }, lambda { x-=1 } |
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/ruby | |
class RoverRemote | |
def initialize(cmds) | |
parse(cmds) | |
end | |
def parse(cmds) | |
cmds.split("\n").each do |cmd| | |
case cmd |
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 Article < ActiveRecord::Base | |
has_many :content_relationships, as: :origin, dependent: :destroy | |
has_many :related_articles, through: :content_relationships, source: :related_content, source_type: "Article" | |
has_many :related_videos, through: :content_relationships, source: :related_content, source_type: "Video" | |
end | |
class Video < ActiveRecord::Base | |
has_many :content_relationships, as: :origin, dependent: :destroy |
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
# lines 3..14 create a hash with squares of 2 pointing at their | |
# associated x,y coordinates as well as the inverse | |
width = 5 | |
left = [] | |
width.times { |i| left += [i] * (width + 1) } # [0,0,0,0,0,1,1,1,1,1..] | |
right = [*0..width] * width # [0,1,2,3,4,5,0,1,2,3,4,5..] | |
tuples = right.zip left # [[0, 0], [1, 0], [2, 0], [3, 0], [4, 0], [5, 0], [0, 1], [1, 1].. |
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
[core] | |
whitespace = indent-with-non-tab tab-in-indent trailing-space -blank-at-eof | |
[grep] | |
line-number = true | |
[help] | |
autocorrect = 1 | |
[alias] | |
st = status | |
di = diff | |
co = checkout |
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 'active_support/inflector' | |
constantize = lambda { |str| | |
result = "" | |
str.split("_").inject("") { |acc, klass| | |
begin | |
try = acc + klass.classify | |
try.constantize |
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 chunkify enum, out, limit, &block | |
enum.inject([]) do |acc, e| | |
size = (acc+[e]).join(",").size | |
if size > limit | |
out += yield(acc) | |
acc = [e] | |
elsif e == enum.last | |
out += yield(acc + [e]) | |
else |
OlderNewer