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
/** | |
* A custom element for rendering a checkbox list of items. Example: | |
* <checkbox-list | |
* title="Hello World" | |
* itemLabels="Apple,Banana, Chocolate" | |
* items="a,b,c" | |
* value="all" | |
* /> | |
* | |
* And change can be detected with: |
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
import numpy as np | |
import scipy.io.wavfile | |
# generate a "canonical" waveform | |
elements = [] | |
for i in range(0, 255): | |
for k in range(20): | |
elements.append(i) | |
for i in range(255, 0, -1): | |
for k in range(20): |
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
def build_table(W): | |
# initialize our table | |
T = [-1 for element in W] | |
# the current position we're calculating a table value | |
pos = 1 | |
# an extra index for referencing the candidate location that a mismatch would start over at. | |
cnd = 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
(function() { | |
// Get a context | |
var canvas = document.createElement('canvas'); | |
var gl = null; | |
try { | |
gl = canvas.getContext('webgl'); | |
if(!gl) throw new Error(''); | |
} catch(e) { | |
return false; | |
} |
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 makeDraggable(element, onDragMove, onDragEnd) { | |
element.style.position = 'absolute'; | |
var mouseIsDown = false; | |
var offset = { x: 0, y: 0}; | |
var oldZIndex = ''; | |
element.addEventListener('mousedown', function(evt) { | |
oldZIndex = element.style.zIndex; | |
element.style.zIndex = 999; |
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
# A class for holding the unique letters from a string, and their number of occurences | |
class LetterSet: | |
# constructor, adds the words to a dictionary with letters as keys and letter counts as values | |
# ala: { 'a': 4, 'b' : 2, ... } etc. | |
def __init__(self, word): | |
self.letter_counts = {} | |
for letter in word: | |
self.add_letter(letter) |
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 _ = require('lodash'); | |
var chiSquaredTest = require('chi-squared-test'); | |
var seedrandom = require('seedrandom'); | |
var rng = seedrandom('hello.'); | |
function rollDie(sides) { | |
var index = Math.floor(rng() * sides.length); | |
return sides[index]; | |
} |
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
from random import uniform | |
numberOfCases = 1000 | |
print(numberOfCases + 1) | |
# an edge case to test for | |
print('0.1 0.1 1 1') | |
for i in range(numberOfCases): | |
starting_concentration = uniform(0.25, 0.5) |
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
from math import cos, sin, pi | |
def distance(p1, p2): | |
dx = p1[0] - p2[0] | |
dy = p1[1] - p2[1] | |
return (dx * dx + dy * dy)**0.5 | |
def equals(p1, p2, epsilon=0.001): | |
return distance(p1, p2) <= epsilon |
NewerOlder