Skip to content

Instantly share code, notes, and snippets.

@wh13371
wh13371 / oraexp.py
Created July 21, 2017 12:12
python - oracle export
#! /usr/bin/python
import sys, time, os, datetime, json
import logging, logging.handlers
import subprocess
log = logging.getLogger(__name__)
UID = "moo"
PWD = "moo"
@wh13371
wh13371 / utc.py
Created March 15, 2017 12:02
python - epoch tool
#! /usr/bin/env python
import os, argparse, time, datetime, pytz, json
import logging, logging.handlers
from pprint import pprint
"""
usage examples:
>utc.py # current epoch to timestamp for each timezone
>utc.py 1234567890 # epoch to timestamp for each timezone
>utc.py -t "2009-02-13 23:31:30" # timestamp string to epoch for each timezone
>utc.py -r # run forever
@wh13371
wh13371 / args.py
Created February 9, 2017 18:31
python - args from file(s) or STDIN
#! /usr/bin/python
import fileinput, argparse
from glob import glob
"""
# read from <file(s)> or <STDIN>
# Examples:
args.py *.txt
args.py 1.txt 2.txt 3.txt
@wh13371
wh13371 / get.lines.pl
Created May 7, 2016 06:41
perl - get X to Y lines from file
use strict;
use warnings;
use 5.020;
use Getopt::Long qw(GetOptions);
Getopt::Long::Configure ("bundling"); # -d
my $debug;
GetOptions('debug|d' => \$debug) or die "$0";
@wh13371
wh13371 / iis_log_parser.py
Created March 3, 2016 11:39
python - very basic IIS log parser
import fileinput, sys
from pprint import pprint
header = ['date', 'time', 's-ip', 'cs-method', 'cs-uri-stem', 'cs-uri-query', 's-port', 'cs-username', 'c-ip', 'cs(User-Agent)', 'sc-status', 'sc-substatus', 'sc-win32-status', 'sc-bytes', 'cs-bytes', 'time-taken']
l = [] # a list to hold a <dict> for each line in the IIS log file
for line in fileinput.input(sys.argv[1]):
if not line.startswith('#'):
fields = line.split()
@wh13371
wh13371 / tee.pl
Created February 26, 2016 19:08
perl - tee
#! /usr/bin/perl
# usage: ping 8.8.8.8 | tea.pl [-v] [-t] [FILE]
# -v = verbose | -t = prefix timestamp to output | FILE = output filename
use IO::Handle;
use Getopt::Long;
use Time::HiRes;
use POSIX;
@wh13371
wh13371 / exif.py
Created February 19, 2016 10:30
python - exif image renamer
#! /usr/bin/python
import sys, datetime, os, time
from PIL import Image # for <PIL> on Python 2.6 => "pip install Pillow" - for Python 2.7 <PIL> part of core modules
from PIL.ExifTags import TAGS
# usage examples:
# ./exif.py ~/Pictures/*
# ./exif.py DSCF0155.JPG
# ./exif.py ~/Pictures/DSCF0155.JPG ~/Pictures/DSCF0156.JPG
@wh13371
wh13371 / flipflop.pl
Created February 18, 2016 16:07
perl - flipflop
# tiny "flip-flop"
use strict;
use warnings;
use 5.020;
use Getopt::Long qw(GetOptions);
Getopt::Long::Configure ("bundling"); # -lcd => line / chomp / debug
my $debug;
@wh13371
wh13371 / .bashrc.sh
Created October 3, 2015 11:20
centos - bashrc
# .bashrc
# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi
# User specific aliases and functions
# a decent bash prompt # \d or \D = date - \t = time - \u = user - \h = host - \w = cwd
@wh13371
wh13371 / docopt_simple.py
Created July 21, 2015 19:34
python - docopt example (simple)
#!/usr/bin/python
"""
Usage:
% [-dv] FILE ...
% -h | --help
% --version
Options: