This file has been truncated, but you can view the full file.
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
function _classCallCheck(e, t) { | |
if (!(e instanceof t)) throw new TypeError("Cannot call a class as a function") | |
} | |
function _classCallCheck(e, t) { | |
if (!(e instanceof t)) throw new TypeError("Cannot call a class as a function") | |
} | |
function _classCallCheck(e, t) { | |
if (!(e instanceof t)) throw new TypeError("Cannot call a class as a function") |
This file has been truncated, but you can view the full file.
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
function _classCallCheck(e, t) { | |
if (!(e instanceof t)) throw new TypeError("Cannot call a class as a function") | |
} | |
function _classCallCheck(e, t) { | |
if (!(e instanceof t)) throw new TypeError("Cannot call a class as a function") | |
} | |
function _classCallCheck(e, t) { | |
if (!(e instanceof t)) throw new TypeError("Cannot call a class as a function") |
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 'spreadsheet' | |
def speadsheet_with_buffer | |
buf = StringIO.new | |
book = Spreadsheet::Workbook.new | |
sheet = book.create_worksheet :name => "New Worksheet" | |
sheet.row(0).concat %w{col_1, col_2, col_3} | |
sheet[1,0] = "next row, first column" | |
book.write buf |
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 RunningStat | |
attr_reader :n, :oldM, :newM, :oldS, :newS | |
def initialize | |
@n = 0 | |
end | |
def clear | |
@n = 0 | |
end |
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
# Four versions of the Fibonacci solution for the nth element | |
# Iterative | |
def fib(n) | |
if n < 2 | |
num = n | |
else | |
n1 = 1 | |
n2 = 0 | |
n-1.times do |i| |
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
# Originally viewed on Giorgio Gonnella's blog | |
# http://looks-interesting.blogspot.com/2009/07/simple-implementation-of-suffix-array.html | |
# added substring and binary search | |
class SuffixArray | |
attr_reader :suf, :string | |
def initialize(string) | |
@string = string |
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 | |
require 'pqueue' | |
class Graph | |
attr_reader :edges | |
INFINITY = 1 << 32 | |
def initialize(size) | |
@edges = Array.new(size) {Array.new(size)} | |
end |
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 BinaryTree | |
include Enumerable | |
attr_accessor :key, :data, :left, :right | |
def initialize(h) # assume h is form {:key => k, :data=>d} | |
@key = @data = nil | |
assign_key_data(h) | |
@left = @right = nil |