Skip to content

Instantly share code, notes, and snippets.

@wh13371
wh13371 / grep58.py
Last active August 29, 2015 14:14
python - mini grep with text highlight
#! /usr/bin/python
"""
Usage:
grep58.py <pattern> <file>...
grep58.py <pattern>
Examples:
# from file(s)
@wh13371
wh13371 / now.pl
Last active August 29, 2015 14:14
perl - a half decent datetime ("yyyy_mm_dd_HH_mm_ss.ffffff") method
#! /usr/bin/perl
# a Perl script with a "now" method to return a (yyyy_mm_dd_HH_mm_ss.ffffff) timestamp - Linux & Windows filename valid
use strict;
use warnings;
use POSIX; # for "strftime"
use Time::HiRes; # for "Time::HiRes::gettimeofday"
use 5.010;
@wh13371
wh13371 / perl_template.pl
Last active August 29, 2015 14:14
perl - rough template thats outputs to screen & log file
#! /usr/bin/perl
use strict;
use warnings;
use 5.010;
use Time::HiRes qw/time gettimeofday/;
use POSIX 'strftime';
use FileHandle ('autoflush');
use Getopt::Std;
@wh13371
wh13371 / python_line_count.py
Last active August 29, 2015 14:14
python - file line count
#! /usr/bin/python
"""
Usage: ./file.line.count.py <filename>
Example: ./file.line.count.py error.log
"""
import sys
@wh13371
wh13371 / .bashrc
Last active August 29, 2015 14:14
bashrc - linux snippets thereof...
# a decent bash prompt
# \d = date - \t = time - \u = user - \h = host - \w = cwd
PS1='\[\e[1;32m\][\[\e[1;33m\]\d \[\e[1;34m\]\t \[\e[1;32m\]\u\[\e[1;36m\]@\[\e[1;31m\]\h\[\e[1;33m\](\[\e[1;36m\]\w\[\e[1;33m\])\[\e[1;32m\]]\[\e[1;37m\]% \e[m'
# disk usage
alias diskspace="du -Sh | sort -n -r |more"
# move up directories (i.e. "up" or "up 3")
up(){
@wh13371
wh13371 / runcmd.pl
Last active August 29, 2015 14:14
perl - runcmd - run commands and output to console\log file
#!/usr/bin/perl
# examples:
# ./runcmd.pl -l -c "ls -lah"
# include <timestamp> and enable <verbose> mode
# ./runcmd.pl -t -l -v -c "ls -lah"
# run multiple commands with <delay> = 5
@wh13371
wh13371 / chomp_stdin.pl
Last active August 29, 2015 14:14
python - chomp\strip stdin
#! /usr/bin/python
import sys
"""
usage: cat dogs_breakfast.py | ./chomp_stdin.py > dogsnuts.py
"chomp" noise from each line, half useful if you want to drop ALL formatting\identation
"""
@wh13371
wh13371 / fetch.pl
Last active August 29, 2015 14:14
perl - "fetch" - a tiny grep/ACK util - more for education than practicality...
#!/usr/bin/perl
# "fetch" - a tiny grep\ACK util - more for education than practicality...
use strict;
use warnings;
use 5.010;
use File::Find;
use Cwd;
use Time::HiRes qw/ time /;
@wh13371
wh13371 / output.debug.string.py
Last active October 22, 2023 12:51
python - logging to DbgView with OutputDebugString
#! /usr/bin/python
import logging
import ctypes
# output "logging" messages to DbgView via OutputDebugString (Windows only!)
OutputDebugString = ctypes.windll.kernel32.OutputDebugStringW
class DbgViewHandler(logging.Handler):
def emit(self, record):
@wh13371
wh13371 / diff.py
Created February 17, 2015 16:55
python diff util
#! /usr/bin/python
import sys, os, time, difflib, optparse
BLUE = '\033[94m'
GREEN = '\033[92m'
YELLOW = '\033[93m'
RED = '\033[91m'
CYAN = '\033[96m'
WHITE = '\033[97m'