Skip to content

Instantly share code, notes, and snippets.

@bradparker
bradparker / unit-matcher.js
Created November 20, 2014 22:32
Unit Matcher
// Take "3mm", "-3inches", or "3.45 cm" and return ['3', 'mm'], ['-3', 'inches'], ["3.45", "cm"] etc
function unitParse (str) {
return (str.match(/([-\d.]+)\s+?([A-Za-z]+)/) || []).slice(1)
}
@bradparker
bradparker / anthropology
Last active August 29, 2015 14:06
Anthropology - Charlie Parker
|-------------------------|-------------------------|-------------------------|-------------------------|
|-------------------------|-------------------------|-------------------------|-------------------------|
|----7--------8--6--7--10-|----------8-----10-8-----|----7--8--7-----------7--|-------------------------|
|-8-----10-9--------------|-------------------------|-------------10-7--8-----|-10----8--7-----------8--|
|-------------------------|-------------------------|-------------------------|----10-------------------|
|-------------------------|-------------------------|-------------------------|-------------------------|
| + - + - + - + - | + - + - + - + - | + - + - + - + - | + - + - + - + - |
|-------------------------|-------------------------|-------------------------|-------------------------|
|-------------------------|-------------------------|----------------9-----7--|-8-----------------------|
@bradparker
bradparker / tuning-fork.js
Created September 21, 2014 04:59
Tuning Fork
var context = new AudioContext(),
gainNode = context.createGain(),
oscillator = context.createOscillator();
gainNode.connect(context.destination);
oscillator.frequency.value = 440;
oscillator.connect(gainNode);
oscillator.start();
// ..
// gainNode.gain.value = 0;
@bradparker
bradparker / collection-compare.js
Created September 12, 2014 00:28
Collection comparison helpers
function allInCollection (collection) {
return function (subCollection) {
return subCollection.every(function (subItem) {
return collection.some(function (item) {
return item.id === subItem.id;
});
});
};
}
const range = (start, end) =>
Array.from({
length: end - start
}).map((_, index) => (index + start))
const sum = nums =>
nums.reduce((total, num) => total + num)
sum(range(20, 100))
@bradparker
bradparker / circle.js
Last active January 3, 2016 13:29
simple x and y cords for a circle
function circle (radius, x, y, nPoints) {
var circle = [];
var nPoints = nPoints || 360;
var wedge = 2 * Math.PI / nPoints;
for (var angle = wedge; angle < 2 * Math.PI; angle += wedge) {
circle.push({
x: x + radius * Math.cos(angle),
y: y + radius * Math.sin(angle)
});