Skip to content

Instantly share code, notes, and snippets.

View nyteshade's full-sized avatar

Brielle Harrison nyteshade

View GitHub Profile
@nyteshade
nyteshade / ChoiceSet.js
Created September 25, 2016 09:19
Weighted Random
/**
* ChoiceSet is a weighted random solution that allows the each of the
* items that are being chosen to have simply a name or full suite of
* values other than their weights and names.
*
* Once the items have been setup with a name and weight, the system works
* by creating a one to one array. Each item in the new array is a sum of
* all the subsequent and current weights. The final weight, being the
* maximum total weight, is also stored.
*
@nyteshade
nyteshade / packme.js
Last active April 30, 2018 04:14
Run webpack on the fly
#!/usr/bin/env node --harmony
// Fetch the Path, File System and Child Process modules
var Path = require('path');
var FS = require('fs');
var CP = require('child_process');
/**
* The actual webpack config is stored within a function and then
* extracted as a string as this preserves the regular expression
@nyteshade
nyteshade / multiline.js
Created December 8, 2016 21:29
Kill whitespace before and after template strings
/**
* A small helper for multiline template strings that allows you to
* not worry about new lines and indentations within your code from
* breaking up the format of the string.
*
* @param {Array} strings an array of Strings from the template, broken up by
* where the substitions are to be inserted.
* @param {Array} values an array of values to be inserted after each string
* of a matching index.
* @return {String} a template String without any prefixed or postfixed tabs
@nyteshade
nyteshade / html.html
Created April 6, 2017 00:12
Copland Progress Bars
<div class="progress p0">
<div class="bar">
<div class="slice slice1"></div>
<div class="slice slice2"></div>
<div class="slice sliceN"></div>
<div class="slice slice3"></div>
<div class="slice slice4"></div>
<div class="slice slice5"></div>
</div>
<div class="track">
@nyteshade
nyteshade / getcip.c
Last active April 12, 2017 01:23
niceps1
#include <sys/types.h>
#include <arpa/inet.h>
#include <ifaddrs.h>
#include <libgen.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
@nyteshade
nyteshade / Code.js
Last active May 4, 2017 22:51
Simple class in ES5 parlance that tracks code and its history of changes
// ES5
/**
* The Code "class" defines an object that represents a source code with
* a history of changes. Whenever its source property is assigned, the
* new value is pushed onto a stack of code. Whenever its source property
* is read, the latest iteration of the code is returned as a string.
*
* @method Code
*
@nyteshade
nyteshade / functions.sh
Last active July 6, 2017 02:12
File (de)encryption using openssl
# Encryption and decryption BASH functions using openssl
function decrypt() {
# The first param doesn't contain .enc, write output plus .decrypted if no 2nd
if [ "${1/.enc/}" = "${1}" -a -e "${1}" ]; then
openssl enc -d -aes-256-cbc -in "${1}" -out "${2:-${1}.decrypted}"
# The first param contains .enc, write the output without if no 2nd param
elif [ "${1/.enc/}" != "${1}" -a -e "${1}" ]; then
openssl enc -d -aes-256-cbc -in "${1}" -out "${2:-${1/.enc/}}"
@nyteshade
nyteshade / Function.signature.js
Created April 4, 2018 20:00
A small patch to Function.prototype that helps make functions and classes a bit more self-documenting
// Patch Function.prototype to provide the signature in the REPL
Object.defineProperty(
Function.prototype,
'signature',
{
get() {
let source = this.toString()
// For classes we need to extract the signature of the
// constructor function within; so use some regular
@nyteshade
nyteshade / updateNpm.bat
Created June 18, 2018 01:00 — forked from johnmcase/updateNpm.bat
Update npm on windows
rem see https://github.com/coreybutler/nvm-windows/issues/300
@echo off
SETLOCAL EnableDelayedExpansion
if [%1] == [] (
echo Pass in the version you would like to install, or "latest" to install the latest npm version.
) else (
set wanted_version=%1
@nyteshade
nyteshade / asArray.js
Last active August 28, 2018 21:00
Convert object with numeric keys to array, keeping order
/**
* If the value supplied is actually a number, basically finite values that
* can be parsed as floats and are not `NaN` will cause this function to
* return true
*
* @param {mixed} value any value that should be tested for numberhood
*
* @return {Boolean} true if the value is not `NaN` and can be parsed as
* a float
*/