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 BinaryHeap(type){ | |
this.heap = [] | |
this.comparator = type.comparator; | |
} | |
BinaryHeap.prototype.swap = function(index1, index2){ | |
var temp = this.heap[index1]; | |
this.heap[index1] = this.heap[index2]; |
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 Bag(data){ | |
this.data = data.slice(0); | |
this.misses = 0; | |
} | |
/** | |
* Remove the element at index from the Bag | |
* | |
* @param index | |
* @return {*} |
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 Node(val){ | |
this.left = null; | |
this.right = null; | |
this.val = val; | |
} | |
function Tree(){ | |
this.root = null; |
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
if(typeof Object.keys === 'undefined'){ | |
Object.keys = function(o){ | |
var out = []; | |
for(var key in o){ | |
if(o.hasOwnProperty(key)){ | |
out.push(key); | |
} | |
} | |
return out; | |
} |
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
var http = require('http'), | |
EventEmitter = require('events').EventEmitter; | |
var nextEvent = new EventEmitter(); | |
var requestId = 0; | |
function poll(){ | |
requestId++; | |
http.get("<url>", function(res){ | |
res.on('data', function(chunk){ |
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 'nokogiri' | |
def read_elements(filename, element_path, id_name, &callback) | |
f = File.open(filename) | |
xml = Nokogiri::XML(f) | |
elements = [] | |
xml.xpath(element_path).each do |element| | |
element_id = element.attributes[id_name].value.to_s | |
elements.push(element_id) |
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
var parse = require('css-parse') | |
var fs = require('fs') | |
var _ = require("underscore"); | |
var contents = fs.readFileSync("style.css", "utf-8"); | |
var x = parse(contents); | |
var printSelectors = function(regex){ | |
var importantSelectors = []; | |
_.each(x.stylesheet.rules, function(d){ |
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
# To run | |
# ruby main.rb <header_base_color> | |
# | |
# Examples | |
# ruby main.rb 666666 | |
# ruby main.rb EE7621 | |
# ruby main.rb EE7621 C48E48 FF3300 | |
# | |
# It looks nicer when the header_base_color is a darker color | |
# |
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 | |
# Save in file to_gemfile.rb | |
# Use like so | |
# gem list | ./to_gemfile.rb | |
gem_file = File.open("Gemfile", "w") | |
gem_file.write("source :rubygems\n") | |
STDIN.readlines.each do |line| | |
line = line.chomp | |
line =~ /(.*)\s\((.*)\)/ |
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
import java.util.regex.Matcher; | |
import java.util.regex.Pattern; | |
public class Main { | |
private final static Pattern SCRIPT_SRC_PATTERN = Pattern.compile("(src)(?:\\s*=\\s*)(?:(?:\"((?:\\.|[^\"])*)\")|(?:\'((?:\\.|[^\'])*)\')|([^>\\s]+))"); | |
public static void main(String[] args){ | |
String works = "<script src=\"test\"></script>"; | |
Matcher m = SCRIPT_SRC_PATTERN.matcher(works); |