Skip to content

Instantly share code, notes, and snippets.

View kristopolous's full-sized avatar
💣
New releases are coming soon!

chris mckenzie kristopolous

💣
New releases are coming soon!
View GitHub Profile
@kristopolous
kristopolous / priority_queue.js
Created March 10, 2016 01:06
A Javascript Priority Queue based on Array
var Priority = (function(){
function sort(pri) {
if(pri.dirty) {
var sorted = pri.sort(function(a, b) {
return 1000000 * (b.priority - a.priority) + 0.0001 * (a.id - b.id);
});
pri.dirty = false;
pri.splice.apply([], [0, 0].concat(sorted));
@kristopolous
kristopolous / laravel3to5.md
Last active July 22, 2016 04:57
Getting Input to work in laravel5

Laravel 5 decided to remove the global Input class. What are the implications to existing code bases? As usual the answer is "eh who cares? fuck em."

How does a responsible adult deal with a bunch of finickey novelty-obsessed designers who change specs and pull the rug out from you every 6 months?

Unfortunately I have no general answer to this confounding and dumbfounding lack of even the most basic discipline, but in the case of Input I do!

Adding a backwards-compatible Input into your laravel5 project

This can be reliably achieved through middleware.

This probably isn't the "right" way of doing things, but if you are one of those dweebs advocating to break every thing every month then sorry, you don't get a seat at the table.

@kristopolous
kristopolous / Random selection from weighted set
Created November 22, 2016 01:00
An effecient random selector observing weighted sets
(function(){
function verify(weights, chosen, trialCount) {
var variance = 0, ttl = chosen.length;
for(var ix = 0; ix < ttl; ix++) {
console.log(weights[ix], chosen[ix] / trialCount);
variance += Math.sqrt(Math.abs(Math.pow(weights[ix], 2) - Math.pow(chosen[ix] / trialCount, 2)));
}
console.log(variance / ttl);
}
@kristopolous
kristopolous / simple-us-regex-phone-formatter
Created May 9, 2017 23:02
simple us regex phone formatter in JS
function phoneFormat(str) {
return str.replace(/[+1]*(\d{3})(\d{3})(.*)/, '1 ($1) $2-$3');
}
@kristopolous
kristopolous / tcpdump-on-device.md
Created May 31, 2017 19:45
tcpdump on a device without disk space

On the device to capture from we set up a FIFO that will be pushed off to another device on the network with disk, in this case we are using 192.168.1.11 as the "host"

On the host, we start up netcat that will be pushed into a capture file that we can analyze later, in this instance, we are listening on port 5001 $ nc -l -p 5001 > capture.cap

In a terminal on the device we make a fifo and then push it out over the network through netcat $ mknod /tmp/fifo p $ cat fifo | nc 192.168.1.11 5001

import sys, math
width=14400
height=10800
image = [ [ 0 for y in range ( width ) ] for x in range( height ) ]
maxval = 7
delta_lng = .9
delta_lat = delta_lng * 28/40
lng_low = -118.8
lng_high = lng_low + delta_lng
#!/usr/bin/python
import sys
import png
from pprint import pprint
cx = 0
width = 4000
height = 4000
image = [ [ 0 for y in range ( width ) ] for x in range( height ) ]
#!/usr/bin/python
import sys
import png
import os
import numpy as np
import json
import math
import time
import random
#/bin/bash
# /etc/init.d/xdm: Login Procedure for Bob480
# Edited Sept-2001; Contact Author: cjm@ucdavis.edu
n=$1
n=$n"."
[ $n == "stop." ] && exit
moveon=0
set PATH="/bin:/usr/bin:/sbin"
@kristopolous
kristopolous / transp.py
Last active September 20, 2021 07:22
transposition die roll example
#!/usr/bin/env python3
import random
def encode(plain):
plain = list(plain)
cypher = ''
while len(plain) > 0:
# Roll a die, add 3 to the result
step = random.randint(4,9)
# start at the beginning of the remaining string