Skip to content

Instantly share code, notes, and snippets.

View dcocharro's full-sized avatar

Diogo Cocharro dcocharro

View GitHub Profile
@andrei-m
andrei-m / levenshtein.js
Last active October 9, 2024 10:36
Levenshtein distance between two given strings implemented in JavaScript and usable as a Node.js module
/*
Copyright (c) 2011 Andrei Mackenzie
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 THE SOFTWARE OR THE
@withakay
withakay / bjorklund.js
Created October 14, 2011 10:10
Bjorklund algorithm in JavaScript
/*
An implementation of the Bjorklund algorithm in JavaScript
Inspired by the paper 'The Euclidean Algorithm Generates Traditional Musical Rhythms'
by Godfried Toussaint

This is a port of the original algorithm by E. Bjorklund which I
found in the paper 'The Theory of Rep-Rate Pattern Generation in the SNS Timing Systems' by
E. Bjorklund.
@jpillora
jpillora / combinations.js
Last active September 7, 2020 15:52
Array/String combinations in JavaScript
//Explaination:
// start with the empty set
// extract the head element
// copy each element in the set with the current head element appended
// recurse
var combinations = function(set) {
return (function acc(xs, set) {
var x = xs[0];
if(typeof x === "undefined")
@devilelephant
devilelephant / BeatBuddyWorldPercussionMidiChart.tsv
Created February 17, 2018 23:58
Beat Buddy World Percussion Midi Chart
Midi Note Note Name
85 C#5 Bongo Low - palm
84 C5 Bongo Low - closed slap
82 A#4 Shaker
75 D#4 Clave
59 B2 Splash2
57 A2 Hand Crash 2
56 G#2 Cowbell
55 G2 Splash 1
54 F#2 Tambourine
@zeffii
zeffii / nodedemo.js
Created October 7, 2018 08:24
max msp node.script
const maxApi = require("max-api");
let x = 0;
let y = 0;
maxApi.addHandler("input", (dir) => {
switch (dir) {
case "UP":
y += 1;
@KalebNyquist
KalebNyquist / lookupZoteroCollections.js
Created August 8, 2021 21:44
One of my frustrations with Zotero is that there is no easy way to list all the collections in which a file is stored. This is my band-aid of a solution. The code can be run under Tools > Developer > Run Javascript using "Sync" mode.
// Instructions:
// (1) Highlight file of interest.
// (2) Run code in Zotero's JavaScript console (found under Tools > Developer > Run Javascript) in sync mode.
function collections_output() {
zp = Zotero.getActiveZoteroPane()
items = zp.getSelectedItems()
collection_ids = items[0]["_collections"]
collections_cache = Zotero.Collections._objectCache