Skip to content

Instantly share code, notes, and snippets.

@jkatricak
jkatricak / rosters.pl
Created April 25, 2013 19:12
rosters.pl for Baseball Hack 22 (Windows)
#!/usr/bin/perl
print "retroID,lastName,firstName,bats,throws,team,pos\n";
opendir RSDIR, "." or die "can't open directory .: $!\n";
while (readdir RSDIR) {
if ( $_ =~ /(\d\d\d\d)eve$/ ) {
opendir YRDIR, $_ or die "can't open directory .: $!\n";
chdir($_) or die "can't change to directory .: $!\n";
while (readdir YRDIR) {
@jkatricak
jkatricak / translate.pl
Created April 25, 2013 19:11
translate.pl for Baseball Hack 22 (Windows)
#!/usr/bin/perl
use Archive::Extract;
$outfile = '"C:\Users\John\Desktop\Baseball Hacks\retrosheet\pbp.csv"';
print `type all_hdr.txt > $outfile`;
opendir RSDIR, "." or die "can't open directory .: $!\n";
while (readdir RSDIR) {
if ( $_ =~ /(\d\d\d\deve)\.zip$/ ) {
print "Unzipping $_\n";
@jkatricak
jkatricak / CreateClass.vb
Created June 16, 2011 17:32
create a basic VB.NET class given an array of property names
'create a basic class given an array of property names
Public Sub CreateClass()
Dim cols
cols = Split("LETTER-NBR,INST,APPL,BRCH-ACCT,LST-PROM-DT,LST-PROM-AMT,PRIMARY-NAME,SECONDARY-NAME,ADDR-LINE-1,ADDR-LINE-2,CITY-STATE,TAX-ID-NBR,PROMS-BRKN,LEGAL-STATUS,AGENT-NBR,ACCT-TYPE,COLLAT-DESC,DUE-DATE,DUE-AMT,GRACE-DAYS,LST-PMT-DT,LST-PMT-AMT,CURR-BAL,REG-PMT-AMT,EMP-ID,ORIG-AMT,DT-1,DT-2,DT-3,DT-4,AMT-1,AMT-2,AMT-3,AMT-4,NBR-1,NBR-2,NBR-3,NBR-4,SAF-1,SAF-2,SAF-3,SAF-4,LAF-1,LAF-2,LAF-3,LAF-4,LAF-5,PHONE-NBR,LC-DUE,DEF-LC", ",")
Dim outfile As New System.IO.StreamWriter("c:\documents and settings\jkatricak\desktop\letterclass.txt")
For Each col In cols
col = Replace(col, "-", "_")
outfile.WriteLine(vbTab & "Private _" & col & " As String = " & Chr(34) & Chr(34))
@jkatricak
jkatricak / MSbkup_copy.bat
Created March 8, 2011 15:31
automate SQL Server backups
CLS
@ECHO OFF
ECHO Backing up SQL databases to file.
"C:\Program Files\Microsoft SQL Server\90\Tools\Binn\osql.exe" -E -S SERVERNAME -i "C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Backup\SQL Backup Files\backup.sql"
ECHO Done.
@jkatricak
jkatricak / mp32wav.pl
Created February 6, 2011 20:16
Convert multiple mp3 files to wav using lame
#!/usr/bin/perl
foreach $argnum (0 .. $#ARGV) {
$tmp = $ARGV[$argnum];
$ARGV[$argnum] =~ s/\.mp3/\.wav/g;
print "$tmp\n";
system("lame --decode \"$tmp\" \"$ARGV[$argnum]\"");
}
@jkatricak
jkatricak / ddb2bdb.vbs
Created February 3, 2011 20:57
Rename all files in a directory with one extention to another extension
'Convert .ddb files to .bdb for camera backup software
'Note: this script must be in the same directory
'(normally _DDB_) as the files you want to convert.
Set WshShell = WScript.CreateObject("WScript.Shell")
Set objFS = CreateObject("Scripting.FileSystemObject")
strCurrentFolder=WshShell.CurrentDirectory
Dim fso, f, f1, fc, s
Dim i
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFolder(strCurrentFolder)
@jkatricak
jkatricak / permute.pl
Created January 29, 2011 21:01
Coed lineup generator
#!/usr/bin/perl
use Algorithm::Permute;
# put players and their obp/slgs here
my @pname = ('John','Eddie','Scott','Todd','Mario','Beth','Maggie','Erin','Amanda');
my @pobp = (.677,.590,.563,.556,.364,.500,.300,.333,.273);
my @pslg = (.900,.921,.552,.722,.364,.370,.300,.200,.200);
# formulae from http://www.beyondtheboxscore.com/story/2006/2/12/133645/296
my @obpx = (2.997,2.255,2.141,1.670,2.254,1.346,1.528,1.188,2.550);
my @slgx = (.931,1.263,.933,1.504,1.146,1.237,1.164,.825,.539);
@jkatricak
jkatricak / cleanmp3.pl
Created January 29, 2011 20:59
Convert filenames from upper to lower case, strip out parens and apostrophes
#!/usr/bin/perl
foreach $argnum (0 .. $#ARGV) {
$tmp = $ARGV[$argnum];
$ARGV[$argnum] =~ tr/A-Z/a-z/;
$ARGV[$argnum] =~ s/\(//g;
$ARGV[$argnum] =~ s/\)//g;
$ARGV[$argnum] =~ s/\'//g;
print "$tmp\n";
system("mv \"$tmp\" \"$ARGV[$argnum]\"");
}
@jkatricak
jkatricak / gist:801024
Created January 28, 2011 21:37
VBA to create an HTML table from the current Excel worksheet
'TODO:
'check/prompt number of rows/columns
'prompt for border width
'differentiate bold and not (plus other formatting?)
'output to ...
Sub CreateHTMLTable()
Dim strTable As String
Dim i As Long, j As Integer
Dim lngRows As Long, intCols As Integer