Skip to content

Instantly share code, notes, and snippets.

View mikesmullin's full-sized avatar
🛴
woot!

Mike Smullin mikesmullin

🛴
woot!
View GitHub Profile
@mikesmullin
mikesmullin / solitare.js
Created November 9, 2019 16:46
Solitare Solver for MOLEK-SYNTEZ game
(async () => {
const orderedSet = ['6','7','8','9','10','V','D','K','T'];
const nextAbove = c =>
orderedSet[orderedSet.indexOf(c) + 1];
let moveHistory = [];
const analyze = (state) => {
let moves = [];
@mikesmullin
mikesmullin / saml-x509-pki-parsing.js
Created July 18, 2018 04:38
Parsing SAML x.509 Certificate in pure-Javascript
const _idpX509Cert = _.get(resp, ['samlp:Response', 'Assertion', 0,
'ds:Signature', 0, 'KeyInfo', 0, 'ds:X509Data', 0, 'ds:X509Certificate', 0]);
const asn1js = require('asn1js');
const pkijs = require("pkijs");
const Certificate = pkijs.Certificate;
const buf = new Buffer(_idpX509Cert, 'base64').buffer;
console.log('_idpX509Cert', _idpX509Cert);
const asn1 = asn1js.fromBER(buf);
@mikesmullin
mikesmullin / mysql_find_unused_indicies.sql
Last active July 15, 2018 16:59
Finds unused indexes in a MySQL database so you can remove them.
use information_schema;
select
tables.table_name,
statistics.index_name,
statistics.cardinality,
tables.table_rows
from tables
join statistics
on (statistics.table_name = tables.table_name
and statistics.table_schema = '<YOUR DATABASE NAME HERE>'
@mikesmullin
mikesmullin / config-php-w-xdebug.sh
Last active July 15, 2018 16:59
HOWTO: Configure PHP with Xdebug plugin
# Setup debugging with Xdebug
# apt wont install for php5.2, so build
cd /tmp
wget http://xdebug.org/files/xdebug-2.1.4.tgz
tar zxvf xdebug-2.1.4.tgz
cd xdebug-2.1.4/
sudo apt-get install php5-dev
phpize
./configure
make
@mikesmullin
mikesmullin / install-pgsql-ubuntu.sh
Last active July 15, 2018 16:54
Install PostgreSQL 8.4 on Ubuntu server
# setup db
sudo -i
apt-get install postgresql-8.4
vim /etc/postgresql/8.4/main/pg_hba.conf
# change line 82 to read:
local all all md5
# insert after line 84, replacing with your actual LAN ip outside the vm:
host all all 10.1.10.65/32 md5
:wq
vim /etc/postgresql/8.4/main/postgresql.conf
@mikesmullin
mikesmullin / stream-mysqldump-import-over-ssh.sh
Last active July 15, 2018 16:48
Import remote MySQL database by streaming a compressed dump over SSH
ssh REMOTE-SERVER.COM "mysqldump -uroot -p REMOTE_DB | gzip -c" | gunzip | mysql -uroot LOCAL_DB
@mikesmullin
mikesmullin / fixing-a-software-bug.md
Last active July 15, 2018 16:38
Process of fixing a software bug

Process of fixing a software bug:

A Guide for the Impatient Line Manager

(and how its interesting that only half of the time is estimatable

in a poorly run / bottom-dollar organization)

  1. Reproduce; verify problem
    (not estimatable; can only set a maximum cut-off time based on pain/worth)

    in other words, if you could capture errors at the moment they happen (client-side error reporting),
    as well as the steps that led up to them (user behavior analytics, determinism, demo recording),

@mikesmullin
mikesmullin / megaphone.sh
Last active July 15, 2018 16:03
open loopback between microphone and speakers for Ubuntu Linux. written in Bash
#!/bin/sh
echo to unload, combine on same line:
echo pactl unload-module # to unload
pactl load-module module-loopback; #latency_msec=1000
@mikesmullin
mikesmullin / cmavg.coffee
Last active July 15, 2018 16:00
Cumulative Moving Average (lets you calculate average in the middle of a stream of numbers)
avg = (a) ->
sum = 0
for v in a
sum += v
sum / a.length
cavg = (v, av, c) ->
av + ((v - av) / c)
console.log '---'
@mikesmullin
mikesmullin / wrap.js
Created July 14, 2018 07:20
sort of looks like a regexp parser; will use regexp instead
var wrap = (list, test, cb) => {
const stack = [];
let start, end, lastTest, result, lastItem, item, out;
for (let i=0,len=list.length; i<len; i++) {
item = list.splice(i,1)[0];
result = test(item, lastItem);
if ((!result && lastTest !== result) || (i === list.length-1 && lastTest === result)) {
out = cb(item, i, start, end, stack, lastItem);
if (null != out) {
list.splice(i, 0, ...out);