Skip to content

Instantly share code, notes, and snippets.

View amundo's full-sized avatar
🫥
(0)

Patrick Hall amundo

🫥
(0)
  • Massachusetts
  • 16:53 (UTC -12:00)
View GitHub Profile
@amundo
amundo / find.js
Created February 23, 2015 02:19
poor man's dom selection
function find(selector, scope) {
var matches = (scope || document).querySelectorAll(selector);
if (matches.length == 1) {
return matches
} else {
return [].slice.call(matches)
}
}
@amundo
amundo / saveJSON.js
Created November 22, 2014 01:44
a simple function to export a JSON file
function saveJSON(data, saveAs){
var stringified = JSON.stringify(data, null, 2);
var blob = new Blob([stringified], {type: "application/json"});
var url = URL.createObjectURL(blob);
var a = document.createElement('a');
a.download = saveAs + '.json';
a.href = url;
a.id = saveAs;
document.body.appendChild(a);
@amundo
amundo / emitterless.md
Created November 2, 2014 20:23
Do we really need an event emitter?

A ton of libraries out there model “event emitting”:

https://github.com/HenrikJoreteg/wildemitter

These libraries all allow us to create some sort of emitter object on which we can register and trigger custom events.

I’m not sure I get it.

It seems that everyone is shoving this emitter into the global namespace (if it’s used all over an app, no big whoop). So if that’s the case, what do we need an emitter for at all? We can just run addEventListener and dispatchEvent wherever we need to, and those events will be attached to window. (I’m talking browser here, I don’t speak node.)

@amundo
amundo / json2webvtt.js
Created October 23, 2014 16:31
A first pass at rendering wavesurfer.js annotations as WEBVTT
var sample = [
{
"start": 2.7,
"end": 4.1,
"data": {}
},
{
"start": 6,
"end": 8.2,
"data": {}
@amundo
amundo / count.js
Last active August 29, 2015 14:07
counting things in javascript
var count = function (sequence) {
return sequence.reduce(function (tally, item) {
if (!(item in tally)) {
tally[item] = 0
}
tally[item] += 1;
return tally
}, {
})
}
@amundo
amundo / .gitignore
Last active August 29, 2015 14:01 — forked from mbostock/.block
Oaxaca map
build
node_modules
.DS_Store
@amundo
amundo / index.html
Last active August 29, 2015 14:00 — forked from mbostock/.block
<!DOCTYPE html>
<meta charset="utf-8">
<style>
rect {
stroke: #fff;
}
</style>
<body>
<!doctype html>
<html>
<head>
<title>page</title>
<meta charset=utf-8>
</head>
<body>
<div id="airplane">
<form class="col-md-8 form-horizontal">
cat sections/[0-6]_*.txt > masters.txt
#cat sections/[3]_*.txt > masters.txt
@amundo
amundo / a2audio.js
Created March 19, 2014 17:16
JS function to change links like <a href="something.wav">sound</a> so that they play when clicked
/*
There are a lot of pages like:
http://titus.uni-frankfurt.de/ld/
Which have links to .wav files. It's annoying to have to change
context, load "QuickTime", blah blah, and to lose the context
of the name of the link when you're listening to it.
The following function creates an Audio object which plays when