<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>jsilence.org &#187; Code</title>
	<atom:link href="http://www.jsilence.org/category/code/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.jsilence.org</link>
	<description>invisible, inaudible, in the background pattern</description>
	<lastBuildDate>Tue, 31 Jan 2012 19:52:36 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<atom:link rel='hub' href='http://www.jsilence.org/?pushpress=hub'/>
		<item>
		<title>Tor Tunnel Convenience on OSX</title>
		<link>http://www.jsilence.org/2012/01/tor-tunnel-convenience-on-osx/</link>
		<comments>http://www.jsilence.org/2012/01/tor-tunnel-convenience-on-osx/#comments</comments>
		<pubDate>Mon, 30 Jan 2012 11:08:32 +0000</pubDate>
		<dc:creator>jsilence</dc:creator>
				<category><![CDATA[Code]]></category>

		<guid isPermaLink="false">http://www.jsilence.org/?p=480</guid>
		<description><![CDATA[Occasionally I use the Tor proxy for surfing. Since I don't want to bog down my local internet connection which often is shared with others, I run a Tor middle node on a virtual server at some ISP. This way I can contribute to the Tor network all the time, even when I am ...]]></description>
			<content:encoded><![CDATA[<p>Occasionally I use the Tor proxy for surfing. Since I don&#8217;t want to bog down my local internet connection which often is shared with others, I run a Tor middle node on a virtual server at some ISP. This way I can contribute to the Tor network all the time, even when I am not currently using Tor myself.</p>
<p>For connecting to my Tor node, I set up some small scripts to do all the plumbing for me. Simply fire up my tortunnel, and I&#8217;m ready to go. Switching Proxies on OSX is buried deep in a second level menu item in the network settings. I am using two little scripts to have the proxy switched on and off automatically.</p>
<pre>
#!/bin/bash
HOST=`host my.virtualserver.tld|awk '{print $4}'`
pon
sudo ssh -p24 username@$HOST  -L localhost:8123:$HOST:8123 \
 -L  localhost:53:$HOST:53 -t 'tmux -c "/usr/local/bin/arm/arm"'
pof
</pre>
<p>Since I also redirect my DNS lookups I have to fetch the hostname of my own server before I switch on the proxy. I have dnsmasq running on my server. This allows me to filter some bogus name resolutions. Sure, the DNS lookups can be traced back to my server. Maybe I will funnel them tru Tor later. </p>
<p>The arm Script on my server shows nifty graphs and info about the health of my Tor node.</p>
<p><code>pon</code> and <code>pof</code> are simple shellscripts which use the OSX networksetup tool to operate the proxy settings:</p>
<pre>#!/bin/bash
networksetup -setsecurewebproxystate Ethernet on
networksetup -setwebproxystate Ethernet on
networksetup -setsecurewebproxystate Airport on
networksetup -setwebproxystate Airport on
networksetup -setdnsservers Ethernet 127.0.0.1
echo "proxy is on"
</pre>
<pre>
#!/bin/bash
networksetup -setsecurewebproxystate Ethernet off
networksetup -setwebproxystate Ethernet off
networksetup -setsecurewebproxystate Airport off
networksetup -setwebproxystate Airport off
etworksetup -setdnsservers Ethernet empty
echo "proxy is off"
</pre>
<p>I use Safari for my Tor surfing since Safari uses the system wide proxy settings. Firefox uses its own settings. This way I can torsurf in parallel to normal surfing. Of course there are some proxy switching plugins for Firefox I could use, but since I usually keep a lot of tabs open and do my main surfing on FF I decided to use Safari as my anonymous Browser.</p>
<p>Private browsing can not be automatically be turned on per default in Safari, thus I am using a little Script to activate Safari and set it to private mode:</p>
<pre>
tell application "Safari"
	activate
end tell

tell application "System Events"
	tell process "Safari"
		tell menu bar 1
			tell menu bar item "Safari"
				tell menu "Safari"
					click menu item "Private Browsing"
				end tell
			end tell
		end tell
	end tell
end tell
</pre>
<p>If you are using a different system language, you will have to adjust the &#8220;Private Browsing&#8221; term into the approriate locale. Simply check the Safari menu.</p>
<p>The start page of Safari is set to the <a href="https://check.torproject.org/">Tor Check website</a> to see whether I am really using the Tor network.</p>
<p class="wp-flattr-button"></p> <p><a href="http://www.jsilence.org/?flattrss_redirect&amp;id=480&amp;md5=b46bfcdb29bf0152adb01953ed0f8219" title="Flattr" target="_blank"><img src="http://www.jsilence.org/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.jsilence.org/2012/01/tor-tunnel-convenience-on-osx/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Edit Pdf Metadata</title>
		<link>http://www.jsilence.org/2011/01/edit-pdf-metadata/</link>
		<comments>http://www.jsilence.org/2011/01/edit-pdf-metadata/#comments</comments>
		<pubDate>Tue, 25 Jan 2011 14:05:40 +0000</pubDate>
		<dc:creator>jsilence</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Productivity]]></category>
		<category><![CDATA[cli]]></category>
		<category><![CDATA[metadata]]></category>
		<category><![CDATA[OSX]]></category>
		<category><![CDATA[Pdf]]></category>

		<guid isPermaLink="false">http://www.jsilence.org/?p=407</guid>
		<description><![CDATA[For my 'Project Paperless' I recently purchased the highly recommended Fujitsu ScanSnap 1500M, which comes bundled with a functionally limited edition of Abby Finereader. The Finereader software receives the scanned document and runs a surprisingly high quality OCR on it, resulting in a Pdf which shows the scanned paper in the background, but additionally ...]]></description>
			<content:encoded><![CDATA[<p>For my &#8216;Project Paperless&#8217; I recently purchased the highly recommended Fujitsu ScanSnap 1500M, which comes bundled with a functionally limited edition of Abby Finereader. The Finereader software receives the scanned document and runs a surprisingly high quality OCR on it, resulting in a Pdf which shows the scanned paper in the background, but additionally has selectable text above that. The output Pdf has picture and text and is therefore indexable by Spotlight. Sweet.</p>
<p>There are two problems with this setup:</p>
<ol>
<li>Title, Author and Creator metadata is not editable</li>
<li>Scans from other sources are refused by Finereader.</li>
</ol>
<p><span id="more-407"></span>Searching for a convenient tool to solve this I came across <a title="Pdf Toolkit Homepage" href="http://www.pdflabs.com/tools/pdftk-the-pdf-toolkit/">pdftk</a>, which can be installed via <a title="MacPorts Homepage" href="http://www.macports.org">MacPorts</a> or <a title="Pdf Tagging" href="http://hubionmac.com/wordpress/2009/06/pdfs-mal-schnell-taggen/">other sources</a> (Link target in german). pdftk allows you to manipulate a couple of aspects of a pdf file, among which extracting and changing Pdf metadata such as Title, Author or Creator is one.<br />
On the command line one would first extract the metadata into a separate file:</p>
<pre>user@host &gt; pdftk input_file.pdf dump_data &gt; info.txt
</pre>
<p>After editing the info.txt file the Metadata can be sent back into the file with:</p>
<pre>user@host &gt; pdftk input_file.pdf update_info  info.txt output output_file.pdf
</pre>
<p>Some pdf files, depending how they were generated, don&#8217;t seem to have a metadata dictionary, resulting in a warning:</p>
<pre>user@host &gt; pdftk input_file.pdf dump_data
Warning: no info dictionary found
NumberOfPages: 1
</pre>
<p>The metadata can not be updated when there is no metadata dictionary:</p>
<pre>user@host &gt; pdftk input_file.pdf update_info info.txt output utput_file.pdf
Internal Error: no Info dictionary found, so no Info added.
Warning: no Info added to output PDF.
</pre>
<p>The solution to this is to pipe the input file once through pdftk which will add a info dictionary:</p>
<pre>user@host &gt; pdftk input_file.pdf cat output input_file.pdf
user@host &gt;
</pre>
<p>After that the metadata can be updated as described above.</p>
<p>For OSX there is a convenient GUI for editing metadata named <a title="Pdf Metaedit" href="http://hubionmac.com/wordpress/2009/06/pdfs-mal-schnell-taggen/">Pdf_Metaedit</a>. It is based on pdftk, so you&#8217;ll have to install that first.</p>
<p>The only thing that is needed for coercing Abby Finereader into processing foreign scans is to set the &#8216;Creator&#8217; field to &#8216;ScanSnap Manager #S1500M&#8217; using the described method. If there are only few Pdf documents, then the Metaedit GUI will come in handy. If there are more, it will be better to script it and maybe even convenient to create a folder action for this.</p>
<p>UPDATE: Wrote a small script for automatic processing and cloned the &#8220;Postscipt to Pdf&#8221; folder action that comes with OSX to call this script for all files in my incoming scans folder. Now I only have to throw the files into the right folder to have the creator changed. Next step is to automatically process them with Abby Finereader.  </p>
<pre>
#!/bin/bash

PDFTK=/opt/local/bin/pdftk

SCRIPTNAME=`basename $0`
SOURCEFILE=$1
TARGETFILE=$2
METATMPFILE=`mktemp /tmp/${SCRIPTNAME}.TXT.XXXXXX` || exit 1
PDFTMPFILE=`mktemp /tmp/${SCRIPTNAME}.PDF.XXXXXX` || exit 1

# check for metadata dictionary and run through the pipe if there is none
$PDFTK $SOURCEFILE dump_data_utf8 > $METATMPFILE
if [ "`wc -l $METATMPFILE | awk '{print $1}'`" -eq "1" ]
then
    $PDFTK $SOURCEFILE cat output $PDFTMPFILE
    $PDFTK $PDFTMPFILE dump_data_utf8 > $METATMPFILE   # need some metadata to work with
else
    cp $SOURCEFILE $PDFTMPFILE                                  # working with the tempfile
fi

# replace Creator with "ScanSnap Manager #S1500M" for Abby Finereader
awk '{if($2 == "Creator")  {print;getline;print $1 " ScanSnap Manager #S1500M";} else print}' $METATMPFILE | $PDFTK $PDFTMPFILE update_info_utf8 - output $TARGETFILE

# cleanup
rm $METATMPFILE $PDFTMPFILE
</pre>
<p class="wp-flattr-button"></p> <p><a href="http://www.jsilence.org/?flattrss_redirect&amp;id=407&amp;md5=f71dbe7bf34a8a0bf918c27a0735d5dc" title="Flattr" target="_blank"><img src="http://www.jsilence.org/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.jsilence.org/2011/01/edit-pdf-metadata/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mein schnörkelloser bash Prompt</title>
		<link>http://www.jsilence.org/2010/02/mein-schnorkelloser-bash-prompt/</link>
		<comments>http://www.jsilence.org/2010/02/mein-schnorkelloser-bash-prompt/#comments</comments>
		<pubDate>Thu, 11 Feb 2010 21:29:12 +0000</pubDate>
		<dc:creator>jsilence</dc:creator>
				<category><![CDATA[Code]]></category>

		<guid isPermaLink="false">http://www.jsilence.org/?p=141</guid>
		<description><![CDATA[Es gibt im Netz tausende Beispiele für fancy bash prompts.  Ich mag meinen Prompt schnörkellos und effizient. Ich möchte wissen, auf welcher Maschine ich bin, ich möchte gerne wissen wo ich bin, aber ich möchte auch noch Platz zum Tippen haben und nicht nur lange Pfade sehen.
Deshalb lasse ich mir die letzten beiden ...]]></description>
			<content:encoded><![CDATA[<p>Es gibt im Netz tausende Beispiele für fancy bash prompts.  Ich mag meinen Prompt schnörkellos und effizient. Ich möchte wissen, auf welcher Maschine ich bin, ich möchte gerne wissen wo ich bin, aber ich möchte auch noch Platz zum Tippen haben und nicht nur lange Pfade sehen.<br />
Deshalb lasse ich mir die letzten beiden Verzeichnisse anzeigen. An denen lässt sich in der Regel sehr gut ablesen, wo man gerade herumdümpelt.</p>
<p>In der .bashrc fügt man dafür folgendes ein:<br />
<code><br />
function PWD {<br />
tmp=${PWD%/*/*};<br />
[ ${#tmp} -gt 0 -a "$tmp" != "$PWD" ] &#038;&#038; echo ${PWD:${#tmp}+1} || echo $PWD;<br />
}</code><br />
<code><br />
export PS1="\h:\$(PWD 3)>";</code></p>
<p>Voilá!</p>
<p class="wp-flattr-button"></p>]]></content:encoded>
			<wfw:commentRss>http://www.jsilence.org/2010/02/mein-schnorkelloser-bash-prompt/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

