Skip to content

Instantly share code, notes, and snippets.

View dtao's full-sized avatar

Dan Tao dtao

View GitHub Profile
@dtao
dtao / convert_to_markdown.rb
Last active December 20, 2015 06:59
A very basic script to translate a simple HTML file (consisting only of paragraphs with bold & italic text) to Markdown.
require 'nokogiri'
file = ARGV[0]
if !File.exist?(file)
puts "File #{file} does not exist."
exit
end
html = File.read(file)
@dtao
dtao / createGeneratorIdea.js
Created January 11, 2014 21:24
An idea for how generators could be implemented pre-ES6
/**
* Using yield to create a generator -- only possible in ES6/Harmony.
*/
function fibonacci(limit) {
var fn1 = 1;
var fn2 = 1;
while (1) {
var current = fn2;
fn2 = fn1;
fn1 = fn1 + current;
@dtao
dtao / frp.example.js
Created May 5, 2014 15:58
Lazy.js jQuery Event Stream
window.addEventListener('load', function() {
// This 'createWrapper' method is super weird and awkward and I'm not proud of
// it at all. But right now it's the only option for defining custom sequence
// types that wrap arbitrary sources. In a future version I will come up with
// something much better, swear to God.
var jqueryWrapper = Lazy.createWrapper(function(selector, eventName) {
var source = this;
$(selector).on(eventName, function(e) {
source.emit(e);
});