Skip to content

Instantly share code, notes, and snippets.

View ledjon's full-sized avatar

Jon Coulter ledjon

View GitHub Profile
@ledjon
ledjon / mysql.pl
Last active December 19, 2015 11:09
Perl script to do a fast inserts into MySQL table to test auto_increment speed
#!/usr/bin/perl
use strict;
use DBI;
use Parallel::ForkManager;
# create table t1a (id int4 auto_increment primary key) engine = innodb;
# create table t1b (id int4 auto_increment primary key) engine = myisam;
# run as "time ./mysql.pl t1a" or "time ./mysql.pl t1b"
@ledjon
ledjon / pg.pl
Created July 8, 2013 01:49
Perl script to do a fast nextval() calls in PostgreSQL to show the cache = 1 vs. cache = 10000 and speed differences. Note: Lots of "sql injection" happening here because this is a demo. This runs so fast that the prepare time (when using proper ? syntax) was actually much more CPU than the work itself.
#!/usr/bin/perl
use strict;
use DBI;
use Parallel::ForkManager;
# seqtest=# create sequence t1 increment by 1 start with 1 cache 1;
# CREATE SEQUENCE
# seqtest=# create sequence t1000 increment by 1 start with 1 cache 10000;
# CREATE SEQUENCE
@ledjon
ledjon / cp-remove-bad-index-element.py
Created September 5, 2016 17:07
remove an entry from couchpotato's "release" index (when corrupted)
#!/usr/bin/python
# note: you must set this to the path to your couchpotato base installation dir:
# export PYTHONPATH=./CouchPotatoServer
from CodernityDB.database import Database
import sys
import pprint
@ledjon
ledjon / ttjsoni
Created July 30, 2018 20:06
try to json *nix tool output
I know this is a really old topic: but maybe one way to address this problem is to have a general purpose tool that does a "pretty good" job of converting text-based output to structured output.
The reality is that most *nix tools output in a way that is designed for the human mind to "parse", so there is probably a detectable structure to the output that a smart tool [smarter than one I could create] could "guess" about a structure for the data and reformat it as json. The key is getting the data into "some sort of json output", even if imperfect.
For example, taking an output like this:
$ ifconfig
eth0 Link encap:Ethernet HWaddr 06:41:73:c2:ca:15
inet addr:172.31.25.84 Bcast:172.31.31.255 Mask:255.255.240.0
inet6 addr: fe80::441:73ff:fec2:ca15/64 Scope:Link