Archiv für die Kategorie „snippet“

No loopback interface on Windows (XP)

Mittwoch, 22. Oktober 2008

Learned today that Windows doesn’t support a loopback interface for localhost. In consequence, network packets destined for the local machine are never passed to any interface and therefore can’t be captured by a packet sniffer. Unfortunately, looking at the network is my preferred way of diagnosing network problems, so this behavior gets in the way. An easy workaround is to route packets to a local address to the standard gateway instead. The gateway then sends the packets back to the local machine. This is a bit of a detour, but at least the traffic shows up. This dramatically changes how the packets are being moved around, so it might not help… But just in case:

  1. grab your IP address and Gateway using ipconfig in a DOS box.
  2. route add $LOCAL_IP mask 255.255.255.255 $GATEWAY_IP metric 1
  3. when you’re done, use route delete $LOCAL_IP to get things back to normal

Visualizing Ant Redux.

Dienstag, 14. Oktober 2008

I’ve written a small update to my ant-file visualization tool. The only visible change is that the default task is now marked in the output.

You can either download the jar containing everything you need, or build it yourself from the source available via:

svn co http://a2800276.googlecode.com/svn/branches/antvis

If Antvis is run from the command line like so:

$ java -jar antvis.jar
usage: [jre] antvis.AntVis -f inputFile [-t format] [-o outfile]
	format: format supported by dot. Default: `dot`
	outfile: Default stdout
call [jre] antvis.AntVis -l for a list of supported formats

It prints out the available options. If it’s called correctly:

$ java -jar antvis.jar -f build.xml -t png -o self.png

It will produce graphical representations of the provided build.xml file like this one

self.png

for Antviz’s own build.xml or this one

jpos_ant.png

The above is an example of a more complicated build.xml script, it ships with jpos.

Backslashes in C includes…

Samstag, 27. September 2008

Who’d have thought:

  1. that DOS backslashes in C include paths aren’t only ugly and a pain, but also not legal* C:

    If the characters ‚, \, „, //, or/* occur in the sequence between the < and > delimiters, the behavior is undefined. Similarly, if the characters ‚, \, //, or /* occur in the sequence between the “ delimiters, the behavior is undefined. A header name preprocessing token is recognized only within a #include preprocessing directive.

    (C99 6.4.7.3)

  2. … the C99 Standard is available for free online This links directly to the pdf containing the current standard, which lives here.
  3. It’s easy to fix:

    find . -name '*.[c|h]' -print0 | xargs -0 \
       ruby -i.bak -pe 'scan(/^\s*#include.*/){ gsub(/\\/, "/") }'
    
  4. * yeah, I know, it’s legal just undefined.
    ** this post inspired by this.

Backing up MacOSX Address Book without MaxOSX Address Book

Dienstag, 9. September 2008

I recently installed a new harddrive on my Macbook. Before proceeding, I made a backup of my entire drive using SuperDuper. I wanted a fresh install, so instead of just dumping the old disk image on the new drive, I installed Leopard and started selectively copying what I needed.

Everything went well until I wanted my Address Book back. Unfortunately, all advice concerning backing up Address Book is along the lines of „Start Address Book and select ‚Back up‘ from the ‚File‘ menu“, but no one tells you where Address Book actually saves the addresses. The easiest way to find out turned out to be using Instruments to monitor what files Address Book opened on startup.

To make a long story short: to transfer entries from one computer to another, just copy the Folder:

/Users/.../Library/Application Support/AddressBook

You may not be able to overwrite some files, because they are in use by other programmes (in my case the culprit was Safari). You can figure out which programme currently has files open using fuser in the Terminal.

Removing PDF Restrictions.

Montag, 19. Mai 2008

Adobe’s PDF file format comes with the possibility to restrict the things you’re allowed to do with a PDF document. This has nothing do do with encrypting the document to keep unauthorized people from reading it. Instead, authors may want to disallow printing, modifying or copy&pasting parts of a document. It’s still possible to view the documents on the screen.

Apparently, on older versions of Mac OSX’s Preview, it was possible to just „Save as …“ a restricted PDF, the resulting saved file would be a PDF without restrictions. This was fixed, but the ColoySync utility still had the possibility to use the „Save as …“ trick. Apparently at some point, they fixed ColorSync as well.

As far as I can tell, the easiest way to print a restricted document nowadays is to use ColorSync to „Export …“ the PDF to a TIFF file, open the TIFF (it will be huge) in Preview and either print it directly, or print to a PDF. Of course, the resulting PDF won’t be searchable, but as far as I know, Adobe hasn’t come up with a „disallow search“ restriction (which no doubt, a lot of publishers would use) so you can search in the original, restricted PDF.

Arguments vs. Parameters

Mittwoch, 19. März 2008

Just friendly reminder from the language police. The terms argument and parameter aren’t synonyms. Parameters are the variables declared in a function definition, as in:

    void range(int to, int from)

„the function range has two int parameters named to and from„. Arguments on the other hand are the values being passed in when the function is called:

    range(0,x)

„the function range is being called with the arguments 0 and x.“

ruby main idiom

Mittwoch, 20. Februar 2008

Because I keep forgetting, it’s


if $0 == __FILE__
  puts "main"
end

where __FILE__ contains the name of the file that the currently executing code is located in and $0 is the name of the currently executing program.

Digest Ruby (MD5, SHA) in Ruby

Sonntag, 10. Februar 2008

I don’t know how many times I’ve gone to the stdlib documentation for usage information concerning digest. Unfortunately, there’s nothing to see there, move along. Documentation is provided in the src distribution [src]/ext/digest/digest.txt. The abridged version:

require 'digest/[md5|sha1|sha2|rmd160]'    
digest = Digest::[MD5|SHA1|SHA256|SHA384|SHA512|RMD160].new   
while #some loop     
  digest.update(bytes)
end
digest.digest #raw bytes
digest.hexdigest #hex

alternatively, the short form:

require 'digest/MD5'
d = Digest::MD5.new
d.hexdigest('whatever you're digesting')

sha2 contains implementations for the digest classes SHA256,SHA384,SHA512

Finally the lengths of the returned hex strings:

len bytes len hex
MD5 16 32
SHA1 20 40
RMD160 20 40
SHA256 32 64
SHA384 48 96
SHA512 64 128