Skip to content

Instantly share code, notes, and snippets.

View danieluhl's full-sized avatar

Typing Turtle danieluhl

View GitHub Profile
@danieluhl
danieluhl / js namespace
Created March 8, 2012 21:49
JavaScript Namespace
(function (libraryNamespace, $, undefined) {
// private properties
var privateProperty = 'default private';
// public properties
libraryNamespace.publicProperty = 'default public';
// private methods
function updatePublicProperty(newPublic) {
this.publicProperty = newPublic || 'new public';
/*
TrafficCop
Author: Jim Cowart
License: Dual licensed MIT (http://www.opensource.org/licenses/mit-license) & GPL (http://www.opensource.org/licenses/gpl-license)
Version 0.1.0
*/
(function($, undefined) {
var inProgress = {};
@danieluhl
danieluhl / grunt_tests.js
Last active December 2, 2015 19:37
An example of how to run node commands from grunt and get the output result
'use strict';
module.exports = function(grunt) {
grunt.registerTask('runTests', '', function() {
var done = this.async();
grunt.util.spawn({
cmd: 'node',
args: ['./js/tests/runner/tests.js']
}, function(e, result) {
@danieluhl
danieluhl / walk_graph.js
Created December 23, 2015 21:17
Walk a graph from leaf to root and build results based on a child/parent relationship
tree = {
a: ['b', 'c', 'd'],
b: ['e', 'f'],
c: ['g', 'h'],
h: ['i', 'j', 'k'],
k: ['l'],
l: ['m', 'n']
}
var _ = require('underscore');
module.exports = function(grunt) {
grunt.registerTask('walk-ast', function() {
grunt.log.writeln('walking');
var file = require('file');
var uglify = require('uglify-js');
var result = [];
function walkAST(node) {
if (node instanceof uglify.AST_If) {
if (node.condition) {
@danieluhl
danieluhl / node_lottery_1.js
Created January 13, 2016 21:23
not so random node lottery simulator distribution example
// somehow when running this in node I get strange numbers for the distribution of the final "random" number
// this assumes a lottery system of 6 balls, 5 picked randomly from a batch of 39 and the final one from 8
var fastLottery = function() {
var count = 0;
var running = true;
var distribution = [0, 0, 0, 0, 0, 0, 0, 0];
var finalCount = 0;
while (running) {
count++;
@danieluhl
danieluhl / node_lottery.js
Last active January 13, 2016 21:46
So you think you're gonna win the lottery? Run this node script to see how lucky you are!
// based on standard powerball lotto of 69 balls for the first 5 and 26 for the "power ball"
// note that this could potentially run forever, running in node should take ~30min but be warned, the browser is much slower!
var _ = require('underscore');
var balls = [];
var powerball = [];
for(var i = 1; i < 70; i++) {
balls.push(i);
}
for(i = 1; i < 27; i++) {
@danieluhl
danieluhl / node_lottery_fast.js
Last active January 13, 2016 22:27
Quick and dirty odds based lotto game
var count = 0;
var run = function() {
var rand = Math.floor((Math.random() * 292000000)) + 1;
var check = 0;
while(true) {
check = Math.floor((Math.random() * 292000000)) + 1;
if(check === rand) {
break;
}
rand = Math.floor((Math.random() * 292000000)) + 1;
@danieluhl
danieluhl / luck_tester.html
Created January 13, 2016 23:10
HTML version of luck tester
<input id="button" type="button" value="WHAT'S MY LUCK!?!" onclick="return window.run()" />
<h1 id="results"></h1>
<script type="text/javascript">
var count = 0;
var result = '';
window.run = function() {
console.log('running');
var rand = Math.floor((Math.random() * 292000000)) + 1;
var check = 0;
while(true) {
const keyElements = document.querySelectorAll('.key');
const audioElements = document.querySelectorAll('audio');
const sounds = {};
const keys = {};
// got this from wes bos
function removeTransition (e) {
if (e.propertyName !== 'transform') return;
e.target.classList.remove('playing');
}