Skip to content

Instantly share code, notes, and snippets.

View crookm's full-sized avatar
🌳

Matt Crook crookm

🌳
View GitHub Profile
@crookm
crookm / parallel no semaphore.sh
Created December 20, 2019 08:49
Running parallel batch tasks in bash
#!/bin/bash
task() {
sleep 1; echo "$1 - $(date)";
}
N=2
for item in {1..6}; do
((i=i%N)); ((i++==0)) && wait
@crookm
crookm / ffmpeg.sh
Created November 4, 2018 05:53
FFmpeg commands to create DASH and HLS
mkdir dash && \
ffmpeg -hide_banner -i original.mkv -c:v libvpx-vp9 -row-mt 1 -keyint_min 150 -g 150 -tile-columns 4 -frame-parallel 1 \
-movflags faststart -f webm -dash 1 -speed 3 -threads 4 -an -vf scale=426:240 -b:v 400k -r 30 -dash 1 dash/426x240-30-400k.webm && \
ffmpeg -hide_banner -i original.mkv -c:v libvpx-vp9 -row-mt 1 -keyint_min 150 -g 150 -tile-columns 4 -frame-parallel 1 \
-movflags faststart -f webm -dash 1 -speed 3 -threads 4 -an -vf scale=426:240 -b:v 600k -r 30 -dash 1 dash/426x240-30-600k.webm && \
ffmpeg -hide_banner -i original.mkv -c:v libvpx-vp9 -row-mt 1 -keyint_min 150 -g 150 -tile-columns 4 -frame-parallel 1 \
-movflags faststart -f webm -dash 1 -speed 3 -threads 4 -an -vf scale=640:360 -b:v 700k -r 30 -dash 1 dash/640x360-30-700k.webm && \
ffmpeg -hide_banner -i original.mkv -c:v libvpx-vp9 -row-mt 1 -keyint_min 150 -g 150 -tile-columns 4 -frame-parallel 1 \
-movflags faststart -f webm -dash 1 -speed 3 -threads 4 -an -vf scale=640:360 -b:v 900k -r 30 -dash 1 dash/640x360-30-900k.we
export default class API {
constructor() {
/**
* This is the function that should be called in the
* actual application.
*/
this.apiFunc = this._debounce(this._apiFunc, 1000 * 2);
}
/**

Keybase proof

I hereby claim:

  • I am crookm on github.
  • I am crookm (https://keybase.io/crookm) on keybase.
  • I have a public key ASDb2xTjW6QH6qhbUN94hemJ1SK8Ye9zadv2gmyUbNmCXgo

To claim this, I am signing this object:

@crookm
crookm / http_auth_digest_dict_attack.py
Created May 20, 2018 19:41
Basic MD5 dictionary attack on digest HTTP authentication methods - variables should be filled-in with captured packets
import hashlib
extracted = 'known_auth_hash'
nonce = 'known_nonce_hash'
user = 'known_username'
realm = 'known_realm'
uri = '/image.png'
method = 'GET'
@crookm
crookm / stego_extract_img_lsb.py
Last active May 21, 2018 06:58
Python program to extract the text stored in a stego image, that uses LSB row-major - requires PIL
from PIL import Image
stream = []
with open('image.png', 'rb') as img_file:
im = Image.open(img_file)
px = im.load()
x = 0
y = 0
end = False
@crookm
crookm / clean_tv_series_filenames.py
Last active January 10, 2019 03:08
Quick python 3 program to rename files for downloaded TV series
import glob, os, re
os.chdir('/directory/you/want/to/work/in')
for file in glob.glob('*[sS][0-9][0-9][eE][0-9][0-9]*'):
ep_string = re.search('[sS][0-9]{2}[eE][0-9]{2}', file).group(0).upper()
file_type = file.split('.')[-1]
new_name = ep_string + '.' + file_type
print(new_name)
os.rename(file, new_name)
@crookm
crookm / work_dist_query.sql
Created February 7, 2018 04:52
Atomic selection of work that prevents race conditions
UPDATE work
SET
`worker_id` = ?,
`worker_claimedAt` = NOW()
WHERE
(`worker_id` IS NULL
OR `worker_claimedAt` < DATE_SUB(NOW(), INTERVAL 30 SECOND))
AND `active` = 1
ORDER BY `worker_lastWork` DESC
LIMIT 1;
@crookm
crookm / work_dist_worker.js
Created February 7, 2018 04:51
Forked worker to continuously process information in node.js
const self = { id: 0 };
let work_loop = () => {
// some work here! :D
};
function sendPayload(payload) {
process.send(payload);
}
@crookm
crookm / work_dist_index.js
Created February 7, 2018 04:22
Setup several forked processes in node.js
const { fork } = require('child_process');
let awaiting = {}; // array of payload ids awaiting responses from workers
let awaiting_lastid = 1; // incrementing payload ids
let worker_pool = [];
function sendPayload(id, payload) {
payload.id = awaiting_lastid++; // set and add id
awaiting[payload.id] = { worker: id, date: Date.now() }