Skip to content

Instantly share code, notes, and snippets.

Brad bradparker

Block or report user

Report or block bradparker

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@bradparker
bradparker / circle.js
Last active Jan 3, 2016
simple x and y cords for a circle
View circle.js
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)
});
View reduced.js
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 / collection-compare.js
Created Sep 12, 2014
Collection comparison helpers
View collection-compare.js
function allInCollection (collection) {
return function (subCollection) {
return subCollection.every(function (subItem) {
return collection.some(function (item) {
return item.id === subItem.id;
});
});
};
}
View tuning-fork.js
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 / anthropology
Last active Aug 29, 2015
Anthropology - Charlie Parker
View anthropology
|-------------------------|-------------------------|-------------------------|-------------------------|
|-------------------------|-------------------------|-------------------------|-------------------------|
|----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-----------------------|
View unit-matcher.js
// 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 / line-slope-intercept.js
Created Dec 31, 2014
Line, slope intercept form
View line-slope-intercept.js
function Line (slope, intercept) {
this.slope = slope
this.intercept = intercept
}
function getX (y) {
y = y || 0
return (y - this.intercept) / this.slope
}
Line.prototype.getX = getX;
View cons.js
const cons = (a, b) =>
(member) => {
if (member === 1) {
return a
} else if (member === 2) {
return b
}
}
const car = (pair) =>
View alternative.hs
module Main where
import Control.Applicative
import Data.Monoid
fizz n
| n `mod` 3 == 0 = Just "Fizz"
| otherwise = Nothing
buzz n
View index.html
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Scratch pad</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/mocha/2.2.5/mocha.min.css" />
</head>
<body>
<div id="mocha"></div>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/chai/3.2.0/chai.min.js"></script>
You can’t perform that action at this time.