Skip to content

Instantly share code, notes, and snippets.

View wwwslinger's full-sized avatar

Jason McInerney wwwslinger

  • @adverttu
  • San Diego, CA
View GitHub Profile
@wwwslinger
wwwslinger / parallel_mysql_import.sh
Last active August 29, 2015 14:09
Parallelize a large MySQL import (in part from https://gist.github.com/wardbekker/964146)
# Large (multi-GB), gzipped mysqldump file: dump.sql.gz
# Split into a file per table, but appending any header optimizations with SET and USE statements
zcat dump.sql.gz | awk '/DROP TABLE IF EXISTS/{n++}{print >"out" n " .sql" }'
# Creates n output files, for example 34, but the first "out.sql" with no number
# has all the header SET and USE statements. We need to prepend out.sql to every
# other outn.sql. We have to do this with a temporary outn.txt file and GNU Parallel
# (http://www.gnu.org/software/parallel/):
mv out.sql out.txt
@wwwslinger
wwwslinger / dell1600n-net-scan.pl
Created June 25, 2014 22:53
Dell 1600n Network Scanning script for Linux and Mac (from http://www.jon.demon.co.uk/dell1600n-net-scan/)
#!/usr/bin/perl -w
# Perl hack to do network scanning using Dell 1600n printer/scanner/fax/copier.
# Read LICENCE section below for terms and conditions.
# Run with no args for usage.
# $Id: dell1600n-net-scan.pl,v 1.64 2010-09-19 16:19:33 jon Exp $
#
# Jon Chambers, 2005-05-19
#
# Contains excellent and gratefully received patches from:
@wwwslinger
wwwslinger / pyevolve_xmas.py
Last active January 1, 2016 08:59
Evolve yourself a Merry Christmas!
from pyevolve import G1DBinaryString, GSimpleGA
import binascii, numpy as np
targ = np.array(list(str(bin(int(binascii.hexlify("Merry Christmas!"), 16))[2:])))
genome = G1DBinaryString.G1DBinaryString(127)
genome.evaluator.set(lambda chromosome: sum(np.array(list(str(chromosome.getBinary()))) == targ))
ga = GSimpleGA.GSimpleGA(genome,42)
ga.setGenerations(100)
ga.evolve(freq_stats=10)
print ga.bestIndividual()
print "".join(targ)
@wwwslinger
wwwslinger / wav_components.py
Created September 19, 2013 18:18
Read a .wav audio file, create the spectrogram, run ISA for components.
import wave, struct, numpy as np, matplotlib.mlab as mlab, pylab as pl
def wavToArr(wavefile):
w = wave.open(wavefile,"rb")
p = w.getparams()
s = w.readframes(p[3])
w.close()
sd = np.fromstring(s, np.int16)
return sd,p
def wavToSpec(wavefile,log=False,norm=False):
@wwwslinger
wwwslinger / get_urls_prll.py
Created September 15, 2013 04:02
Get urls from a file list recursively and in parallel
'''Creates a directory based on the id in the line
and recursively downloads site files to a specified depth.
Files are save with directory structure of the site according
to the wget implementation.
Example site_list.txt file:
id_345 http://www.stackoverflow.com
id_367 http://stats.stackexchange.com
id_378 http://www.google.com