Skip to content

Instantly share code, notes, and snippets.

@SgtPooki
SgtPooki / randomAlphaNumString.js
Last active June 8, 2017 17:03
Simple test to see how long it takes a random alphanumeric function to generate a duplicate string.
/**
*************************************************************************************************************
***** This will no longer lock up your browser tab, but it will not find a match for a very long time ****
***** Do not run this in a tab you do not want to reload ****
*************************************************************************************************************
*
* This was just me playing around trying to see if I could get a duplicate random string
* when using the Math.random().toString(radix) method.
*
* I had planned to implement web workers with this as well so that I could let it
@SgtPooki
SgtPooki / LocalStorageHelper.js
Last active December 20, 2015 17:09
Local storage helper AMD module to allow serialization of any data type
/**
* @fileOverview LocalStorageHelper RequireJS AMD Module File
*
* @author Russell Dempsey <[email protected]>
* @version 1.0
*/
define(function(require, module, exports) {
'use strict';
//includes
@SgtPooki
SgtPooki / gist:5447849
Created April 23, 2013 22:10
Simple function to create an object with list of currently pressed keys
var keys = {};
$('#notes')
.live('keydown', function(e){
keys[e.keyCode] = 'down';
console.log(keys);
})
.live('keyup', function(e){
delete keys[e.keyCode];
console.log(keys);
});
@SgtPooki
SgtPooki / CreateElement
Last active March 4, 2017 08:36
Create element function that makes the best of jquery and javascript. Will convert to jquery plugin and test speed there as well. You can check results of speed tests here: http://jsperf.com/building-dom-items/2. Plan is to make this function the method to use when creating elements so that it is always the fastest and most browser compatible me…
/*
Sample object that should work is:
var exampleObj = {
tag: 'div',
attr: {
id: '1234',
href: 'some/url/path',
class: ['createdElement', 'example', 'parent'],
text: 'some text'
},
@SgtPooki
SgtPooki / voseAlias.js
Last active December 11, 2015 11:48
Converted https://gist.github.com/3171981 to JavaScript. Used a few functions from http://phpjs.org/ to simplify refactoring.
/*
* Implementation of Vose's Alias Method
* Pass in an array of probabilities such as [.1, .2, .4, .7],
* probabilities do not have to add up to 1.
* Returned will be the selected index based on the probabilities.
*
* show statistics with
* aliasMethod(yourArray, true);
*
* use with