Category: DevelopmentReading Arguments from the Command Line with PerlAugust 21, 2012 The variable The actual argument values are stored in the array Categories: Development Tags: perl Perl Code for Processing CSV Files July 30, 2012 Below is a sample Perl script containing many constructs that I commonly use to process output in the form of a comma-separated value (CSV) file.
use strict;
# Read from standard in, one line at a time
while (my $line=<STDIN>)
{
# Trim trailing newline
chomp $line;
# Create an array from a line of comma-separated values
my @cols = split(/,/,$line);
}
Categories: Development Tags: perl View Object Signatures in Python February 15, 2011 You can typically view the signature of an object (i.e. a list of its instance files and methods) using the class Foo:
def __init__(self):
self.first = 'Aaron'
self.last = 'Gember'
f = Foo()
dir(f)
results in the following output from ['__doc__', '__init__', '__module__', 'first', 'last'] Categories: Development Tags: python Mercurial Over SSH April 12, 2010 To clone a Mercurial (hg) repository over SSH, use the command hg clone ssh://hostname/path/to/reporeplacing hostname with the hostname of the computer who you would like to connect to via SSH to obtain the repository and path/to/repo with the path to the repository, relative to your home directory. To use a directory relative to the root directory of the remote host, add additional slash after the hostname
hg clone ssh://hostname//path/to/repo Categories: Development, Linux Installing Phidgets in Fedora January 27, 2010 Phidgets are boards for sensing and control projects that are managed via a USB connection to a computer. I use the Phidget Interface Kit 0/0/4 for my Christmas light controllers. To control the boards from a Linux workstation, it is necessary to install the Phidgets driver. To allow connectivity to Phidgets from Fedora 12 (or Fedora 10 or 11):
I typically control the Phidget board using Python. To install the necessary Python modules:
Categories: Development, Linux Tags: fedora, phidgets, python Revert Commit in Subversion January 21, 2010 In the directory you want to revert, run: svn merge -r HEAD:[revision number before bad commit] . svn commit Categories: Development, Linux Tags: subversion Preventing Auto-Padding in C Structures January 05, 2010 Most networking applications written in C use structures to easily access the data in a packet header. If all the pieces are appropriately word aligned (i.e. one or more sequential parts of the header total 4-bytes in length), then a regular C structure works just fine. The standard IP, TCP, and UDP headers are all word aligned. However, the custom packet header I was using for a project was not word aligned. Using a regular structure without any special notation, caused the GNU C compiler (gcc) to automatically add padding to the structure to force one or more sequential variables to be 4-byte aligned. But, the packet should not contain this extra padding. The parts of the header need to be "packed." To force an entire structure to be packed, add __attribute__((packed))at the end of the structure definition. For example: struct mine {
short a;
int b;
}__attribute__((packed));
It is important to note that not all architectures will allow "packed" structures. Most RISC architectures require that variables be word-aligned, and generate a fault when memory is read across two words. The x86 and x86_64 architectures allow non-word-aligned variables for backwards compatibility to earlier processor versions. Wikipedia has more details on data structure alignment. (The original source of this solution is: http://tuxsudh.blogspot.com/2005/05/structure-packing-in-gcc.html) Categories: Development, Networking Tags: c Including Code Blocks in LaTeX September 23, 2009 I recently had a need to include a block of C code in a report I was writing in LaTeX. I discovered the \usepackage{listings}
somewhere before your
\begin{lstlisting}[language=C,frame=single]
CODE GOES HERE
\end{lstlisting}
You can specify other options besides language and frame. For more details on the package see the LaTex Wikibook. Categories: Development Tags: latex Adding a Line to the Top of a File with Sed August 25, 2009 I recently needed to add a copyright notice to the top of multiple Java files. In the directory where the files were located I ran the command sed -e '1i\/* Copyright (C) 2009 Aaron Gember. */\n' -i *.java The Categories: Development, Linux Multiple Letter Mail Merge in Word 2007 August 07, 2009 I recently assisted someone with a mail-merge in Microsoft Word 2007 for a letter whose content depended on a person's interests. I started with three different components (all in the same directory):
In the Word document containing the top of the letter, I setup a mail-merge. The source data was the Excel spreadsheet. I inserted the necessary merge fields for the top of the letter. I also inserted the area of interest field surrounded by four equal signs ( ====<< Area_Of_Interest >>==== In the same document I wrote a macro to do the following:
Sub InsertLetter()
Dim dept
Dim aRange
Dim done
Dim filename
'Execute mail merge
With ActiveDocument.MailMerge
.Destination = wdSendToNewDocument
.Execute
End With
'Search entire document for special tags
done = False
Selection.SetRange ActiveDocument.Range.Start, ActiveDocument.Range.End
'Continue searching document until no more tags are found
Do While (Not done)
'Execute search
With Selection.Find
.Text = "====*===="
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = True
.MatchWildcards = True
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute
'If tag is found, get value of tag
If (Selection.Find.Found) Then
dept = ActiveWindow.ActivePane.Selection
dept = Left(dept, Len(dept) - 4)
dept = Right(dept, Len(dept) - 4)
filename = dept + ".doc"
'Verify document to insert (replacing tag) exists and insert
If (Dir(filename) <> "") Then
ActiveWindow.ActivePane.Selection = ""
Set aRange = ActiveWindow.ActivePane.Selection
aRange.Start = aRange.End
aRange.InsertFile filename:=filename
'Display and put error message in document if file does not exist
Else
MsgBox "No letter found for department: " + dept, vbExclamation
ActiveWindow.ActivePane.Selection = "No letter found for department: " _
+ dept
End If
'Update search range to search the rest of the document
Selection.SetRange Selection.End, ActiveDocument.Range.End
Else
done = True
End If
Loop
End Sub
Categories: Development Tags: excel, mail merge, word |
SearchCategories
Also see Emily & Aaron's Blog Tagsacm apt awk bash benchwork bibtex c compiz dd-wrt dia dvd eeebuntu eeepc eps excel fedora firefox flash freebsd gnome hostname iptables java kde latex mac os x mail merge mediawiki mercurial mrtg nvidia pdf perl phidgets postscript powerpoint printer putty pxe python R route scenery sed snmp ssh structures subnet subversion sudo ubuntu vegetarian vim visio windows word wrt54gl x11 yum Years |