<?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/"
	xmlns:series="http://unfoldingneurons.com/"
	>

<channel>
	<title>Voodoo Programming &#187; Hack</title>
	<atom:link href="http://www.cneophytou.com/tag/hack/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.cneophytou.com</link>
	<description>Things programmers do that they know shouldn&#039;t work but they try anyway, and which sometimes actually work, such as recompiling everything.</description>
	<lastBuildDate>Fri, 12 Nov 2010 17:07:39 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
		<item>
		<title>Downloading your code from Google App Engine</title>
		<link>http://www.cneophytou.com/2008/04/17/downloading-your-code-from-google-app-engine/</link>
		<comments>http://www.cneophytou.com/2008/04/17/downloading-your-code-from-google-app-engine/#comments</comments>
		<pubDate>Thu, 17 Apr 2008 14:42:23 +0000</pubDate>
		<dc:creator>Constantinos</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[Google Apps]]></category>
		<category><![CDATA[Hack]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://www.cneophytou.com/?p=112</guid>
		<description><![CDATA[I've started using Google's App Engine since it launched, mostly playing around with Python (always wanted to learn), and setting up a small app to deal with my Desktop Photo Feed script. One irritation I had was that I wanted to share my code with a friend, but the app engine doesn't provide any way [...]]]></description>
			<content:encoded><![CDATA[I've started using Google's <a href="http://appengine.google.com/">App Engine</a> since it launched, mostly playing around with Python (always wanted to learn), and setting up a small app to deal with my <a href="http://www.cneophytou.com/2008/04/17/photo-feed-as-desktop-background/">Desktop Photo Feed</a> script. One irritation I had was that I wanted to share my code with a friend, but the app engine doesn't provide any way of downloading the source code.<br />
<br />
One way around this that I found, was a blog post by <a href="http://david-burger.blogspot.com/">David Burger</a> on <a href="http://david-burger.blogspot.com/2008/04/download-your-code-from-google-app.html">Download Your Code from Google App Engine</a>, where he created a Makefile to do the dirtywork. Because I don't like Makefiles (and have it from good authority that Googlers hate Makefiles too, but that's besides the point - just to reinforce my position), I modified his method to make it slightly more versatile so that it can work well with OS X (<code>tar</code> includes ._* resource fork files which are annoying), and also turn it into a shell script.<br />
<span id="more-112"></span>
<br />
There are two steps to the process. First, save this code as a file called something like <code>update.sh</code> in the base folder where your app code is located, and make it executable:</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #007800;">ARCHIVE_DIR</span>=archive
<span style="color: #007800;">ARCHIVE_NAME</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">basename</span> <span style="color: #007800;">$PWD</span><span style="color: #000000; font-weight: bold;">`</span>.tgz
&nbsp;
<span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #660033;">-rf</span> <span style="color: #800000;">${ARCHIVE_DIR}</span>
<span style="color: #c20cb9; font-weight: bold;">find</span> . <span style="color: #660033;">-name</span> <span style="color: #ff0000;">&quot;*~&quot;</span> <span style="color: #660033;">-delete</span>
<span style="color: #c20cb9; font-weight: bold;">find</span> . <span style="color: #660033;">-name</span> <span style="color: #ff0000;">&quot;*pyc&quot;</span> <span style="color: #660033;">-delete</span>
<span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">COPY_EXTENDED_ATTRIBUTES_DISABLE</span>=<span style="color: #c20cb9; font-weight: bold;">true</span>
<span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">COPYFILE_DISABLE</span>=<span style="color: #c20cb9; font-weight: bold;">true</span>
<span style="color: #c20cb9; font-weight: bold;">tar</span> <span style="color: #660033;">-czf</span> <span style="color: #800000;">${ARCHIVE_NAME}</span> <span style="color: #660033;">--exclude</span> .DS_Store <span style="color: #660033;">--exclude</span> <span style="color: #800000;">${ARCHIVE_NAME}</span> <span style="color: #660033;">-C</span> ..<span style="color: #000000; font-weight: bold;">/</span> <span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">basename</span> <span style="color: #007800;">$PWD</span><span style="color: #000000; font-weight: bold;">`</span>
<span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #660033;">-p</span> <span style="color: #800000;">${ARCHIVE_DIR}</span>
<span style="color: #c20cb9; font-weight: bold;">mv</span> <span style="color: #800000;">${ARCHIVE_NAME}</span> <span style="color: #800000;">${ARCHIVE_DIR}</span>
appcfg.py update .<span style="color: #000000; font-weight: bold;">/</span></pre></div></div>



<p>
<a href='http://www.cneophytou.com/wp-content/uploads/2008/04/update.sh'>Download this script</a><br />
<br />
Then, you would probably want to password protect the resource that points to this archive file, so add this to your <code>app.yaml</code> file:</p>


<div class="wp_syntax"><div class="code"><pre class="yaml" style="font-family:monospace;">- url: /archive
  static_dir: archive
  login: admin</pre></div></div>



<p>
Now, whenever you wish to update your app, just execute <code>./update.sh</code> instead of <code>./appcfg.py update ./</code>, and the archive of your source will be created and uploaded with your changes. To download, assuming the folder your application is in has the same name as your application, just visit <code>http://yourapp.appspot.com/archive/yourapp.tgz</code> where <code>yourapp</code> is your app's name, and <code>yourapp.tgz</code> is your app folder's name if it's different from your app's name, and you will be prompted to download the archive assuming you're logged in as administrator. That's it!]]></content:encoded>
			<wfw:commentRss>http://www.cneophytou.com/2008/04/17/downloading-your-code-from-google-app-engine/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Hints and code snippets for a more sane OS X Terminal experience</title>
		<link>http://www.cneophytou.com/2006/11/13/hints-and-code-snippets-for-a-more-sane-os-x-terminal-experience/</link>
		<comments>http://www.cneophytou.com/2006/11/13/hints-and-code-snippets-for-a-more-sane-os-x-terminal-experience/#comments</comments>
		<pubDate>Mon, 13 Nov 2006 11:06:56 +0000</pubDate>
		<dc:creator>Constantinos</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[OS X]]></category>
		<category><![CDATA[Hack]]></category>
		<category><![CDATA[Terminal]]></category>
		<category><![CDATA[Unix]]></category>

		<guid isPermaLink="false">http://www.cneophytou.com/2006/11/13/hints-and-code-snippets-for-a-more-sane-os-x-terminal-experience/</guid>
		<description><![CDATA[Pretty long title, huh? Well, I&#8217;ve finally made the decision that there&#8217;s no way I&#8217;ll ever be able to keep a journal. So instead, I&#8217;ll start posting code snippets and general hints that I mostly harvested online (and try to cite wherever I can &#8211; remember that is -), but also modified to suit my [...]]]></description>
			<content:encoded><![CDATA[Pretty long title, huh? Well, I&#8217;ve finally made the decision that there&#8217;s no way I&#8217;ll ever be able to keep a journal. So instead, I&#8217;ll start posting code snippets and general hints that I mostly harvested online (and try to cite wherever I can &#8211; remember that is -), but also modified to suit my purposes&#8230; First up is seamless integration of X11 in OS X with the Terminal application.. Read on for the code<br />
<span id="more-71"></span>
<br />
First off, the reason I got started in this: I HATE xterm. Really dislike it, to the point where I would actively avoid any xwindow apps. That&#8217;s until I came across <a href='http://www.macosxhints.com/article.php?story=2005091004025818&#038;query=x11%2Bterminal'>this hint</a> at <a href='http://www.macosxhints.com'>macosxhints.com</a>. Really nice hint, but to get the best possible approach you have to shift through all the comments, and merge some bash with some csh scripts in order to get the most seamless approach. So this is my solution, for the bash shell, derived from that hint on macosxhints, and explicitly avoiding any modifications of master files (which might get overwritten with an OS X upgrade).<br />
<br />
First step, is to prevent X11 from opening up an xterm window. That&#8217;s fairly easy. Simply create a file called <code>.xinitrc</code> under your home (<code>~/</code>) directory with your favorite editor (like <a href='http://macromates.com/'>TextMate</a> <img src='http://www.cneophytou.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />  ), and paste this code in it (lifted straight off the <a href='http://www.macosxhints.com/article.php?story=2005091004025818&#038;query=x11%2Bterminal'>aforementioned hint</a>):<br />
</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #007800;">PATH</span>=<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>X11R6<span style="color: #000000; font-weight: bold;">/</span>bin:<span style="color: #007800;">$PATH</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># surpress starting of an initial xterm</span>
xterm<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #7a0874; font-weight: bold;">&#123;</span>
    <span style="color: #7a0874; font-weight: bold;">return</span> <span style="color: #000000;">0</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># remember the display name</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$DISPLAY</span>&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #007800;">$HOME</span><span style="color: #000000; font-weight: bold;">/</span>.tmp<span style="color: #000000; font-weight: bold;">/</span>X11-display-<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">hostname</span> -s<span style="color: #000000; font-weight: bold;">`</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># run system-defined xinitrc (doesn't return)</span>
<span style="color: #7a0874; font-weight: bold;">source</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>X11<span style="color: #000000; font-weight: bold;">/</span>xinit<span style="color: #000000; font-weight: bold;">/</span>xinitrc</pre></div></div>




<p>
Now what this does, is redefine the function that calls up the xterm window, and make it do nothing. Then the master file is sourced, so no harm no foul. This modification will survive across upgrades too.<br />
<br />
Now to the more tricky part. In your <code>.bash_profile</code> file, insert this little gem of a code:<br />
</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #000000; font-weight: bold;">!</span><span style="color: #007800;">$DISPLAY</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #000000; font-weight: bold;">!</span><span style="color: #007800;">$SSH_TTY</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #000000; font-weight: bold;">!</span><span style="color: #007800;">$REMOTEHOST</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000; font-weight: bold;">then</span>
    <span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">DISPLAY</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">ps</span> xw <span style="color: #660033;">-o</span> <span style="color: #7a0874; font-weight: bold;">command</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #660033;">-n</span> <span style="color: #ff0000;">'/^\/.*X11.*\:/s/.*:/:/p'</span><span style="color: #000000; font-weight: bold;">`</span>
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$DISPLAY</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000; font-weight: bold;">then</span>
    <span style="color: #000000; font-weight: bold;">if</span> xwininfo <span style="color: #660033;">-display</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$DISPLAY</span>&quot;</span> <span style="color: #660033;">-root</span> <span style="color: #000000; font-weight: bold;">&gt;/</span>dev<span style="color: #000000; font-weight: bold;">/</span>null <span style="color: #000000;">2</span><span style="color: #000000; font-weight: bold;">&gt;&amp;</span><span style="color: #000000;">1</span>
    <span style="color: #000000; font-weight: bold;">then</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> Using X11 display <span style="color: #007800;">$DISPLAY</span>
        <span style="color: #7a0874; font-weight: bold;">export</span> DISPLAY
    <span style="color: #000000; font-weight: bold;">else</span>
        <span style="color: #7a0874; font-weight: bold;">unset</span> DISPLAY
    <span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #000000; font-weight: bold;">fi</span></pre></div></div>



<p>
<br />
This piece of code simply tries to capture the $DISPLAY given by X11, so it can be used in the Terminal. This is usually <code>:0</code>, but not if you&#8217;re running it over ssh. This should catch either.<br />
<br />
So far so good. Whenever I need xwindows, I can start X11, then open a new terminal window and voila. But wait a minute. Why would I have to manually start X11? When that app is idle, it&#8217;s using up almost zero resources. I could very easily place it in my startup items. That&#8217;s a good solution, with the problem being that I rarely need X11, and I don&#8217;t want to have it in my dock all the time.<br />
<br />
This is where the magic happens (btw this same method can be used to hide the dock and menu-bar of pretty much ANY app). Find the X11 app in the finder under <code>/Applications/Utilities/</code>. Ctrl-click on it, and &#8220;Show Package Contents&#8221;. Then navigate to <code>Contents/Info.plist</code>, open it up in the Property List Editor, and add a new sibling under Root called <code>LSUIElement</code>, set it to boolean, and give it the value &#8216;Yes&#8217; (or set it to string and give it the value 1). Save the plist file, and close it.<br />
<br />
Almost there. Now in the terminal, give the command <code>touch /Applications/Utilities/X11.app/</code>, and you&#8217;re all set. Double click on the X11 app to start it, and&#8230; nothing! The only way you can know it&#8217;s running, is if you look for it in the Activity Monitor! This won&#8217;t survive across upgrades of X11, and in fact if X11 gets upgraded you <em>will</em> have to open Activity Monitor to kill it before the upgrade, but I feel it&#8217;s an easy change to make, and a change that&#8217;s almost a second nature to me.<br />
<br />
So that&#8217;s my solution for this. Right now I have X11 running in the background at all times, and terminal simply captures the display and uses it whenever it needs it. And since all the modified files are in the user&#8217;s home directory, this solution will survive across OS upgrades. As a final note, I do have the capture script for tcsh, but it&#8217;s the same as the script listed in a comment of the previously mentioned macosxhints hint, so I won&#8217;t enter it here again. Just look for it there.]]></content:encoded>
			<wfw:commentRss>http://www.cneophytou.com/2006/11/13/hints-and-code-snippets-for-a-more-sane-os-x-terminal-experience/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

