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 FactoryGirlHelper | |
BLACKLIST = [:user] | |
def first(args) | |
name = args.first | |
klass = name.to_s.camelize.constantize | |
conditions = args.last | |
if conditions.present? && conditions.is_a?(Hash) |
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
# Print all combinations of balanced parentheses of length n | |
def recurse(str:, open:, closed:, n:) | |
if open + closed == n - 1 | |
str += ')' | |
p str | |
else | |
if open < n / 2 | |
recurse(str: str + '(', open: open + 1, closed: closed, n: n) | |
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
/** | |
* Original original code (Java) by Neil Wallis | |
* @link http://www.neilwallis.com/java/water.html | |
* | |
* Original JS code by Sergey Chikuyonok ([email protected]) | |
* http://chikuyonok.ru | |
*/ | |
(function(){ | |
var canvas = document.getElementById('c'), | |
/** @type {CanvasRenderingContext2D} */ |
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 Graph | |
def initialize | |
@nodes = [] | |
end | |
def add_node(name) | |
fail 'Node already exists!' if find_node(name) | |
nodes << Node.new(name) | |
nodes.last | |
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
module Sort | |
def mergesort!(a) | |
a.replace(mergesort(a)) | |
end | |
def mergesort(a) | |
return a if a.length <= 1 | |
halfway = a.length / 2 | |
left, right = a[0..halfway - 1], a[halfway..a.length] |
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 ListEntry | |
attr_accessor :next, :prev, :data | |
def initialize(data) | |
@next = nil | |
@prev = nil | |
@data = data | |
end | |
end | |
class List |
NewerOlder