Skip to content

Instantly share code, notes, and snippets.

@zapthedingbat
zapthedingbat / fiddle.html
Last active December 14, 2015 04:39
Taggable jQuery plugin
<div id="tagme" style="height:500px;width:500px;background-color:#DDF"></div>
@zapthedingbat
zapthedingbat / markov.js
Created March 21, 2013 00:38
Markov Chain implementation
/*
Copyright (C) 2013 Sam Greenhalgh - RadicalResearch Ltd
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH TH
@zapthedingbat
zapthedingbat / gist:7908110
Created December 11, 2013 10:23
Debouncer Only executes the most recent call after the specified timeout.
// Only executes the most recent call after the specified timeout.
function Debouncer() {
var timeout;
this.execute = function(callback, wait) {
if (timeout) {
clearTimeout(timeout);
timeout = null;
}
@zapthedingbat
zapthedingbat / Object.extend.js
Created December 13, 2013 10:08
Extend method copies properties from one object to another. Requires JavaScript 1.8.5+
Object.extend = function(toObj, fromObj){
var p = Object.getOwnPropertyNames(fromObj),
i = p.length;
while(i--)
{
Object.defineProperty(toObj, p[i], Object.getOwnPropertyDescriptor(fromObj, p[i]));
}
};
@zapthedingbat
zapthedingbat / chromebackbug.html
Last active February 17, 2016 18:04
Chrome Unload Back Bug
<!DOCTYPE html>
<html>
<head>
<script>
window.addEventListener('unload', function(){
var origionalUrl = location.href;
var newUrl = origionalUrl.replace('#.*$', '') + '#nope';
console.log('cancel navigation', newUrl);
window.location.replace(newUrl);
window.location.replace(origionalUrl);

Keybase proof

I hereby claim:

  • I am zapthedingbat on github.
  • I am zapthedingbat (https://keybase.io/zapthedingbat) on keybase.
  • I have a public key whose fingerprint is 560A 68F0 73EF 2F76 AE8C 014F 35C4 4D58 1084 3365

To claim this, I am signing this object:

using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
namespace ZapTheDingbat.IO
{
public class CsvReader : IEnumerable<IReadOnlyList<string>>, IEnumerator<IReadOnlyList<string>>
const runs = 10;
function run(method, runIndex) {
console.time(`run ${runIndex}`);
return method().then(() => {
console.timeEnd(`run ${runIndex}`);
if (runIndex < runs){
return run(method, runIndex+1);
}
});
@zapthedingbat
zapthedingbat / birthday.js
Created February 24, 2017 11:18
Calculating the probability that a member of a team shares their birthday with someone else in the same team.
//https://en.wikipedia.org/wiki/Birthday_problem#Calculating_the_probability
function p(n){
let a = 1;
for(let i = 0; i < n; i++){
a *= ((365 - i) / 365);
}
return 1 - a;
}
const chance = p(parseInt(process.argv.pop())) * 100;
console.log(`There is a ${chance}% chance of two people in the same team sharing the same birthday`);
@zapthedingbat
zapthedingbat / bookmarklet.js
Created April 11, 2017 09:00
A bookmarklet source
console.log('bookmarklet');