Skip to content

Instantly share code, notes, and snippets.

Avatar

Alexander Harding aeharding

View GitHub Profile
View index.html
<!DOCTYPE html>
<html>
<head>
<script src="//cdn.jsdelivr.net/pouchdb/6.0.7/pouchdb.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.3/underscore.js"></script>
</head>
<body>
<button onclick="seed()">Seed the database with 10000 docs</button><br>
<button onclick="recreate()">Destroy and recreate database</button><br>
<button onclick="verifyDocs()">Verify 10000 docs exist</button><br>
@aeharding
aeharding / secureRandom.js
Created Sep 29, 2016
Generates a cryptographically secure number [0-1) as an alternative to Math.random()
View secureRandom.js
// Generates a cryptographically secure number [0-1)
// as an alternative to Math.random()
//
// source: http://stackoverflow.com/a/13694869/1319878
function secureRandom() {
var arr = new Uint32Array(2);
crypto.getRandomValues(arr);
// keep all 32 bits of the the first, top 20 of the second for 52 random bits
var mantissa = (arr[0] * Math.pow(2,20)) + (arr[1] >>> 12)
@aeharding
aeharding / timeoutSort.coffee
Last active Aug 29, 2015
Sort an array of positive integers using timeouts. *genius*
View timeoutSort.coffee
# Only works with positive numbers #dealwithit
timeoutSort = (arr, cb) ->
ret = []
longest = 0
for t in arr then do ->
longest = t if t > longest
tmp = t
setTimeout ->
ret.push tmp
, t
@aeharding
aeharding / LinkedList.coffee
Last active Aug 29, 2015
A LinkedList (with Node and Iterator) written in Coffeescript to exercise my mind!
View LinkedList.coffee
class LinkedList
isEmpty: ->
not @head?
prepend: (item) ->
node = new Node item, @head
@tail = node if @isEmpty()
@head = node
append: (item) ->
@aeharding
aeharding / index.coffee
Last active Aug 29, 2015
Diagonal star on dinamic grid thingy
View index.coffee
diagDir = false
x = 5
y = 9
console.clear()
# Initialize that shizzle
grid = []
for i in [0...10]
grid.push []
You can’t perform that action at this time.