<?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>RedKrieg&#039;s Blog &#187; RedKrieg</title>
	<atom:link href="http://redkrieg.com/author/redkrieg/feed/" rel="self" type="application/rss+xml" />
	<link>http://redkrieg.com</link>
	<description>/dev/random</description>
	<lastBuildDate>Tue, 10 May 2011 06:03:58 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>MySQL Query Parser</title>
		<link>http://redkrieg.com/2011/05/10/mysql-query-parser/</link>
		<comments>http://redkrieg.com/2011/05/10/mysql-query-parser/#comments</comments>
		<pubDate>Tue, 10 May 2011 06:03:58 +0000</pubDate>
		<dc:creator>RedKrieg</dc:creator>
				<category><![CDATA[Python]]></category>
		<category><![CDATA[Sadmin]]></category>

		<guid isPermaLink="false">http://redkrieg.com/?p=180</guid>
		<description><![CDATA[In my day to day activities, I often need to know who&#8217;s being especially bad at MySQL on multi-user systems. Sure, running SHOW PROCESSLIST; a few dozen times might give me an idea, but often you just have to start &#8230; <a href="http://redkrieg.com/2011/05/10/mysql-query-parser/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>In my day to day activities, I often need to know who&#8217;s being especially bad at MySQL on multi-user systems.  Sure, running SHOW PROCESSLIST; a few dozen times might give me an idea, but often you just have to start logging and hope for the best.</p>
<p>NO MORE I SAY!</p>
<p>I built a very basic MySQL query parser in Python that takes a MySQL 5.0/5.1 log file (any size, it&#8217;s rather memory efficient) and returns the total number of SELECT, UPDATE, and INSERT queries, tallies their Queries Per Second, and sorts by selects to give a final output of just who&#8217;s been bad and in what way.</p>
<p>I&#8217;ll let the help output do the talking:</p>
<p><code>redkrieg@h4xs3rv3r [~]$ queryparser.py --help<br />
usage: queryparser.py [options] [filename]</code></p>
<p><code> </code></p>
<p><code>[filename] is optional and defaults to stdin.</code></p>
<p><code> </code></p>
<p>&nbsp;</p>
<p><code>options:<br />
-h, --help            show this help message and exit<br />
-v, --verbose         Print info on stderr (default: True)<br />
-q, --quiet           Suppress stderr output<br />
-o FILE, --output=FILE<br />
Write output to FILE (default: stdout)<br />
-r REGEX, --regex=REGEX<br />
Tally arbitrary REGEX string (slow)</code></p>
<p>Supports arbitrary regex searches and takes a best-guess approach to identifying the appropriate user when it&#8217;s not obvious.  Without the regex option, it can chew through a 1GB log in about 30 seconds on my VPS while staying in a single execution thread.</p>
<p>Download the latest version <a href="http://scripts.rkutil.us/queryparser.py">here</a></p>
]]></content:encoded>
			<wfw:commentRss>http://redkrieg.com/2011/05/10/mysql-query-parser/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Adding notifications to finch</title>
		<link>http://redkrieg.com/2011/03/14/adding-notifications-to-finch/</link>
		<comments>http://redkrieg.com/2011/03/14/adding-notifications-to-finch/#comments</comments>
		<pubDate>Tue, 15 Mar 2011 00:16:05 +0000</pubDate>
		<dc:creator>RedKrieg</dc:creator>
				<category><![CDATA[Ubuntu]]></category>

		<guid isPermaLink="false">http://redkrieg.com/?p=172</guid>
		<description><![CDATA[So, we use XMPP for our internal chat system at work, but I hate pidgin and empathy&#8217;s not much better. Naturally I searched for command line alternatives and the least offensive one I could find was finch, which admittedly uses &#8230; <a href="http://redkrieg.com/2011/03/14/adding-notifications-to-finch/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>So, we use XMPP for our internal chat system at work, but I hate pidgin and empathy&#8217;s not much better.  Naturally I searched for command line alternatives and the least offensive one I could find was finch, which admittedly uses libpurple on the backend, so it&#8217;s really pidgin, but at least it&#8217;s in a terminal now.  Of course, I lost all my notifications of incoming messages, which isn&#8217;t cool, so I cooked up a simple script and call it instead of playing sound through finch.  In finch&#8217;s &#8220;sounds&#8221; menu, simply change &#8220;Automatic&#8221; to &#8220;command&#8221;.  In ubuntu, you&#8217;ll need two new packages:</p>
<p>sudo aptitude install libnotify-bin mplayer</p>
<p>And you&#8217;ll need this script, and to remember the path to it:</p>
<pre>
#!/bin/bash

latest_line=`find ~/.purple/logs/jabber/ -mtime -1 -printf "%T@ %Tx %TX %p\n" | sort -n -r | head | cut -d ' ' -f 2- | awk '{print $NF}' | head -1 | xargs tail -1 | sed -e 's#<[^>]*>##g'`
mplayer $1 >/dev/null 2>&#038;1 &#038;
notify-send "`echo $latest_line | cut -d ':' -f 3 | awk -F ')' '{print $2}'`" "`echo $latest_line | cut -d ':' -f 4-`"
</pre>
]]></content:encoded>
			<wfw:commentRss>http://redkrieg.com/2011/03/14/adding-notifications-to-finch/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Pianobar &#8211; An open source Pandora client</title>
		<link>http://redkrieg.com/2011/01/02/pianobar-an-open-source-pandora-client/</link>
		<comments>http://redkrieg.com/2011/01/02/pianobar-an-open-source-pandora-client/#comments</comments>
		<pubDate>Sun, 02 Jan 2011 15:31:38 +0000</pubDate>
		<dc:creator>RedKrieg</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Ubuntu]]></category>

		<guid isPermaLink="false">http://redkrieg.com/?p=169</guid>
		<description><![CDATA[I&#8217;ve been using pianobar for about two weeks now and have yet to experience any crashes that plagued my usage previously. It is by far the most efficient, stable way to use Pandora. In Ubuntu, you can install it from &#8230; <a href="http://redkrieg.com/2011/01/02/pianobar-an-open-source-pandora-client/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been using <a href="https://github.com/PromyLOPh/pianobar">pianobar</a> for about two weeks now and have yet to experience any crashes that plagued my usage previously.  It is by far the most efficient, stable way to use <a href="http://pandora.com">Pandora</a>.  In Ubuntu, you can install it from the software center or via <a href="apt:pianobar">&#8220;apt-get install pianobar&#8221;</a>.  I also recommend installing <a href="apt:libnotify-bin">libnotify-bin</a> if you want to use notifications on song changes (instructions below).</p>
<p>Once installed, you can either run it straight away by opening a terminal and typing &#8220;pianobar&#8221;, or you can set up some configurations first to enhance your experience.  I use a shell script to catch events from the player and display notifications with the song artist and title.</p>
<p>For configuration, edit ~/.config/pianobar/config in your favorite editor.  Here is my configuration (note that I pay for Pandora One, if you do not, you can&#8217;t specify mp3-hifi as your audio_format):<br />
<code><br />
event_command = /home/myuser/bin/pianobar-notify<br />
user = user@domain.com<br />
password = yourpassword<br />
audio_format = mp3-hifi<br />
</code></p>
<p>The script at /home/myuser/bin/pianobar-notify will be called any time an &#8220;event&#8221; is sent.  See the man page for details on how you can extend this.  Below is the pianobar-notify script I use (don&#8217;t forget to chmod +x):<br />
<code><br />
#!/bin/bash<br />
# create variables<br />
while read L; do<br />
        k="`echo "$L" | cut -d '=' -f 1`"<br />
        v="`echo "$L" | cut -d '=' -f 2`"<br />
        export "$k=$v"<br />
done < <(grep -e '^\(title\|artist\|album\|stationName\|pRet\|pRetStr\|wRet\|wRetStr\|songDuration\|songPlayed\|rating\|coverArt\)=' /dev/stdin) # don't overwrite $1...</p>
<p>case "$1" in<br />
        songstart)<br />
#               echo 'naughty.notify({title = "pianobar", text = "Now playing: ' "$title" ' by ' "$artist" '"})' | awesome-client -<br />
#               echo "$title -- $artist" > $HOME/.config/pianobar/nowplaying<br />
#               # or whatever you like...<br />
                notify-send "Pianobar - $stationName" "Now Playing: $artist - $title"<br />
                ;;</p>
<p>#       songfinish)<br />
#               # scrobble if 75% of song have been played, but only if the song hasn't<br />
#               # been banned<br />
#               if [ -n "$songDuration" ] &#038;&#038;<br />
#                               [ $(echo "scale=4; ($songPlayed/$songDuration*100)>50" | bc) -eq 1 ] &#038;&#038;<br />
#                               [ "$rating" -ne 2 ]; then<br />
#                       # scrobbler-helper is part of the Audio::Scrobble package at cpan<br />
#                       # "pia" is the last.fm client identifier of "pianobar", don't use<br />
#                       # it for anything else, please<br />
#                       scrobbler-helper -P pia -V 1.0 "$title" "$artist" "$album" "" "" "" "$((songDuration/1000))" &#038;<br />
#               fi<br />
#               ;;</p>
<p>        *)<br />
                if [ "$pRet" -ne 1 ]; then<br />
                        notify-send "Pianobar - ERROR" "$1 failed: $pRetStr"<br />
                elif [ "$wRet" -ne 1 ]; then<br />
                        notify-send "Pianobar - ERROR" "$1 failed: $wRetStr"<br />
                fi<br />
                ;;<br />
esac<br />
</code></p>
<p>Have fun enjoying your music without a web browser!</p>
]]></content:encoded>
			<wfw:commentRss>http://redkrieg.com/2011/01/02/pianobar-an-open-source-pandora-client/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Deep Fried Philly Steak</title>
		<link>http://redkrieg.com/2010/11/27/deep-fried-philly-steak/</link>
		<comments>http://redkrieg.com/2010/11/27/deep-fried-philly-steak/#comments</comments>
		<pubDate>Sun, 28 Nov 2010 02:37:12 +0000</pubDate>
		<dc:creator>RedKrieg</dc:creator>
				<category><![CDATA[Fun]]></category>

		<guid isPermaLink="false">http://redkrieg.com/?p=159</guid>
		<description><![CDATA[In a stroke of pure genius this weekend, my brother created the Deep Fried Philly Steak. For the benefit of mankind, I shall hereby document the process: Use a frying pan with a touch of olive oil to sautee some &#8230; <a href="http://redkrieg.com/2010/11/27/deep-fried-philly-steak/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>In a stroke of pure genius this weekend, my brother created the Deep Fried Philly Steak.  For the benefit of mankind, I shall hereby document the process:</p>
<p>Use a frying pan with a touch of olive oil to sautee some vegetables.  We used onion, green pepper, mushrooms, and minced garlic, like these:<br />
<div id="attachment_162" class="wp-caption alignnone" style="width: 310px"><a href="http://redkrieg.com/wp-content/uploads/2010/11/2010-11-27-13.45.16.jpg"><img src="http://redkrieg.com/wp-content/uploads/2010/11/2010-11-27-13.45.16-300x225.jpg" alt="" title="Veggies and cheese" width="300" height="225" class="size-medium wp-image-162" /></a><p class="wp-caption-text">They might not look so great raw, but fry these bad boys up...</p></div></p>
<p>When the vegetables are sauteed to perfection, add sliced beef.  We used steak-ums, but I imagine this would be better with something fresher.  Fry &#8217;til the beef is done, then add some cheese blend.  It&#8217;ll look something like this, but more:<br />
<div id="attachment_160" class="wp-caption alignnone" style="width: 310px"><a href="http://redkrieg.com/wp-content/uploads/2010/11/2010-11-27-13.45.12.jpg"><img src="http://redkrieg.com/wp-content/uploads/2010/11/2010-11-27-13.45.12-300x225.jpg" alt="" title="Beef, or what&#039;s left of it" width="300" height="225" class="size-medium wp-image-160" /></a><p class="wp-caption-text">Delicious meat...  and fat</p></div></p>
<p>Next, roll out some roll-up pizza dough, we used the <a href="http://www.pillsbury.com/products/pizza-crust">Pillsbury Classic Pizza Crust</a> for ours.  Place six slices of provolone on the rolled-out pizza crust and cut in to six squares.  Place a ball of your fried treat on each of the slices of provolone:<br />
<div id="attachment_163" class="wp-caption alignnone" style="width: 310px"><a href="http://redkrieg.com/wp-content/uploads/2010/11/2010-11-27-13.45.20.jpg"><img src="http://redkrieg.com/wp-content/uploads/2010/11/2010-11-27-13.45.20-300x225.jpg" alt="" title="Nearly there..." width="300" height="225" class="size-medium wp-image-163" /></a><p class="wp-caption-text">This is what you're looking for.</p></div></p>
<p>Finally, you can top with some mayo if you truly hate your vascular system:<br />
<div id="attachment_164" class="wp-caption alignnone" style="width: 310px"><a href="http://redkrieg.com/wp-content/uploads/2010/11/2010-11-27-13.45.24.jpg"><img src="http://redkrieg.com/wp-content/uploads/2010/11/2010-11-27-13.45.24-300x225.jpg" alt="" title="My arteries!" width="300" height="225" class="size-medium wp-image-164" /></a><p class="wp-caption-text">It's a heart attack in the making.</p></div></p>
<p>Pull the four corners up to meet in the center so you have four points sticking out, then grab these and fold them up as well.  Make sure there aren&#8217;t any gaps through which you can see steak, you should have a ball of stretched dough with no holes.  Drop this in to the deep fryer, which you should have pre-heated to 375 degrees Farenheit filled with vegetable oil (or lard I guess, but I wanted to be alive to write this).<br />
<div id="attachment_165" class="wp-caption alignnone" style="width: 310px"><a href="http://redkrieg.com/wp-content/uploads/2010/11/2010-11-27-13.45.33.jpg"><img src="http://redkrieg.com/wp-content/uploads/2010/11/2010-11-27-13.45.33-300x225.jpg" alt="" title="Floating already" width="300" height="225" class="size-medium wp-image-165" /></a><p class="wp-caption-text">You can tell it's done when it floats, but I let it go 'til it's good and brown</p></div></p>
<p>When it&#8217;s done (golden brown and floating, you may need to turn them to get an even fry) pull them out and place them on some paper towels to soak up some of the liquid death in which they sit.  You now have the most amazing treat ever created.  Enjoy.<br />
<div id="attachment_166" class="wp-caption alignnone" style="width: 310px"><a href="http://redkrieg.com/wp-content/uploads/2010/11/2010-11-27-13.45.37.jpg"><img src="http://redkrieg.com/wp-content/uploads/2010/11/2010-11-27-13.45.37-300x225.jpg" alt="" title="Balls... of steak!" width="300" height="225" class="size-medium wp-image-166" /></a><p class="wp-caption-text">Philly steak, in convenient ball form.</p></div></p>
]]></content:encoded>
			<wfw:commentRss>http://redkrieg.com/2010/11/27/deep-fried-philly-steak/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Compiling heimdall on Ubuntu 10.10</title>
		<link>http://redkrieg.com/2010/11/23/compiling-heimdall-on-ubuntu-10-10/</link>
		<comments>http://redkrieg.com/2010/11/23/compiling-heimdall-on-ubuntu-10-10/#comments</comments>
		<pubDate>Tue, 23 Nov 2010 23:48:53 +0000</pubDate>
		<dc:creator>RedKrieg</dc:creator>
				<category><![CDATA[Android]]></category>
		<category><![CDATA[Ubuntu]]></category>

		<guid isPermaLink="false">http://redkrieg.com/?p=156</guid>
		<description><![CDATA[Heimdall is an open source replacement for the Samsung Galaxy S flashing utility called Odin. I like this because I can&#8217;t stand windows, so if I were to have &#8220;bricked&#8221; my Vibrant, I&#8217;d have been pretty well screwed until I &#8230; <a href="http://redkrieg.com/2010/11/23/compiling-heimdall-on-ubuntu-10-10/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Heimdall is an open source replacement for the Samsung Galaxy S flashing utility called Odin.  I like this because I can&#8217;t stand windows, so if I were to have &#8220;bricked&#8221; my Vibrant, I&#8217;d have been pretty well screwed until I found a friend with a windows machine.  Now, there&#8217;s an option for us &#8220;regular&#8221; folks that don&#8217;t like to pay the microsoft tax just to use our hardware.</p>
<p>First things first, you&#8217;ll need some development packages, so run this command from the terminal:<br />
<code>sudo aptitude install build-essential libusb-1.0-0-dev</code></p>
<p>Next, you&#8217;ll need the hiemdall source from <a href="http://www.glassechidna.com.au/products/heimdall/">here</a>.  You&#8217;ll want to get the linux source archive.</p>
<p>Now unzip the source to a folder in your home directory, I use ~/source/.  There should now be a folder called &#8220;Heimdall-Source&#8221;.</p>
<p>Change directories to Heimdall-Source and run the following commands:<br />
<code>./configure<br />
make<br />
sudo make install</code></p>
<p>You now have heimdall installed.  The README file in the Heimdall-Source folder has information on use of the tool, but the important things to know are that you must run it with sudo, you&#8217;ll need to untar any .tar or .tar.md5 files you have in the odin bundle (tar xvf filename.tar), and include only the parameters from the source that match files you actually have in your odin tarball (if there&#8217;s no Spl.bin in your tarball, don&#8217;t include the &#8220;&#8211;secondary Sbl.bin&#8221; part of the heimdall command).  If your odin bundle contains all of the files heimdall can use, your command would look like this:<br />
<code>sudo heimdall flash --pit s1_odin_20100512.pit --factoryfs factoryfs.rfs --cache cache.rfs --dbdata dbdata.rfs --boot boot.bin --secondary Sbl.bin --param param.lfs --kernel zImage --modem modem.bin</code></p>
]]></content:encoded>
			<wfw:commentRss>http://redkrieg.com/2010/11/23/compiling-heimdall-on-ubuntu-10-10/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Minimalist fcgid with custom php.ini on cPanel</title>
		<link>http://redkrieg.com/2010/11/19/minimalist-fcgid-with-custom-php-ini-on-cpanel/</link>
		<comments>http://redkrieg.com/2010/11/19/minimalist-fcgid-with-custom-php-ini-on-cpanel/#comments</comments>
		<pubDate>Sat, 20 Nov 2010 00:32:23 +0000</pubDate>
		<dc:creator>RedKrieg</dc:creator>
				<category><![CDATA[cPanel]]></category>
		<category><![CDATA[Work]]></category>

		<guid isPermaLink="false">http://redkrieg.com/?p=146</guid>
		<description><![CDATA[I was able to replicate the functionality I enjoyed from SuPHP (per directory php.ini configurations) with a simple wrapper script that's called using an "Action" parameter in the .htaccess file. <a href="http://redkrieg.com/2010/11/19/minimalist-fcgid-with-custom-php-ini-on-cpanel/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I recently changed to using fastcgi on my personal cPanel server (11.28, CentOS) and thought others might benefit from my findings, as I wasn&#8217;t able to find any complete configuration tutorials.</p>
<p>I was able to replicate the functionality I enjoyed from SuPHP (per directory php.ini configurations) with a simple wrapper script that&#8217;s called using an &#8220;Action&#8221; parameter in the .htaccess file.</p>
<p>To start, you&#8217;ll need to run EasyApache:<br />
<code>/scripts/easyapache</code><br />
I have disabled &#8220;Mod SuPHP&#8221; from the easyapache configuration and enabled &#8220;Mod FCGID&#8221;.  This was the only change required to enable FastCGI support using the system php.ini configuration.</p>
<p>I reviewed many forum posts on the topic of local php.ini configuration with fcgid, but none really focused on the per-user aspect and how it can be user definable.  I accomplished this with a very simple wrapper script for php-cgi that sets the PHPRC shell variable to the desired path, then a handler and action in .htaccess to call the script for handling php files.  This allows for different directories to use different php.ini configurations by creating a different wrapper for each php.ini required.</p>
<p>First, edit the wrapper with your favorite text editor:<br />
<code>nano -w ~/public_html/php5.fcgi</code><br />
Note, the name is arbitrary, but it needs to be in cgi-bin.  Add the following code:<br />
<code>#!/bin/sh<br />
PHPRC=~/public_html/<br />
export PHPRC<br />
exec /usr/local/cpanel/cgi-sys/php5<br />
</code><br />
Then save, and make it executable:<br />
<code>chmod 755 ~/public_html/php5.fcgi</code></p>
<p>Next, you need to associate it with .php (and any other you&#8217;d like) extensions.  Add these two lines to ~/public_html/.htaccess (or any .htaccess file)<br />
<code>AddHandler php5-fastcgi .php<br />
Action php5-fastcgi /cgi-bin/php5.fcgi</code></p>
<p>You can add additional extensions to the AddHandler line like so:<br />
<code>AddHandler php5-fastcgi .php .phtml .html</code></p>
<blockquote><p>Update: The above instructions will break subdomains and addon domains if a separate php5.fcgi is not placed in each sub/addon cgi-bin folder.  To combat this, I&#8217;m using a system accessible php5.fcgi that sets PHPRC to ~/public_html/.  To do the same:<br />
<code>nano -w /usr/local/cpanel/cgi-sys/php5.fcgi</code><br />
Then add this code:<br />
<code>#!/bin/sh<br />
PHPRC=~/public_html/<br />
export PHPRC<br />
exec /usr/local/cpanel/cgi-sys/php5</code><br />
Set permissions correctly:<br />
<code>chown root:wheel /usr/local/cpanel/cgi-sys/php5.fcgi<br />
chmod 755 /usr/local/cpanel/cgi-sys/php5.fcgi</code><br />
Finally, change .htaccess to use the new path:<br />
<code>AddHandler php5-fastcgi .php<br />
Action php5-fastcgi /cgi-sys/php5.fcgi</code></p></blockquote>
<p>That&#8217;s it.  It&#8217;s generic, can be copied to any user account without modification, and uses system configs for fcgid options, so it can use sane defaults.</p>
<p>I&#8217;ve uploaded my cpanel3-skel folder with perms set in case you would like to use it on your server.  <a title="Skel folder download" href="http://redkrieg.com/wp-content/uploads/2010/11/skel.tar.gz">Click here</a>.</p>
<p>Update:<br />
Helius reports in the comments that the steps above can break Fantastico on the server.  To correct this, you&#8217;ll need to build cPanel&#8217;s PHP:<br />
<code>/scripts/makecpphp</code><br />
Thanks for the info Helius!</p>
]]></content:encoded>
			<wfw:commentRss>http://redkrieg.com/2010/11/19/minimalist-fcgid-with-custom-php-ini-on-cpanel/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>ADB over SSH &#8211; Fun with port forwards</title>
		<link>http://redkrieg.com/2010/10/11/adb-over-ssh-fun-with-port-forwards/</link>
		<comments>http://redkrieg.com/2010/10/11/adb-over-ssh-fun-with-port-forwards/#comments</comments>
		<pubDate>Mon, 11 Oct 2010 17:25:25 +0000</pubDate>
		<dc:creator>RedKrieg</dc:creator>
				<category><![CDATA[Tutorials]]></category>

		<guid isPermaLink="false">http://redkrieg.com/?p=133</guid>
		<description><![CDATA[So last week one of my coworkers and I were discussing a VPN configuration to allow adb shells over 3G. Just tonight I realized that a VPN isn&#8217;t even required, SSH can do the same job with relatively little effort. &#8230; <a href="http://redkrieg.com/2010/10/11/adb-over-ssh-fun-with-port-forwards/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>So last week one of my coworkers and I were discussing a VPN configuration to allow adb shells over 3G.  Just tonight I realized that a VPN isn&#8217;t even required, SSH can do the same job with relatively little effort.  Here&#8217;s how I rigged my setup.</p>
<p><strong>Prerequisites:</strong></p>
<ul>
<li>A functional SSH server, accessible from outside your network.</li>
<li><a href="http://code.google.com/p/connectbot/">Connectbot</a> on your phone with a connection configured for your home computer.</li>
<li>A functional ADB over USB install with correct PATH variables set.  When you open a new command prompt and type &#8220;adb shell&#8221; you should see a prompt from your phone.</li>
</ul>
<p>Configuration of the above items are well documented elsewhere and will be outside the scope of this article.</p>
<p>So, having the prerequisites in order, you start by modifying your Connectbot connection as follows:</p>
<ul>
<li>Long-press your connection in the list and choose &#8220;Edit host&#8221;.</li>
<li>Press &#8220;Post-login automation&#8221;.</li>
<li>In the box type &#8220;adb connect localhost:5555[ENTER]&#8221; the new line here ([ENTER] key) is necessary to automatically run the command.</li>
<li>Press &#8220;OK&#8221;.</li>
<li>Press back to return to the connection list.</li>
<li>Long-press your connection in the list and choose &#8220;Edit port forwards&#8221;.</li>
<li>Press Menu, then &#8220;Add port forward&#8221; and enter the following:</li>
<ul>
<li>Nickname: &#8220;ADB&#8221;.</li>
<li>Type: &#8220;Remote&#8221;.</li>
<li>Source port: &#8220;5555&#8243;</li>
<li>Destination: &#8220;localhost:5555&#8243;</li>
</ul>
<li>Press &#8220;Create port forward&#8221;.</li>
</ul>
<p>Your connection is now configured to tunnel the ADB protocol over port 5555 from your computer to the phone via reverse SSH tunnelling.  The next step is to configure ADB on the phone to listen over tcp/ip:</p>
<ul>
<li>On your computer, with the phone connected via USB, type &#8220;adb tcpip 5555&#8243;.</li>
</ul>
<p>That&#8217;s it!  You can now disconnect your USB cable, take your phone on a car ride, etc.  If you need to use adb with it, simply use Connectbot to connect to your home computer, after the connection is authenticated (you can use password or public-key) the adb connection will be made automatically, so you simply have to use adb as you normally would!</p>
<p>Remember that over 3G you&#8217;re going to have some delay for commands, here&#8217;s an example push:</p>
<p><code><br />
redkrieg@h4xt0p:~$ time adb push Downloads/UniversalAndroot-1.6.2-beta5.apk /sdcard/<br />
11 KB/s (964401 bytes in 83.041s)<br />
redkrieg@h4xt0p:~$ ls -hal Downloads/UniversalAndroot-1.6.2-beta5.apk<br />
-rw-r--r-- 1 redkrieg redkrieg 942K 2010-10-08 15:08 Downloads/UniversalAndroot-1.6.2-beta5.apk<br />
redkrieg@h4xt0p:~$<br />
</code></p>
<p>So yeah, it&#8217;s slow as dirt, but I totally pushed a file from my home computer to my phone from across the city.</p>
<p>To undo this and restore normal USB ADB functionality, you must first connect with Connectbot using the instructions above, then from your computer run &#8220;adb usb&#8221; to return the phone to USB mode.  If you&#8217;re unable to do this, you&#8217;ll need to run the following from a local shell on the phone:</p>
<p><code><br />
su<br />
setprop service.adb.tcp.port -1<br />
stop adbd<br />
start adbd<br />
</code></p>
<p>That&#8217;s it.  Have fun!</p>
<p>Update: I&#8217;ve just thought things through and realized that this leaves root wide open to remote exploit if someone knows your IP.  Probably best to switch back to USB adb once you&#8217;re done until I figure out a good way to block non-localhost connections to 5555 in iptables on boot.  If you know how to do this, please post a comment, otherwise it&#8217;ll be my project for the night.</p>
<p>Update 2:<br />
After some testing, it seems like T-mo blocks inbound connections like this, so iptables shouldn&#8217;t be necessary. That being said, the following rules should take care of any lingering doubt:</p>
<p><code><br />
iptables -A INPUT -p tcp --dport 5555 -s 127.0.0.1 -j ACCEPT<br />
iptables -A INPUT -p tcp --dport 5555 -j DROP<br />
</code></p>
]]></content:encoded>
			<wfw:commentRss>http://redkrieg.com/2010/10/11/adb-over-ssh-fun-with-port-forwards/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Gravity part deux.</title>
		<link>http://redkrieg.com/2009/11/30/gravity-part-deux/</link>
		<comments>http://redkrieg.com/2009/11/30/gravity-part-deux/#comments</comments>
		<pubDate>Tue, 01 Dec 2009 01:47:23 +0000</pubDate>
		<dc:creator>RedKrieg</dc:creator>
				<category><![CDATA[Art & Design]]></category>
		<category><![CDATA[Fun]]></category>

		<guid isPermaLink="false">http://redkrieg.com/?p=122</guid>
		<description><![CDATA[So I&#8217;ve been playing around in Python lately, primarily because I&#8217;ve been teaching it to a kid I&#8217;ve been tutoring. I decided to take the opportunity to port my old C# based gravity simulation to see how hard it would &#8230; <a href="http://redkrieg.com/2009/11/30/gravity-part-deux/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>So I&#8217;ve been playing around in Python lately, primarily because I&#8217;ve been teaching it to a kid I&#8217;ve been tutoring. I decided to take the opportunity to port my old C# based gravity simulation to see how hard it would be to implement. I chose to use <a title="PyGame library" href="http://www.pygame.org/" target="_blank">pygame</a> because it provides the screen update engine and drawing routines out of the box with an easy way to tell how many milliseconds have passed since the last frame update (required for accurate physics). I haven&#8217;t really made any tweaks to the physics engine since the <a title="My old gravity program" href="http://redkrieg.com/2008/10/01/wheeeeeeeee-gravity1eleven/" target="_blank">mono version</a>, but it&#8217;s still pretty cool to watch. One thing I did add to this is a 2&#215;2 box with alpha 10 that simulates a pencil running over paper wherever a ball passes. I liked the visualization so much, I left it turned on in the version I hereby bequeath to you, dear internet. Below are two of the generated images, the lighter the color of the line, the faster the ball was moving at the time.</p>
<div id="attachment_123" class="wp-caption alignnone" style="width: 810px"><a href="http://redkrieg.com/wp-content/uploads/2009/11/20091130201454.png"><img class="size-full wp-image-123" title="Image one" src="http://redkrieg.com/wp-content/uploads/2009/11/20091130201454.png" alt="First image from my gravity simulator" width="800" height="600" /></a><p class="wp-caption-text">First image from my gravity simulator</p></div>
<div id="attachment_124" class="wp-caption alignnone" style="width: 810px"><a href="http://redkrieg.com/wp-content/uploads/2009/11/20091130201614.png"><img class="size-full wp-image-124" title="Image two" src="http://redkrieg.com/wp-content/uploads/2009/11/20091130201614.png" alt="Second image from my gravity simulator" width="800" height="600" /></a><p class="wp-caption-text">Second image from my gravity simulator</p></div>
<p>Oh, I suppose you&#8217;d like to download the current version. It&#8217;s sloppy, but you&#8217;re welcome to it! Some code borrowed from the python/pygame tutorials, but the physics are all mine.</p>
<p>Download it <a title="Download my gravity simulator" href="http://dl.dropbox.com/u/186933/gravity.tar.gz" target="_self">here</a>.</p>
<p>Update: Almost forgot!!! Left click adds an additional ball, right click saves a screenshot and clears the background.</p>
<p>Update 2:</p>
<div id="attachment_128" class="wp-caption alignnone" style="width: 160px"><a href="http://redkrieg.com/wp-content/uploads/2009/11/20091130210623.jpg"><img class="size-thumbnail wp-image-128" title="Third image" src="http://redkrieg.com/wp-content/uploads/2009/11/20091130210623-150x150.jpg" alt="This one was after about 30 minutes with 6 balls" width="150" height="150" /></a><p class="wp-caption-text">This one was after about 30 minutes with 6 balls</p></div>
<p>Just another image, click to enlarge.</p>
<p>Update 4: Put a video up on YouTube showing what it looks like while running: <a title="Video of gravity simulator" href="http://www.youtube.com/watch?v=OOBBPtsu5MM" target="_blank">http://www.youtube.com/watch?v=OOBBPtsu5MM</a></p>
]]></content:encoded>
			<wfw:commentRss>http://redkrieg.com/2009/11/30/gravity-part-deux/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Wheeeeeeeee Gravity!1!!eleven!</title>
		<link>http://redkrieg.com/2008/10/01/wheeeeeeeee-gravity1eleven/</link>
		<comments>http://redkrieg.com/2008/10/01/wheeeeeeeee-gravity1eleven/#comments</comments>
		<pubDate>Thu, 02 Oct 2008 04:22:34 +0000</pubDate>
		<dc:creator>RedKrieg</dc:creator>
				<category><![CDATA[Fun]]></category>
		<category><![CDATA[Ubuntu]]></category>

		<guid isPermaLink="false">http://redkrieg.com/2008/10/01/wheeeeeeeee-gravity1eleven/</guid>
		<description><![CDATA[Sooooo&#8230;. a few days ago I felt like simulating a bit of gravity. Turns out that was the easy part&#8230; Basically I wrote a gravity simulator with accurate(?) collision detection all based on force vectors applied over time. I did &#8230; <a href="http://redkrieg.com/2008/10/01/wheeeeeeeee-gravity1eleven/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Sooooo&#8230;.  a few days ago I felt like simulating a bit of gravity.  Turns out that was the easy part&#8230;  Basically I wrote a gravity simulator with accurate(?) collision detection all based on force vectors applied over time.  I did all the physics and trig work from the top of my head, and the last time I had a physics or trig class was eight years ago, so I might have forgotten something important.  Collisions look right to me right now, but the code driving them relies on some pretty loose interpretations of gravity/time, so any frameskips could cause some rather interesting reflections.  <a href="http://dl.getdropbox.com/u/186933/gravity-0.1.tar.gz">Tarball (with source)</a> and <a href="http://dl.getdropbox.com/u/186933/gravity_0.1-1_i386.deb">Ubuntu deb package (binary only)</a> at their respective links.</p>
<p>I made a half-assed attempt at commenting the source, because I&#8217;m a nice guy.  You should be able to get an idea of what I was thinking from there.</p>
<p>Update [20081002003930EDT]: Almost forgot, uses Cairo for drawing.  XOrg process maxes the cpu at the resolution I&#8217;m using for this thing&#8230;  NO idea why.  Any programmers wanna help?</p>
]]></content:encoded>
			<wfw:commentRss>http://redkrieg.com/2008/10/01/wheeeeeeeee-gravity1eleven/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Nag&#8217;s Head in 24 hours.</title>
		<link>http://redkrieg.com/2008/08/10/nags-head-in-24-hours/</link>
		<comments>http://redkrieg.com/2008/08/10/nags-head-in-24-hours/#comments</comments>
		<pubDate>Sun, 10 Aug 2008 09:03:49 +0000</pubDate>
		<dc:creator>RedKrieg</dc:creator>
				<category><![CDATA[Me]]></category>

		<guid isPermaLink="false">http://redkrieg.com/2008/08/10/nags-head-in-24-hours/</guid>
		<description><![CDATA[I&#8217;ve been in Nag&#8217;s Head for just a bit over 24 hours now and thus far it&#8217;s been the best Nag&#8217;s Head trip yet. Lets start at the beginning&#8230; Deer in a bag. Fucking deer in its fucking bag made &#8230; <a href="http://redkrieg.com/2008/08/10/nags-head-in-24-hours/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been in Nag&#8217;s Head for just a bit over 24 hours now and thus far it&#8217;s been the best Nag&#8217;s Head trip yet. Lets start at the beginning&#8230; Deer in a bag. Fucking deer in its fucking bag made me have to do a pirouette in my fucking car on the driver&#8217;s side tire, then some kind of double hamstring somersault backflip and ended up in the next lane over doing the speed limit. Totally sweet dude. Once we got here shit got real and we got as obliterated as possible for maximum debauchery. There was some crazy girl, but that problem was solved in short order. Today there was a liberal smattering of rock band, outlet mallification, and beachgoing X 2. The first beach trip (among the day walkers) was pretty much a bust, there being a distinct shortage of surfable waves, however the second trip made tonight worthwhile. I got to the beach around 3 am and immediately noticed that I was surrounded by phytoplankton. Every movement, no matter how deep under water, caused a flurry of tiny green luminescent organisms to fire their biochemical caches and illuminate the immediate area, giving a net effect of glowing water. My friend Scott happened to bring a boogie board and was floating, so I became one with the ocean and learned to float too. After a liberal period of stargazing, I began to pay attention to the ocean&#8217;s warm embrace and happened to notice a clicking sound underwater. It was probably a good minute before I realized that the rhythmic clicking I was being subjected to wasn&#8217;t one of my friends, but was in point of fact dolphins. I was hearing dolphins talk to each other. I know this description doesn&#8217;t really convey the beauty I experienced today, but I wanted to record it regardless. Fuck you.</p>
]]></content:encoded>
			<wfw:commentRss>http://redkrieg.com/2008/08/10/nags-head-in-24-hours/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Served from: redkrieg.com @ 2012-05-20 15:39:23 by W3 Total Cache -->
