Skip to content

Instantly share code, notes, and snippets.

View schnell18's full-sized avatar

Justin Zhang schnell18

View GitHub Profile
@schnell18
schnell18 / dbext SQL*Plus autotrace profile
Last active December 22, 2015 06:59
A sample dbext profile that enables auto trace so that the execution plan is displayed after the result of SQL statement in a Vim buffer
let g:dbext_default_profile_system = 'type=ORA:user=system@host1_ora:passwd=system'
let g:dbext_default_profile_hr = 'type=ORA:user=hr@host1_ora:passwd=hr'
let g:dbext_default_SQLITE_bin = 'sqlite3'
let g:dbext_default_profile_sqlite = 'type=SQLITE:dbname=/home/mfg/work/000.sqlite'
let g:dbext_default_ORA_cmd_header = "set timing on\n" .
\ "set autotrace on\n" .
\ "set pagesize 50000\n" .
\ "set wrap off\n" .
\ "set sqlprompt \"\"\n" .
\ "set linesize 10000\n" .
@schnell18
schnell18 / set_ora_shared_pool_size
Created September 10, 2013 07:48
Display advises on optimal Oracle shared pool size
-- list advises on optimal shared pool size
select 'Shared Pool' component,
shared_pool_size_for_estimate est,
estd_lc_time_saved_factor parse_time_factor,
case when current_parse_time_elapsed_s + adjustment_s < 0
then 0
else current_parse_time_elapsed_s + adjustment_s
end response_time
from (select shared_pool_size_for_estimate,
shared_pool_size_factor,
@schnell18
schnell18 / ssh_config_annotated
Created October 28, 2013 04:55
Well commented ssh_config file for SSH client side configuration.
# ssh_config system-wide configuration for OpenSSH clients
# This is the ssh client system-wide configuration file. This
# file provides defaults for users that are compliant with SSH
# policy and ensure best practices are followed. While this file
# is compliant, please keep in mind that users can change settings
# with user-specific overrides from the command line or their own
# config file in some cases.
# Configuration data is parsed as follows:
# 1. command-line options
# 2. user-specific file
@schnell18
schnell18 / list_dates.sh
Last active December 27, 2015 01:29
find 8-digit named SQLite databases under current directory and run SQL and redirect the result to individual files. The gist demonstrates the use of regex in find command.
for db in $(find . -regextype posix-extended -regex '.*\<[0-9]{8}$' | cut -d'/' -f2-)
do
cat << EOF | sqlite3 $db > $db.dates
select distinct date(login_time, 'unixepoch') login
from login_record
;
EOF
done
@schnell18
schnell18 / create_chrootjail.sh
Created November 3, 2013 05:23
Script to automate the creation of chroot jail w/ minimal executables to run git.
#!/bin/sh
# script to automate the creation of chroot jail
# w/ minimal executables to run git
export CHROOT=/var/chroot
function copy_binary() {
for i in $(ldd $*|grep -v dynamic|cut -d " " -f 3|sed 's/://'|sort|uniq)
do
cp --parents $i $CHROOT
@schnell18
schnell18 / find_tickets
Last active December 27, 2015 08:49
find ticket from svn commit message for given list of files
#!/bin/sh
# List the tickets which modify the set of files under <your_sub_dir> in the history.
for f in $(find <your_sub_dir> -name .svn -a -type d -prune -o -type f -print)
do
svn log $f | egrep "^XXX-.*:" | cut -d ":" -f1 | sort | uniq >> tickets.tmp
done
cat tickets.tmp | sort | uniq > tickets.lst
@schnell18
schnell18 / get_authorized_keys.pl
Last active December 27, 2015 15:49
This script retrieves SSH Public keys from LDAP for user granted SSH access to gitolite managed Git repositories. It's an LDAP equivalent of .authorized_keys file.
#!/usr/bin/perl -w
use strict;
use Net::LDAP;
die "Username not specified\n" unless @ARGV;
if ($ARGV[0] ne "git") {
# don't let regular user authenticate by LDAP public key
printf "%s\n", get_pub_key($ARGV[0]);
@schnell18
schnell18 / convert_to_vCard.pl
Created November 10, 2013 14:15
This script convert simple user name and mobile phone in .csv to vCard format so that it can be imported in the mobile phone easily.
#!/usr/bin/perl -w
use Text::vCard::Addressbook;
my $ab = Text::vCard::Addressbook->new();
open my $f, '<', 'address.txt' or die "Can not open file for read: $!\n";
while(<$f>) {
chomp;
my ($fn, $phone) = split(/\s+/, $_);
my $vcard = $ab->add_vcard();
@schnell18
schnell18 / create_branches
Last active December 28, 2015 09:49
Massively create 9 branches in one go
for b in $(echo {test,sup,prod}/{intl,trck,trlr})
do
git branch $b
done
@schnell18
schnell18 / shutdown_vboxnet0
Created November 15, 2013 13:47
Remove and re-create the host only network vboxnet0 to work around issue which hangs OSX Maverick shutdown process
#!/bin/sh
# This script is a workaround to virtualbox
# hostonly network hang on OSX Maverick.
vboxmanage hostonlyif remove vboxnet0
vboxmanage hostonlyif create