Skip to content

Instantly share code, notes, and snippets.

@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
@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 / 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 / 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 <rdempsey@nerdery.com>
* @version 1.0
*/
define(function(require, module, exports) {
'use strict';
//includes
@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
echo 'export PATH=$HOME/local/bin:$PATH' >> ~/.bashrc
. ~/.bashrc
mkdir $HOME/local
mkdir ~/node-latest-install
cd ~/node-latest-install
curl http://nodejs.org/dist/node-latest.tar.gz | tar xz --strip-components=1
./configure --prefix=$HOME/local
make install # ok, fine, this step probably takes more than 30 seconds...
#curl https://npmjs.org/install.sh | sh # this is no longer required
@SgtPooki
SgtPooki / .htaccess
Created March 19, 2014 22:54
remove .php
# Apache Rewrite Rules
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
#RewriteLog /var/rewrite.log RewriteLogLevel 9
# Redirect to URL without extension. (remove .php)
RewriteCond %{THE_REQUEST} ^[A-Z]+\s.+\.php\sHTTP/.+
RewriteRule ^(.+)\.php $1 [R=301,L]
@SgtPooki
SgtPooki / installNode.sh
Created April 30, 2014 20:02
Script to install node and npm on a new arch linux install
sudo pacman -Syy
sudo pacman -S --noconfirm python2 wget git make gcc vim
sudo mv /usr/bin/python /usr/bin/python-BAK
sudo ln -s /usr/bin/python2 /usr/bin/python
source <(curl -s https://gist.githubusercontent.com/SgtPooki/7667376/raw/node-and-npm-in-30-seconds.sh)
@SgtPooki
SgtPooki / beep.bat
Last active August 29, 2015 14:01
Create a beep! "beep x" will beep x times, for a max of 10. x defaults to 1.
@echo off
REM loopNum defaults to 1, caps at 10.
REM see https://gist.github.com/SgtPooki/99e12f32a874aa7dd3b2
SET loopNum=1
If not "%~1"=="" (
SET loopNum=%1
)
@SgtPooki
SgtPooki / provision.sh
Created June 3, 2014 22:31
nvm / rvm provisioning script
#!/bin/bash
sudo apt-get update
sudo apt-get install python-software-properties
sudo add-apt-repository ppa:git-core/ppa
sudo apt-get update
sudo apt-get install -y git curl python-software-properties libcurl3 libcurl3-gnutls libcurl4-openssl-dev