This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function allInCollection (collection) { | |
return function (subCollection) { | |
return subCollection.every(function (subItem) { | |
return collection.some(function (item) { | |
return item.id === subItem.id; | |
}); | |
}); | |
}; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
|-------------------------|-------------------------|-------------------------|-------------------------| | |
|-------------------------|-------------------------|-------------------------|-------------------------| | |
|----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-----------------------| |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const cons = (a, b) => | |
(member) => { | |
if (member === 1) { | |
return a | |
} else if (member === 2) { | |
return b | |
} | |
} | |
const car = (pair) => |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Main where | |
import Control.Applicative | |
import Data.Monoid | |
fizz n | |
| n `mod` 3 == 0 = Just "Fizz" | |
| otherwise = Nothing | |
buzz n |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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> |
OlderNewer