Skip to content

Instantly share code, notes, and snippets.

const MAX_TIMEOUT = 2147483647;
class ChunkedTimeout {
private handle: number | undefined;
constructor(private callback?: () => void, private msLeft: number = 0) {
this.next();
}
public clear() {
this.msLeft = 0;
if (this.handle) {
@keesey
keesey / comixify.js
Last active November 20, 2019 05:24
const comixify = (s, next = {}) => s
.split("")
.map(c => {
if (!/^[A-HJ-Z]$/i.test(c)) return c;
const C = c.toUpperCase();
return (next[C] = !next[C]) ? C : c.toLowerCase();
})
.join("");
const comixifyAll = (lines, next = {}) => lines.map(line => comixify(line, next)).join("\n\n");
@keesey
keesey / phylopic-swagger.json
Last active March 31, 2017 23:37
Proposed OpenAPI Specification for PhyloPic 2.0
{
"swagger": "2.0",
"info":
{
"title": "PhyloPic",
"description": "PhyloPic is a database of free silhouette images of life forms, available for reuse under a Public Domain or Creative Commons license.",
"termsOfService": "http://phylopic.org/terms/",
"contact":
{
"name": "Mike Keesey",
@keesey
keesey / tslint.json
Last active September 9, 2016 21:03
{
"adjacent-overload-signatures": true,
"align": false,
"arrow-parens": false,
"class-name": true,
"comment-format":
[
true,
"check-space"
],
@keesey
keesey / levenshtein.ts
Last active February 14, 2024 10:59
Levenshtein distance implemented in TypeScript
export function levenshtein(a: string, b: string): number
{
const an = a ? a.length : 0;
const bn = b ? b.length : 0;
if (an === 0)
{
return bn;
}
if (bn === 0)
{
declare module node_neo4j {
export interface PropertyContainer
{
// The URL of this property container.
self: string;
// Whether this property container exists in (has been persisted to) the Neo4j database.
exists: boolean;
module Newtonsoft.Json
{
export function deserialize(o: any): any
{
const dict: { [$id: string]: Object } = {};
function _deserialize(o: any): any
{
if (typeof o === "object" && o !== null)
{
let $id: string;
var CHANCE_OF_LIGHTNING = 1 / 100; // Tweak this.
var TOTAL_FRAMES = 4; // Include 'still' frame and lightning frames.
this.stop();
this.addEventListener('tick', function()
{
if (Math.random() < CHANCE_OF_LIGHTNING)
{
this.gotoAndStop(Math.floor(Math.random() * (TOTAL_FRAMES - 1)) + 1);
}
interface Oboe
{
(url: string): Oboe.Call;
doDelete(url: string): Oboe.Call;
doDelete(request: Oboe.Request): Oboe.Call;
doGet(url: string): Oboe.Call;
doGet(request: Oboe.Request): Oboe.Call;
doPatch(url: string, body: any): Oboe.Call;
doPatch(request: Oboe.BodyRequest): Oboe.Call;
doPost(url: string, body: any): Oboe.Call;
@keesey
keesey / aop.ts
Last active December 20, 2015 09:09
module aop
{
export function after<R>(
f: (...args: any[]) => R,
advice: (result: R, ...args: any[]) => any
): (...args: any[]) => R
{
return function()
{
var result = f.apply(this, arguments),