Skip to content

Instantly share code, notes, and snippets.

Dan Tao dtao

Block or report user

Report or block dtao

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
dtao / frp.example.js
Created May 5, 2014
Lazy.js jQuery Event Stream
View frp.example.js
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) {
dtao / createGeneratorIdea.js
Created Jan 11, 2014
An idea for how generators could be implemented pre-ES6
View createGeneratorIdea.js
* 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 / convert_to_markdown.rb
Last active Dec 20, 2015
A very basic script to translate a simple HTML file (consisting only of paragraphs with bold & italic text) to Markdown.
View convert_to_markdown.rb
require 'nokogiri'
file = ARGV[0]
if !File.exist?(file)
puts "File #{file} does not exist."
html =
dtao / agent.js
Created May 21, 2013
How 'this' in JavaScript is like 'instance_eval' in Ruby
View agent.js
function Agent(name) { = name;
this.command = function(subordinate, description, instructions) {
console.log( + " tells " + + ": '" + description + "'");
this.getCoffee = function() {
var recipients =;
dtao / disable_xml_parameter_parsing.rb
Last active Dec 11, 2015
Rails initializer to disable XML parameter parsing to protect against newly discovered exploit
View disable_xml_parameter_parsing.rb
# Disable XML parameter parsing completely as a stopgap measure until upgrading to Rails 2.3.16
# to defend against arbitrary code execution vulnerability; see:
dtao / FastString.cs
Created Aug 25, 2012
Proof of concept for an immutable string class optimized for concatenation with the + operator
View FastString.cs
using System;
using System.Text;
namespace FastStringConcatenation
public class FastString
const int DefaultCapacity = 32;
readonly StringBuilder buffer;
dtao / EvilStringHelper.cs
Created Aug 16, 2012
Devious C# class that makes .NET strings mutable without requiring the /unsafe compiler switch
View EvilStringHelper.cs
public static class EvilStringHelper
private static readonly Action<string, int, char> _setChar;
private static readonly Action<string, int> _setLength;
static EvilStringHelper()
if (Environment.Version.Major < 4)
MethodInfo setCharMethod = typeof(string).GetMethod(
dtao / expand_window.js
Created Aug 1, 2012
Function to automatically zoom in any website to fill available screen width
View expand_window.js
(function() {
function expand($) {
function text($element) {
return $.trim($element.clone().children().remove().end().text());
function isFixedOrFloating($element) {
try {
if ($element.css("position") === "fixed") {
return true;
dtao /
Created May 25, 2012
Sublime Text plugin to increment/decrement all selected numbers
import sublime
import sublime_plugin
class NumberCommand(sublime_plugin.TextCommand):
def run(self, edit):
selection = self.view.sel()
for region in selection:
value = int(self.view.substr(region))
self.view.replace(edit, region, str(self.op(value)))
dtao / example.sublime-keymap
Last active Dec 19, 2017
Sublime Text plugin to replace selected text with random letters/numbers
View example.sublime-keymap
{ "keys": ["ctrl+alt+r"], "command": "randomize" }
You can’t perform that action at this time.