<?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>Blog.Project13.pl &#187; terminal heroes</title>
	<atom:link href="http://www.blog.project13.pl/index.php/category/terminal-heroes/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.blog.project13.pl</link>
	<description>The Blog of a Coder</description>
	<lastBuildDate>Sun, 05 Feb 2012 02:28:52 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Keeping processes alive using God&#8217;s power</title>
		<link>http://www.blog.project13.pl/index.php/coding/1338/keeping-processes-alive-using-gods-power/</link>
		<comments>http://www.blog.project13.pl/index.php/coding/1338/keeping-processes-alive-using-gods-power/#comments</comments>
		<pubDate>Thu, 04 Aug 2011 17:48:21 +0000</pubDate>
		<dc:creator>Ktoso</dc:creator>
				<category><![CDATA[coding]]></category>
		<category><![CDATA[english]]></category>
		<category><![CDATA[guide]]></category>
		<category><![CDATA[terminal heroes]]></category>
		<category><![CDATA[admin]]></category>
		<category><![CDATA[centos]]></category>
		<category><![CDATA[devops]]></category>
		<category><![CDATA[fedora]]></category>
		<category><![CDATA[god]]></category>
		<category><![CDATA[keep alive]]></category>
		<category><![CDATA[process watch]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://www.blog.project13.pl/?p=1338</guid>
		<description><![CDATA[God is a nice &#8220;framework&#8221; and daemon to watch Linux processes and restart them if necessary. As I&#8217;ve configured it today to work on an ubuntu machine here&#8217;s a quick howto: First install ruby, gem and god. apt-get install ruby, rubygems gem install god Then paste this initscript into /etc/init.d/god: got init script. Configure it [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://god.rubyforge.org/" onclick="urchinTracker('/outgoing/god.rubyforge.org/?referer=');"><strong>God</strong></a> is a nice &#8220;framework&#8221; and daemon to watch Linux processes and restart them if necessary. As I&#8217;ve configured it today to work on an ubuntu machine here&#8217;s a quick howto:</p>
<p>First install ruby, gem and god.</p>
<pre>
apt-get install ruby, rubygems
gem install god
</pre>
<p>Then paste this initscript into <strong>/etc/init.d/god</strong>: <a href="http://openmonkey.com/2008/05/27/god-init-script-for-debian-ubuntu-systems/" onclick="urchinTracker('/outgoing/openmonkey.com/2008/05/27/god-init-script-for-debian-ubuntu-systems/?referer=');">got init script</a>. Configure it to use <strong>/etc/god/config.rb</strong> for example, and there do some minor setup (using ruby, yay) so we can get emails if something happenes:</p>
<div class="geshi no ruby">
<ol>
<li class="li1">
<div class="de1"><span class="kw3">require</span> <span class="kw4">File</span>.<span class="me1">dirname</span><span class="br0">&#40;</span><span class="kw2">__FILE__</span><span class="br0">&#41;</span> <span class="sy0">+</span> <span class="st0">&#39;/watches.rb&#39;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="co1"># mailer configuration</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co1"># &#8230;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="re2">God::Contacts::Email</span>.<span class="me1">delivery_method</span> = <span class="re3">:sendmail</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">God.<span class="me1">contact</span><span class="br0">&#40;</span><span class="re3">:email</span><span class="br0">&#41;</span> <span class="kw1">do</span> <span class="sy0">|</span>c<span class="sy0">|</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; c.<span class="me1">name</span> = <span class="st0">&#39;ktoso&#39;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; c.<span class="me1">to_email</span> = <span class="st0">&#39;konrad.malawski@llp.pl&#39;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">end</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="co1"># include all watches</span></div>
</li>
<li class="li1">
<div class="de1">God.<span class="kw3">load</span> <span class="st0">&quot;/etc/god/watches/*.rb&quot;</span></div>
</li>
</ol>
</div>
<p>And then all that&#8217;s left to implement is a watch, so create an <strong>/etc/god/watches/xvbf.rb</strong>. It&#8217;s using a nice DSL to configure how God should act when a process dies etc:</p>
<div class="geshi no ruby">
<ol>
<li class="li1">
<div class="de1">God.<span class="me1">watch</span> <span class="kw1">do</span> <span class="sy0">|</span>w<span class="sy0">|</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; w.<span class="me1">uid</span> = <span class="st0">&quot;jenkins&quot;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; w.<span class="me1">gid</span> = <span class="st0">&quot;jenkins&quot;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; w.<span class="me1">name</span> = <span class="st0">&quot;xvfb&quot;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; w.<span class="me1">interval</span> = <span class="nu0">30</span>.<span class="me1">seconds</span> <span class="co1"># default</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; w.<span class="me1">env</span> = <span class="br0">&#123;</span> <span class="st0">&quot;DISPLAY&quot;</span> <span class="sy0">=&gt;</span> <span class="st0">&quot;:99&quot;</span> <span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; w.<span class="me1">start</span> = <span class="st0">&quot;Xvfb -ac :99 &amp;&quot;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; w.<span class="me1">start_grace</span> = <span class="nu0">10</span>.<span class="me1">seconds</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; w.<span class="me1">restart_grace</span> = <span class="nu0">10</span>.<span class="me1">seconds</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; w.<span class="me1">behavior</span><span class="br0">&#40;</span><span class="re3">:clean_pid_file</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; w.<span class="me1">start_if</span> <span class="kw1">do</span> <span class="sy0">|</span>start<span class="sy0">|</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; start.<span class="me1">condition</span><span class="br0">&#40;</span><span class="re3">:process_running</span><span class="br0">&#41;</span> <span class="kw1">do</span> <span class="sy0">|</span>c<span class="sy0">|</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; c.<span class="me1">running</span> = <span class="kw2">false</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; c.<span class="me1">notify</span> = <span class="br0">&#91;</span><span class="st0">&#39;konrad&#39;</span><span class="br0">&#93;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw1">end</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; <span class="kw1">end</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">end</span></div>
</li>
</ol>
</div>
<p>The code is pretty much self explanatory. We watch if the process Xvfb is running, and if not, after the grace period we restart it. Optional info email could also be sent using the notify property.</p>
<p>That&#8217;s it, have fun automating your build environments!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.blog.project13.pl/index.php/coding/1338/keeping-processes-alive-using-gods-power/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[release] Sidewinder X6 MacroKeys on GNU/Linux</title>
		<link>http://www.blog.project13.pl/index.php/fun/1333/1333/</link>
		<comments>http://www.blog.project13.pl/index.php/fun/1333/1333/#comments</comments>
		<pubDate>Wed, 27 Jul 2011 22:30:03 +0000</pubDate>
		<dc:creator>Ktoso</dc:creator>
				<category><![CDATA[coding]]></category>
		<category><![CDATA[freedom]]></category>
		<category><![CDATA[fun]]></category>
		<category><![CDATA[terminal heroes]]></category>
		<category><![CDATA[keystroke]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[macro]]></category>
		<category><![CDATA[sidewinder]]></category>
		<category><![CDATA[sidewinder x6 linux]]></category>
		<category><![CDATA[xdotool]]></category>

		<guid isPermaLink="false">http://www.blog.project13.pl/?p=1333</guid>
		<description><![CDATA[I&#8217;ve released my keyboard event mapper for the Microsoft Sidewinder X6 in an quite usable state right now. Take a look at sidewinder-x6-linux-macro-key-events on github. Here&#8217;s a quick description what it does: As the Sidewinder is an Microsoft keyboard, it obviously does all it can to not work at it&#8217;s full potential on GNU/Linux systems [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve released my keyboard event mapper for the <a href="http://www.microsoft.com/poland/hardware/gaming/productdetails.aspx?pid=102" onclick="urchinTracker('/outgoing/www.microsoft.com/poland/hardware/gaming/productdetails.aspx?pid=102&amp;referer=');">Microsoft Sidewinder X6</a> in an quite usable state right now. Take a look at <a href="https://github.com/ktoso/sidewinder-x6-linux-macro-key-events" onclick="urchinTracker('/outgoing/github.com/ktoso/sidewinder-x6-linux-macro-key-events?referer=');">sidewinder-x6-linux-macro-key-events</a> on github. Here&#8217;s a quick description what it does:</p>
<p><a href="http://www.blog.project13.pl/wp-content/uploads/2011/07/sidewinder-x6-macro-keys.jpg"><img class="aligncenter size-full wp-image-1334" title="sidewinder-x6-macro-keys" src="http://www.blog.project13.pl/wp-content/uploads/2011/07/sidewinder-x6-macro-keys.jpg" alt="" width="500" height="375" /></a>As the Sidewinder is an Microsoft keyboard, it obviously does all it can to not work at it&#8217;s full potential on GNU/Linux systems ;-) What my script does is watch for usb events, using <strong>usbmon</strong>, then it filters it searching for events from this keyboard, and then it filters out the discrete keystrokes for them. When such keystroke is found, we launch an bash script located in <strong>actions/S##.sh </strong>which can then do anything you want it to do &#8211; fire up intellij, or send keystrokes. I&#8217;d advice the second idea &#8211; use <a href="http://www.semicomplete.com/projects/xdotool/" onclick="urchinTracker('/outgoing/www.semicomplete.com/projects/xdotool/?referer=');">xdotool</a> to send keyboard events, which you then map in Intellij or Netbeans or KDE/GNOME. Such keycode send looks like this:</p>
<p><code>xdotool key --clearmodifiers ctrl+shift+F1</code></p>
<p>That&#8217;s about it. I also wanted to thank some guys on github, who found my project and it really helped them out :-) Just to cite my fav email:</p>
<blockquote><p>
[...]<br />
I&#8217;m amazed to see that somebody made this keyboard work under linux, I was beggining to lose hope. Great job!<br />
[...]
</p></blockquote>
<p>Thanks for the feedback, it&#8217;s what keeps me going with opensourceing projects like this :-)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.blog.project13.pl/index.php/fun/1333/1333/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[git] bisect + maven = automate &#8220;breaking&#8221; commit search</title>
		<link>http://www.blog.project13.pl/index.php/coding/1217/git-bisect-maven-automate-breaking-commit-search/</link>
		<comments>http://www.blog.project13.pl/index.php/coding/1217/git-bisect-maven-automate-breaking-commit-search/#comments</comments>
		<pubDate>Wed, 16 Mar 2011 21:34:31 +0000</pubDate>
		<dc:creator>Ktoso</dc:creator>
				<category><![CDATA[coding]]></category>
		<category><![CDATA[english]]></category>
		<category><![CDATA[guide]]></category>
		<category><![CDATA[terminal heroes]]></category>
		<category><![CDATA[#maven]]></category>
		<category><![CDATA[bisect]]></category>
		<category><![CDATA[git]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[runner]]></category>
		<category><![CDATA[SCM]]></category>
		<category><![CDATA[TDD]]></category>
		<category><![CDATA[testing]]></category>

		<guid isPermaLink="false">http://www.blog.project13.pl/?p=1217</guid>
		<description><![CDATA[Hey there guys. I hope some you enjoyed my presentation on SFI last weekend. The workshop was kinda chaotic (network problems mailny) but I&#8217;m sure some of you got convinced to use, or begin with trying out, git in yout next projects&#8230; :-) Well, that was all nice and cool but git (other DVCS have [...]]]></description>
			<content:encoded><![CDATA[<p>Hey there guys. I hope some you enjoyed my presentation on SFI last weekend. The workshop was kinda chaotic (network problems mailny) but I&#8217;m sure some of you got convinced to use, or begin with trying out, git in yout next projects&#8230; :-)</p>
<p>Well, that was all nice and cool but git (other DVCS have this too) has a lot more to offer! :-) Today we&#8217;ll look into git bisect and how to automate it&#8217;s execution using maven to look for a commit that breakes something. You may run ANY SCRIPT and even write your own and git will use it to test if a commit is &#8220;bad&#8221; or &#8220;good&#8221;. Ok, but let&#8217;s slowdown a little&#8230; What git bisect basically does is performing an binary search, between a range of commits you specify looking for &#8220;the first bad commit&#8221; you you can easily find what caused the bug and fix it. You can drive it by hand and after starting git bisect just test the commit by hand and tell git if it&#8217;s good or bad by &#8220;git bisect bad&#8221; &#8220;git bisect good&#8221;. Git is smart enough to find what commit he should &#8220;git checkout &#8230;&#8221; next to perform a binary search based on your anwsers. </p>
<p>Today we&#8217;ll learn how to make git cooperate with maven and find the first commit that introduced a test failure. See bellow for the full workflow you showcasing this:</p>
<div class="geshi no bash">
<ol>
<li class="li1">
<div class="de1">ktoso<span class="sy0">@</span>dynames breakMe $ mvn org.apache.maven.plugins:maven-archetype-plugin:<span class="nu0">1.0</span>-alpha<span class="nu0">-7</span>:create -<span class="re2">DarchetypeGroupId=</span>org.apache.maven.archetypes -<span class="re2">DarchetypeArtifactId=</span>maven-archetype-quickstart -<span class="re2">DartifactId=</span>bisectfun -<span class="re2">DgroupId=</span>pl.project13</div>
</li>
<li class="li1">
<div class="de1"><span class="co0">#&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;.</span></div>
</li>
<li class="li1">
<div class="de1">ktoso<span class="sy0">@</span>dynames breakMe $ <span class="kw2">ls</span></div>
</li>
<li class="li1">
<div class="de1">bisectfun &nbsp;mavenbisect.<span class="kw2">sh</span></div>
</li>
<li class="li1">
<div class="de1">ktoso<span class="sy0">@</span>dynames breakMe $ <span class="kw3">cd</span> bisectfun<span class="sy0">/</span></div>
</li>
<li class="li1">
<div class="de1">ktoso<span class="sy0">@</span>dynames bisectfun $ <span class="kw2">mkdir</span> src<span class="sy0">/</span><span class="kw3">test</span><span class="sy0">/</span>resources<span class="sy0">/</span></div>
</li>
<li class="li1">
<div class="de1">ktoso<span class="sy0">@</span>dynames bisectfun $ git init .</div>
</li>
<li class="li1">
<div class="de1">Initialized empty Git repository <span class="kw1">in</span> <span class="sy0">/</span>tmp<span class="sy0">/</span>breakMe<span class="sy0">/</span>bisectfun<span class="sy0">/</span>.git<span class="sy0">/</span></div>
</li>
<li class="li1">
<div class="de1">ktoso<span class="sy0">@</span>dynames bisectfun $ git commit ^C</div>
</li>
<li class="li1">
<div class="de1">ktoso<span class="sy0">@</span>dynames bisectfun $ vim .gitignore</div>
</li>
<li class="li1">
<div class="de1">ktoso<span class="sy0">@</span>dynames bisectfun $ git add .</div>
</li>
<li class="li1">
<div class="de1">ktoso<span class="sy0">@</span>dynames bisectfun $ git commit </div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#91;</span>master <span class="br0">&#40;</span>root-commit<span class="br0">&#41;</span> 5b46510<span class="br0">&#93;</span> &nbsp;Initial commit</div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="nu0">4</span> files changed, <span class="nu0">78</span> insertions<span class="br0">&#40;</span>+<span class="br0">&#41;</span>, <span class="nu0">0</span> deletions<span class="br0">&#40;</span>-<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;create mode <span class="nu0">100644</span> .gitignore</div>
</li>
<li class="li1">
<div class="de1">&nbsp;create mode <span class="nu0">100644</span> pom.xml</div>
</li>
<li class="li1">
<div class="de1">&nbsp;create mode <span class="nu0">100644</span> src<span class="sy0">/</span>main<span class="sy0">/</span>java<span class="sy0">/</span>pl<span class="sy0">/</span>project13<span class="sy0">/</span>App.java</div>
</li>
<li class="li1">
<div class="de1">&nbsp;create mode <span class="nu0">100644</span> src<span class="sy0">/</span><span class="kw3">test</span><span class="sy0">/</span>java<span class="sy0">/</span>pl<span class="sy0">/</span>project13<span class="sy0">/</span>AppTest.java</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="sy0">********************************************************************************</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Git Achievement Unlocked<span class="sy0">!</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Master Author <span class="br0">&#40;</span>Level <span class="nu0">10</span><span class="br0">&#41;</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Made <span class="nu0">2</span>^Level commits using git commit. &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li class="li1">
<div class="de1"><span class="sy0">********************************************************************************</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co0">#&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;.</span></div>
</li>
<li class="li1">
<div class="de1">ktoso<span class="sy0">@</span>dynames bisectfun <span class="sy0">@</span> master $ mvn <span class="kw3">test</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co0">#&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;.</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#91;</span>INFO<span class="br0">&#93;</span> BUILD SUCCESSFUL</div>
</li>
<li class="li1">
<div class="de1"><span class="co0">#&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;.</span></div>
</li>
</ol>
</div>
<p>Ok up until now we&#8217;ve just created a simple repository we&#8217;ll be running the tests on. Let&#8217;s tag this state as &#8220;yeah it&#8217;s working here&#8221; just so that I don&#8217;t have to remeber the SHA-1 of this commit. </p>
<div class="geshi no bash">
<ol>
<li class="li1">
<div class="de1">ktoso<span class="sy0">@</span>dynames bisectfun <span class="sy0">@</span> master $ git tag wasOkHere</div>
</li>
</ol>
</div>
<p>And now we&#8217;ll run a script that does some random commit action, just so that bisect has a lot of commits to work on.</p>
<div class="geshi no bash">
<ol>
<li class="li1">
<div class="de1">ktoso<span class="sy0">@</span>dynames bisectfun <span class="sy0">@</span> master $ <span class="kw1">for</span> i <span class="kw1">in</span> <span class="br0">&#123;</span><span class="nu0">1</span>..<span class="nu0">50</span><span class="br0">&#125;</span>; <span class="kw1">do</span> fortune <span class="sy0">&gt;</span> src<span class="sy0">/</span><span class="kw3">test</span><span class="sy0">/</span>resources<span class="sy0">/</span>fortune<span class="re1">$i</span>; git add .; git commit -a -m <span class="st0">&#39;some commit&#39;</span>; <span class="kw1">done</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#91;</span>master 20ae1c1<span class="br0">&#93;</span> some commit</div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="nu0">1</span> files changed, <span class="nu0">3</span> insertions<span class="br0">&#40;</span>+<span class="br0">&#41;</span>, <span class="nu0">0</span> deletions<span class="br0">&#40;</span>-<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;create mode <span class="nu0">100644</span> src<span class="sy0">/</span><span class="kw3">test</span><span class="sy0">/</span>resources<span class="sy0">/</span>fortune1</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#91;</span>master 64b779e<span class="br0">&#93;</span> some commit</div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="nu0">1</span> files changed, <span class="nu0">15</span> insertions<span class="br0">&#40;</span>+<span class="br0">&#41;</span>, <span class="nu0">0</span> deletions<span class="br0">&#40;</span>-<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;create mode <span class="nu0">100644</span> src<span class="sy0">/</span><span class="kw3">test</span><span class="sy0">/</span>resources<span class="sy0">/</span>fortune2</div>
</li>
<li class="li1">
<div class="de1"><span class="co0">#&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;.</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co0">#&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;.</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co0">#&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;.</span></div>
</li>
<li class="li1">
<div class="de1">ktoso<span class="sy0">@</span>dynames bisectfun <span class="sy0">@</span> master $ mvn clean <span class="kw3">test</span> <span class="sy0">&gt;</span> <span class="sy0">/</span>dev<span class="sy0">/</span>null <span class="nu0">2</span><span class="sy0">&gt;</span> <span class="sy0">/</span>dev<span class="sy0">/</span>null</div>
</li>
<li class="li1">
<div class="de1">ktoso<span class="sy0">@</span>dynames bisectfun <span class="sy0">@</span> master $ <span class="kw3">echo</span> <span class="re4">$?</span></div>
</li>
<li class="li1">
<div class="de1"><span class="nu0">0</span></div>
</li>
</ol>
</div>
<p>The tests are still passing&#8230; time to change that! We&#8217;ll break the build with the following commit. And then generate yet another 50 commits to &#8220;hide it&#8221;&#8230; ;-)</p>
<div class="geshi no bash">
<div class="head">ktoso@dynames bisectfun @ master $ echo &#8220;fail :D&#8221; >> src/test/java/pl/project13/AppTest.java</div>
<ol>
<li class="li1">
<div class="de1">ktoso<span class="sy0">@</span>dynames bisectfun <span class="sy0">@</span> master $ <span class="kw3">echo</span> <span class="st0">&quot;fail :D&quot;</span> <span class="sy0">&gt;&gt;</span> src<span class="sy0">/</span><span class="kw3">test</span><span class="sy0">/</span>java<span class="sy0">/</span>pl<span class="sy0">/</span>project13<span class="sy0">/</span>AppTest.java </div>
</li>
<li class="li1">
<div class="de1">ktoso<span class="sy0">@</span>dynames bisectfun <span class="sy0">@</span> master $ <span class="kw3">echo</span> <span class="st0">&quot;fail :D&quot;</span> <span class="sy0">&gt;&gt;</span> src<span class="sy0">/</span><span class="kw3">test</span><span class="sy0">/</span>java<span class="sy0">/</span>pl<span class="sy0">/</span>project13<span class="sy0">/</span>AppTest.java </div>
</li>
<li class="li1">
<div class="de1">ktoso<span class="sy0">@</span>dynames bisectfun <span class="sy0">@</span> master $ git add .</div>
</li>
<li class="li1">
<div class="de1">ktoso<span class="sy0">@</span>dynames bisectfun <span class="sy0">@</span> master $ git commit </div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#91;</span>master 09a58fb<span class="br0">&#93;</span> <span class="kw3">let</span> it crash</div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="nu0">1</span> files changed, <span class="nu0">3</span> insertions<span class="br0">&#40;</span>+<span class="br0">&#41;</span>, <span class="nu0">0</span> deletions<span class="br0">&#40;</span>-<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">ktoso<span class="sy0">@</span>dynames bisectfun <span class="sy0">@</span> master $ <span class="kw1">for</span> i <span class="kw1">in</span> <span class="br0">&#123;</span><span class="nu0">1</span>..<span class="nu0">50</span><span class="br0">&#125;</span>; <span class="kw1">do</span> fortune <span class="sy0">&gt;</span> src<span class="sy0">/</span><span class="kw3">test</span><span class="sy0">/</span>resources<span class="sy0">/</span>fortune<span class="re1">$i</span>; git add .; git commit -a -m <span class="st0">&#39;some commit&#39;</span>; <span class="kw1">done</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#91;</span>master f83cdae<span class="br0">&#93;</span> some commit</div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="nu0">1</span> files changed, <span class="nu0">3</span> insertions<span class="br0">&#40;</span>+<span class="br0">&#41;</span>, <span class="nu0">3</span> deletions<span class="br0">&#40;</span>-<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#91;</span>master 725c5ce<span class="br0">&#93;</span> some commit</div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="nu0">1</span> files changed, <span class="nu0">4</span> insertions<span class="br0">&#40;</span>+<span class="br0">&#41;</span>, <span class="nu0">15</span> deletions<span class="br0">&#40;</span>-<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;rewrite src<span class="sy0">/</span><span class="kw3">test</span><span class="sy0">/</span>resources<span class="sy0">/</span>fortune2 <span class="br0">&#40;</span><span class="nu0">100</span><span class="sy0">%</span><span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co0">#&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;.</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co0">#&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;.</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co0">#&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;&#8230;.</span></div>
</li>
<li class="li1">
<div class="de1">ktoso<span class="sy0">@</span>dynames bisectfun <span class="sy0">@</span> master $ <span class="kw1">for</span> i imvn clean <span class="kw3">test</span> <span class="sy0">&gt;</span> <span class="sy0">/</span>dev<span class="sy0">/</span>null <span class="nu0">2</span><span class="sy0">&gt;</span> <span class="sy0">/</span>dev<span class="sy0">/</span>null</div>
</li>
<li class="li1">
<div class="de1">ktoso<span class="sy0">@</span>dynames bisectfun <span class="sy0">@</span> master $ <span class="kw3">echo</span> <span class="re4">$?</span></div>
</li>
<li class="li1">
<div class="de1"><span class="nu0">1</span></div>
</li>
<li class="li1">
<div class="de1">ktoso<span class="sy0">@</span>dynames bisectfun <span class="sy0">@</span> master $ <span class="kw3">echo</span> <span class="st0">&#39;!!!!!!!!!!!!!!OH NO IT FAILS!!!!!!!!&#39;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="sy0">!!!!!!!!!!!!!!!!</span>OH NO IT FAILS<span class="sy0">!!!!!!!!</span></div>
</li>
<li class="li1">
<div class="de1">ktoso<span class="sy0">@</span>dynames bisectfun <span class="sy0">@</span> master $ git tag failsHere</div>
</li>
</ol>
</div>
<p>Ok the test&#8217;s fail now. But suppose you didn&#8217;t know which commit introduced the bug (in our case made the test&#8217;s fail). You&#8217;d have to guess which one, or check them all or just work it out by looking at your current repository state. But since you&#8217;re doing small commits and do them often &#8211; it&#8217;ll be great if you found out which commit caused this failure. As it&#8217;s preferably small, it&#8217;ll be very easy to find out what change caused the build to fail. No is the time to use <strong>git bisect</strong>!</p>
<div class="geshi no bash">
<ol>
<li class="li1">
<div class="de1">ktoso<span class="sy0">@</span>dynames bisectfun <span class="sy0">@</span> master $ git bisect start</div>
</li>
<li class="li1">
<div class="de1">ktoso<span class="sy0">@</span>dynames bisectfun <span class="sy0">@</span> master $ git bisect bad failsHere </div>
</li>
<li class="li1">
<div class="de1">ktoso<span class="sy0">@</span>dynames bisectfun <span class="sy0">@</span> master $ git bisect good wasOkHere </div>
</li>
<li class="li1">
<div class="de1">Bisecting: <span class="nu0">50</span> revisions left to <span class="kw3">test</span> after this <span class="br0">&#40;</span>roughly <span class="nu0">6</span> steps<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#91;</span>ca199e0cbd19e498eabf6196036313e206b00a7f<span class="br0">&#93;</span> some commit</div>
</li>
</ol>
</div>
<p>We&#8217;ve started bisect, and told him which commit we&#8217;re sure is working and which we&#8217;re sure is failing. Git will now checkout a commit he found &#8220;somewhat in the middle&#8221; and will continue to bisect (binary search) the commit history based on wether a commit is &#8220;good&#8221; or &#8220;bad&#8221;. We could just tell it git by hand by doing &#8220;git bisect good/bad&#8221; etc. But let&#8217;s <strong>git bisect run</strong> a script to do this for us :</p>
<div class="geshi no bash">
<ol>
<li class="li1">
<div class="de1">ktoso<span class="sy0">@</span>dynames bisectfun <span class="sy0">@</span> <span class="br0">&#40;</span>no branch<span class="br0">&#41;</span> $ git bisect run ..<span class="sy0">/</span>mavenbisect.<span class="kw2">sh</span></div>
</li>
<li class="li1">
<div class="de1">running ..<span class="sy0">/</span>mavenbisect.<span class="kw2">sh</span></div>
</li>
<li class="li1">
<div class="de1">Bisecting: <span class="nu0">25</span> revisions left to <span class="kw3">test</span> after this <span class="br0">&#40;</span>roughly <span class="nu0">5</span> steps<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#91;</span>c8658db8e0c5df1d603a9a96ae7a04e71c4ba9d1<span class="br0">&#93;</span> some commit</div>
</li>
<li class="li1">
<div class="de1">running ..<span class="sy0">/</span>mavenbisect.<span class="kw2">sh</span></div>
</li>
<li class="li1">
<div class="de1">Bisecting: <span class="nu0">12</span> revisions left to <span class="kw3">test</span> after this <span class="br0">&#40;</span>roughly <span class="nu0">4</span> steps<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#91;</span>ddc2100ab90d0624df74e81f17d7ed7ea0fc9a61<span class="br0">&#93;</span> some commit</div>
</li>
<li class="li1">
<div class="de1">running ..<span class="sy0">/</span>mavenbisect.<span class="kw2">sh</span></div>
</li>
<li class="li1">
<div class="de1">Bisecting: <span class="nu0">5</span> revisions left to <span class="kw3">test</span> after this <span class="br0">&#40;</span>roughly <span class="nu0">3</span> steps<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#91;</span>31ba35661eecb7a96159e483954d315a63a3789d<span class="br0">&#93;</span> some commit</div>
</li>
<li class="li1">
<div class="de1">running ..<span class="sy0">/</span>mavenbisect.<span class="kw2">sh</span></div>
</li>
<li class="li1">
<div class="de1">Bisecting: <span class="nu0">2</span> revisions left to <span class="kw3">test</span> after this <span class="br0">&#40;</span>roughly <span class="nu0">2</span> steps<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#91;</span>725c5cec8803b1e62dd36a3b74fd8c52d42e807c<span class="br0">&#93;</span> some commit</div>
</li>
<li class="li1">
<div class="de1">running ..<span class="sy0">/</span>mavenbisect.<span class="kw2">sh</span></div>
</li>
<li class="li1">
<div class="de1">Bisecting: <span class="nu0">0</span> revisions left to <span class="kw3">test</span> after this <span class="br0">&#40;</span>roughly <span class="nu0">1</span> step<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#91;</span>f83cdaeb34072a6f9c9a63abf8bb8f2390b996de<span class="br0">&#93;</span> some commit</div>
</li>
<li class="li1">
<div class="de1">running ..<span class="sy0">/</span>mavenbisect.<span class="kw2">sh</span></div>
</li>
<li class="li1">
<div class="de1">Bisecting: <span class="nu0">0</span> revisions left to <span class="kw3">test</span> after this <span class="br0">&#40;</span>roughly <span class="nu0">0</span> steps<span class="br0">&#41;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#91;</span>09a58fbf2821c4f66c003a65f19f6ff99f5ee37d<span class="br0">&#93;</span> <span class="kw3">let</span> it crash</div>
</li>
<li class="li1">
<div class="de1">running ..<span class="sy0">/</span>mavenbisect.<span class="kw2">sh</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">09a58fbf2821c4f66c003a65f19f6ff99f5ee37d is the first bad commit</div>
</li>
<li class="li1">
<div class="de1">commit 09a58fbf2821c4f66c003a65f19f6ff99f5ee37d</div>
</li>
<li class="li1">
<div class="de1">Author: Konrad Malawski <span class="sy0">&lt;</span>konrad .malawski<span class="sy0">@</span>project13.pl<span class="sy0">&gt;</span></div>
</li>
<li class="li1">
<div class="de1">Date: &nbsp; Wed Mar <span class="nu0">16</span> <span class="nu0">22</span>:<span class="nu0">02</span>:<span class="nu0">38</span> <span class="nu0">2011</span> <span class="nu0">+0100</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw3">let</span> it crash</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">:<span class="nu0">040000</span> <span class="nu0">040000</span> ef88527072e0b1532819a75f288a0e65a2737c6a 49083a7d820a731d5edad117a4af097bd9ffb444 M &nbsp; &nbsp; &nbsp;src</div>
</li>
<li class="li1">
<div class="de1">bisect run success</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">ktoso<span class="sy0">@</span>dynames bisectfun <span class="sy0">@</span> <span class="br0">&#40;</span>no branch<span class="br0">&#41;</span> $ git show 09a58fbf2821c4f66c003a65f19f6ff99f5ee37d</div>
</li>
<li class="li1">
<div class="de1">commit 09a58fbf2821c4f66c003a65f19f6ff99f5ee37d</div>
</li>
<li class="li1">
<div class="de1">Author: Konrad Malawski <span class="sy0">&lt;/</span>konrad<span class="sy0">&gt;&lt;</span>konrad .malawski<span class="sy0">@</span>project13.pl<span class="sy0">&gt;</span></div>
</li>
<li class="li1">
<div class="de1">Date: &nbsp; Wed Mar <span class="nu0">16</span> <span class="nu0">22</span>:<span class="nu0">02</span>:<span class="nu0">38</span> <span class="nu0">2011</span> <span class="nu0">+0100</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw3">let</span> it crash</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">diff</span> &#8211;git a<span class="sy0">/</span>src<span class="sy0">/</span><span class="kw3">test</span><span class="sy0">/</span>java<span class="sy0">/</span>pl<span class="sy0">/</span>project13<span class="sy0">/</span>AppTest.java b<span class="sy0">/</span>src<span class="sy0">/</span><span class="kw3">test</span><span class="sy0">/</span>java<span class="sy0">/</span>pl<span class="sy0">/</span>project13<span class="sy0">/</span>AppTest.java</div>
</li>
<li class="li1">
<div class="de1">index c6ffd44..b27c8b8 <span class="nu0">100644</span></div>
</li>
<li class="li1">
<div class="de1">&#8212; a<span class="sy0">/</span>src<span class="sy0">/</span><span class="kw3">test</span><span class="sy0">/</span>java<span class="sy0">/</span>pl<span class="sy0">/</span>project13<span class="sy0">/</span>AppTest.java</div>
</li>
<li class="li1">
<div class="de1">+++ b<span class="sy0">/</span>src<span class="sy0">/</span><span class="kw3">test</span><span class="sy0">/</span>java<span class="sy0">/</span>pl<span class="sy0">/</span>project13<span class="sy0">/</span>AppTest.java</div>
</li>
<li class="li1">
<div class="de1"><span class="sy0">@@</span> <span class="nu0">-36</span>,<span class="nu0">3</span> <span class="nu0">+36</span>,<span class="nu0">6</span> <span class="sy0">@@</span> public class AppTest</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;assertTrue<span class="br0">&#40;</span> <span class="kw2">true</span> <span class="br0">&#41;</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp;<span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;<span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1">+fail :D</div>
</li>
<li class="li1">
<div class="de1">+fail :D</div>
</li>
<li class="li1">
<div class="de1">+fail :D</div>
</li>
<li class="li1">
<div class="de1">ktoso<span class="sy0">@</span>dynames bisectfun <span class="sy0">@</span> <span class="br0">&#40;</span>no branch<span class="br0">&#41;</span> $ git bisect reset </div>
</li>
<li class="li1">
<div class="de1">Previous HEAD position was 09a58fb&#8230; <span class="kw3">let</span> it crash</div>
</li>
<li class="li1">
<div class="de1">Switched to branch <span class="st0">&#39;master&#39;</span></div>
</li>
<li class="li1">
<div class="de1">ktoso<span class="sy0">@</span>dynames bisectfun <span class="sy0">@</span> master $ </div>
</li>
<li class="li1">
<div class="de1"><span class="sy0">&lt;/</span>konrad<span class="sy0">&gt;</span></div>
</li>
</ol>
</div>
<p>Yeah, we&#8217;ve found our failing commit :-) You could use any script you want here, it just has to return 0 if git should think it&#8217;s a &#8220;good commit&#8221; and &#8220;not 0&#8243; if it&#8217;s a &#8220;bad commit&#8221;. I&#8217;ve even seen runners written in PHP running or spellcheckers &#8211; you name it&#8230; :-) Ok but how does this magical script that we&#8217;ve just run look like?</p>
<div class="geshi no bash">
<ol>
<li class="li1">
<div class="de1"><span class="co0">#!/bin/sh</span></div>
</li>
<li class="li1">
<div class="de1">mvn clean <span class="kw3">test</span> <span class="sy0">&gt;</span> <span class="sy0">/</span>dev<span class="sy0">/</span>null <span class="nu0">2</span><span class="sy0">&gt;</span> <span class="sy0">/</span>dev<span class="sy0">/</span>null</div>
</li>
</ol>
</div>
<p>Whoa, that&#8217;s simple&#8230; :-) Keep on git hacking guys! See you soon, with some more git or java tips&#8230; :-) Oh and I&#8217;ll post my presentation (holefully with video) from SFI soon, so keep an eye out! :-)</p>
<p>PS: Yup, the <strong>code retreat</strong> we&#8217;re (SCKRK with a little help from the <a href="http://www.java.pl" onclick="urchinTracker('/outgoing/www.java.pl?referer=');">PolishJUG</a>) organizing got &#8220;sold out&#8221; after just 3h&#8230; ;-) Be sure to take a look and be quicker next time! <a href="http://coderetreat.sckrk.com" onclick="urchinTracker('/outgoing/coderetreat.sckrk.com?referer=');">http://coderetreat.sckrk.com</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.blog.project13.pl/index.php/coding/1217/git-bisect-maven-automate-breaking-commit-search/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[terminal heroes] Display git branch in shell prompt (PS1)</title>
		<link>http://www.blog.project13.pl/index.php/fun/1198/terminal-heroes-display-git-branch-in-shell-prompt-ps1/</link>
		<comments>http://www.blog.project13.pl/index.php/fun/1198/terminal-heroes-display-git-branch-in-shell-prompt-ps1/#comments</comments>
		<pubDate>Sat, 26 Feb 2011 22:29:01 +0000</pubDate>
		<dc:creator>Ktoso</dc:creator>
				<category><![CDATA[english]]></category>
		<category><![CDATA[fun]]></category>
		<category><![CDATA[guide]]></category>
		<category><![CDATA[terminal heroes]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[branch]]></category>
		<category><![CDATA[git]]></category>
		<category><![CDATA[prompt]]></category>
		<category><![CDATA[ps1]]></category>
		<category><![CDATA[shell]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[tricks]]></category>

		<guid isPermaLink="false">http://www.blog.project13.pl/?p=1198</guid>
		<description><![CDATA[I don&#8217;t think I&#8217;ve blogged about this but I&#8217;ve seen this sometime ago and now decided to add it to my .bashrc for good. It&#8217;s a simple trick to make an awesome PS1 shell prompt, displaying the branch you are currently on (if you&#8217;re in a git versioned directory). Not that I&#8217;m forgetting what branch [...]]]></description>
			<content:encoded><![CDATA[<p>I don&#8217;t think I&#8217;ve blogged about this but I&#8217;ve seen this sometime ago and now decided to add it to my .bashrc for good. It&#8217;s a simple trick to make an awesome PS1 shell prompt, displaying the branch you are currently on (if you&#8217;re in a git versioned directory). Not that I&#8217;m forgetting what branch I&#8217;m on, but I hope it&#8217;ll make me create more branches more often and never &#8220;just work on master&#8221; :-)</p>
<p><a href="http://www.blog.project13.pl/wp-content/uploads/2011/02/awesome-git-branch-in-shell.png"><img src="http://www.blog.project13.pl/wp-content/uploads/2011/02/awesome-git-branch-in-shell.png" alt="" title="awesome-git-branch-in-shell" width="530" class="aligncenter size-full wp-image-1211" /></a></p>
<p>The code comes from <a href="http://arnorehn.de/cgi-bin/weblog_basic/index.php?p=34" onclick="urchinTracker('/outgoing/arnorehn.de/cgi-bin/weblog_basic/index.php?p=34&amp;referer=');">http://arnorehn.de/cgi-bin/weblog_basic/index.php?p=34</a> so big kudos too him :-)</p>
<div class="geshi no bash">
<ol>
<li class="li1">
<div class="de1"><span class="co0"># in your ~/.bashrc for example</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw3">alias</span> <span class="re2">gitka=</span><span class="st0">&#39;gitk &#8211;all&#39;</span> <span class="co0">#unrelated to this post, but very useful :-)</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">function</span> formattedGitBranch <span class="br0">&#123;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="re2">_branch=</span><span class="st0">&quot;$(git branch 2&gt;/dev/null | sed -e &quot;</span><span class="sy0">/</span>^\s<span class="sy0">/</span>d<span class="st0">&quot; -e &quot;</span>s<span class="sy0">/</span>^\<span class="sy0">*</span>\s<span class="sy0">//</span><span class="st0">&quot;)&quot;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw3">test</span> -n <span class="st0">&quot;$_branch&quot;</span> <span class="sy0">&amp;&amp;</span> <span class="kw3">echo</span> -e <span class="st0">&quot; @<span class="es0">\e</span>[0;32m $_branch&quot;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#125;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co0">#export PS1=&quot;\u@\h \W \[\e[m\]\$(formattedGitBranch) \[\e[1;32m\]\$ \[\e[m\]\[\e[0m\]&quot; </span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw3">export</span> <span class="re2">PS1=</span><span class="st0">&quot;<span class="es0">\u</span>@<span class="es0">\h</span> <span class="es0">\W</span><span class="es0">\[</span><span class="es0">\e</span>[m<span class="es0">\]</span><span class="es0">\$</span>(formattedGitBranch)<span class="es0">\[</span><span class="es0">\e</span>[0m<span class="es0">\]</span> <span class="es0">\$</span> &quot;</span></div>
</li>
</ol>
</div>
<p>Cheers and <b>happy hacking</b>!</p>
<p>PS: I&#8217;m waiting for my T-shirt and stickers (for training participants) to arrive from github. I&#8217;d love they make it in time for <a href="http://www.sfi.org.pl" onclick="urchinTracker('/outgoing/www.sfi.org.pl?referer=');">SFI</a> but I&#8217;m not sure if it&#8217;s even possible hmmm&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.blog.project13.pl/index.php/fun/1198/terminal-heroes-display-git-branch-in-shell-prompt-ps1/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>G73 keyboard backlight scripts</title>
		<link>http://www.blog.project13.pl/index.php/fun/1163/g73-keayboard-backlight-scripts/</link>
		<comments>http://www.blog.project13.pl/index.php/fun/1163/g73-keayboard-backlight-scripts/#comments</comments>
		<pubDate>Sat, 29 Jan 2011 19:09:42 +0000</pubDate>
		<dc:creator>Ktoso</dc:creator>
				<category><![CDATA[coding]]></category>
		<category><![CDATA[freedom]]></category>
		<category><![CDATA[fun]]></category>
		<category><![CDATA[gaming]]></category>
		<category><![CDATA[guide]]></category>
		<category><![CDATA[terminal heroes]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[fsf]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[notebook]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[terminal]]></category>

		<guid isPermaLink="false">http://www.blog.project13.pl/?p=1163</guid>
		<description><![CDATA[I&#8217;ve upgraded my desktop and laptop last week. By &#8220;and&#8221; I mean that I&#8217;ve bought an desktop replacement class notebook &#8211; an Asus G73 series. Amongst many nice parts it has I&#8217;m very happy about the harddrives &#8211; Seagate Momentus XT, click the link to see an very interesting benchmark of it. Anyways, that&#8217;s not [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve upgraded my desktop and laptop last week. By &#8220;and&#8221; I mean that I&#8217;ve bought an desktop replacement class notebook &#8211; an <strong>Asus G73 </strong>series. Amongst many nice parts it has I&#8217;m very happy about the harddrives &#8211; <a href="http://www.tomshardware.com/reviews/seagate-momentus-xt-hybrid-hard-drive-ssd,2638.html" onclick="urchinTracker('/outgoing/www.tomshardware.com/reviews/seagate-momentus-xt-hybrid-hard-drive-ssd_2638.html?referer=');">Seagate Momentus XT</a>, click the link to see an very interesting benchmark of it. Anyways, that&#8217;s not what this post should be about.</p>
<p>The G73 has an backlit keyboard, which may come in handy while late night coding without lights on as I like to code sometimes. (I&#8217;m using a X6 Sidewinder, even with this Notebook so it&#8217;s not like it&#8217;s keyboard matters to me most of the time ;-)) As usual with such &#8220;super cool addons&#8221; the funtion keys regulating the keyboard backlight seemed to only work on Windows &#8211; which I&#8217;m only using for gaming (but rarely) and testing if the software I happened to write runs ok on it. Anyways, turns out that the keyboard does really well integrate with linux, and you just need a few simple commands to use it, I&#8217;ve made them available on github :-)</p>
<p><a href="https://github.com/ktoso/g73-keyboard-backlight-sh/" onclick="urchinTracker('/outgoing/github.com/ktoso/g73-keyboard-backlight-sh/?referer=');">https://github.com/ktoso/<strong>g73-keyboard-backlight-sh</strong></a> &lt;- Go here to check it out :-)</p>
<div class="geshi no markdown">
<div class="head">Asus G73 Keyboard Backlight GNU/Linux Scripts</div>
<ol>
<li class="li1">
<div class="de1">=============================================
</div>
</li>
<li class="li1">
<div class="de1">To enable the `Fn + F3` and `Fn + F4` shortcuts to work under linux and really
</div>
</li>
<li class="li1">
<div class="de1">manipulate the backlight brighntess on your *Asus G73* series notebook, follow theese simple steps:
</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">1. Clone this repository to your home directory (or wherever you want to, I&#39;ll do this example for ~/ for simplicity)
</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;cd
</div>
</li>
<li class="li1">
<div class="de1">&nbsp;git clone git://github.com/ktoso/g73-keyboard-backlight-sh.git g73
</div>
</li>
<li class="li1">
<div class="de1">&nbsp;
</div>
</li>
<li class="li1">
<div class="de1">2. Make sure all scripts are marked executable:
</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;cd g73
</div>
</li>
<li class="li1">
<div class="de1">&nbsp;chmod +x *.sh
</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">3. Take a look at these scripts to make sure you trust them, why? Because they&#39;ll need root access,
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;without asking for the password. Now we&#39;ll add these scripts to allow `sudo`to run them without
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;asking for any password:
</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;su -c &#39;visudo&#39; # or &#39;sudo visudo&#39; if you&#39;re a sudoer (on ubuntu etc)
</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;There just add the following lines at the end of this file (or similar, with the script names etc).
</div>
</li>
<li class="li1">
<div class="de1">&nbsp;Of course, replace `ktoso` and `/home/ktoso/` with your *username* and *your home directory*.
</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">&nbsp;## allow running keyboard backlight scripts
</div>
</li>
<li class="li1">
<div class="de1">&nbsp;ktoso ALL=(ALL) NOPASSWD:/home/ktoso/g73/*
</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1">4. Now all that&#39;s left is to setup the key bindings for the scripts. If you&#39;re on KDE4, just go to
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;*System Settings -&amp;gt; Shortcuts and Gestures -&amp;gt; Custom Shortcuts* and *edit -&amp;gt; import&#8230;* the file **~/g73/g73_keyboard.khotkeys**
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; which contains ready keybindings for these scripts.
</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; Now you may use `Fn + F3` to make the keyboard backlight shine **less**, and the `Fn + F4` combination to make it shine **more**.</div>
</li>
</ol>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.blog.project13.pl/index.php/fun/1163/g73-keayboard-backlight-scripts/feed/</wfw:commentRss>
		<slash:comments>18</slash:comments>
		</item>
		<item>
		<title>git-hacking: pre-commit hook and custom command</title>
		<link>http://www.blog.project13.pl/index.php/fun/1076/git-hacking-pre-commit-hook-and-custom-command/</link>
		<comments>http://www.blog.project13.pl/index.php/fun/1076/git-hacking-pre-commit-hook-and-custom-command/#comments</comments>
		<pubDate>Sun, 21 Nov 2010 02:07:39 +0000</pubDate>
		<dc:creator>Ktoso</dc:creator>
				<category><![CDATA[coding]]></category>
		<category><![CDATA[english]]></category>
		<category><![CDATA[freedom]]></category>
		<category><![CDATA[fun]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[terminal heroes]]></category>
		<category><![CDATA[#eclipse]]></category>
		<category><![CDATA[git]]></category>
		<category><![CDATA[hack]]></category>
		<category><![CDATA[intellij]]></category>
		<category><![CDATA[netbeans]]></category>
		<category><![CDATA[SCM]]></category>
		<category><![CDATA[tip]]></category>
		<category><![CDATA[xsolve]]></category>

		<guid isPermaLink="false">http://www.blog.project13.pl/?p=1076</guid>
		<description><![CDATA[As my team is using a kinda weird source eclipse code formatter setup, that other IDEs can&#8217;t emulate in 100% I sometimes found myself committing in a file with only a few changed spaces. Of course, I could use &#8220;external-formatter&#8221; plugins etc but that&#8217;s no good. Running eclipse&#8217;s formatter each time I want to format [...]]]></description>
			<content:encoded><![CDATA[<p>As my team is using a kinda weird source eclipse code formatter setup, that other IDEs can&#8217;t emulate in 100% I sometimes found myself committing in a file with only a few changed spaces. Of course, I could use &#8220;external-formatter&#8221; plugins etc but that&#8217;s no good. Running eclipse&#8217;s formatter each time I want to format my source (_very_ often) proved to be too slow and really getting on my nerves.</p>
<p>So&#8230; Since I&#8217;ve started using <strong>git</strong>-svn at work, I do have an possibility to make things better now! The answer lies in client-side-<strong>hooks</strong> and <strong>git aliases</strong> (&#8220;custom commands&#8221;). First let&#8217;s write this as an simple bash script, that we&#8217;ll locate in the <strong>.git/hooks/</strong> folder:<br />
<script src="https://gist.github.com/708972.js?file=gistfile1.sh"></script> It&#8217;s a fairly simple script, so I wont bore you explaining it in detail &#8211; if in doubt, feel free to ask. We only need to place this script as &#8220;<strong>.git/hooks/pre-commit</strong>&#8221; and make it executable and git will take care of the rest for us. Oh and in case you&#8217;re wondering where that <strong>org.eclipse.jdt.core.prefs</strong> came from. It&#8217;s created by eclipse into the .settings folder when you check some option to &#8220;use formatter per project&#8221; &#8211; that&#8217;s the only time I had to fire up and click around in eclipse to get it&#8217;s formatter running &#8220;headless&#8221;. Ok, let&#8217;s check if it works&#8230; <script src="https://gist.github.com/708982.js?file=gistfile1.java"></script><br />
<script src="https://gist.github.com/708976.js?file=gistfile1.sh"></script> <script src="https://gist.github.com/708981.js?file=gistfile1.java"></script><br />
Yup, you can agree or not with the formatting rules &#8211; but what matters is that the whole team decided on it and that we keep it consistent throughout the whole project. This hook will definitely help with this. :-)  Step two for me was changing this into a git command, so that I wouldn&#8217;t launch eclipse each time I just do some quick local commiting. The solution is to drop the hook idea (although it&#8217;s quite nice) and create an custom git command. We do this by doing an alias like that:</p>
<pre>git config --global alias.eclipse-formatter '!~/git-hook-eclipse-formatter'</pre>
<p>The <strong>!command </strong>alias<strong> </strong>support is with us in git since 1.5.0 and it enables us to launch any program/script as an git command. Great, just what I wanted! Let&#8217;s now see what this command really did:</p>
<p><script src="https://gist.github.com/708977.js?file=gistfile1.sh"></script><br />
As you can see, adding an alias is as simple as adding it to your<strong> ~/.gitconfig</strong> or, if you want to setup the alias &#8220;per project&#8221;, to <strong>.git/config</strong> &#8211; pretty cool, ay? Also, this command will be included in bash-autocompletition suggestions! :-)</p>
<p>That&#8217;s it for today&#8230; <em>happy hacking!</em></p>
]]></content:encoded>
			<wfw:commentRss>http://www.blog.project13.pl/index.php/fun/1076/git-hacking-pre-commit-hook-and-custom-command/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>[Terminal Heroes] sed mastery &#8211; group catching</title>
		<link>http://www.blog.project13.pl/index.php/terminal-heroes/884/terminal-heroes-sed-mastery-group-catching/</link>
		<comments>http://www.blog.project13.pl/index.php/terminal-heroes/884/terminal-heroes-sed-mastery-group-catching/#comments</comments>
		<pubDate>Sat, 09 Oct 2010 19:24:36 +0000</pubDate>
		<dc:creator>Ktoso</dc:creator>
				<category><![CDATA[java]]></category>
		<category><![CDATA[terminal heroes]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[sed]]></category>
		<category><![CDATA[shell]]></category>
		<category><![CDATA[terminal]]></category>

		<guid isPermaLink="false">http://www.blog.project13.pl/?p=884</guid>
		<description><![CDATA[Just a quick sed (the stream editor) example, as someone from work needed it a few minutes ago and I was more happy to supply an quick solution: # replace the href part &#91;ktoso@homunculus ~&#93;$ cat sedmastery &#160; &#160;&#60;a href=&#34;#&#34; id=&#34;hibernate&#34;&#62;Hibernate&#60;/a&#62; &#160; &#160;&#60;a href=&#34;#&#34; id=&#34;html&#34;&#62;HTML&#60;/a&#62; &#160; &#160;&#60;a href=&#34;#&#34; id=&#34;js&#34;&#62;JavaScript&#60;/a&#62; &#91;ktoso@homunculus ~&#93;$ sed &#39;s&#124;\([^#]*\)#\([^&#62;]*\)&#62;\([^&#60; ]*\)&#124;\1/\3\2&#62;\3&#124;g&#39; sedmastery [...]]]></description>
			<content:encoded><![CDATA[<p>Just a quick <strong>sed</strong> (the stream editor) example, as someone from work needed it a few minutes ago and I was more happy to supply an quick solution:</p>
<div class="geshi no bash">
<div class="head"># replace the href part</div>
<ol>
<li class="li1">
<div class="de1"><span class="br0">&#91;</span>ktoso<span class="sy0">@</span>homunculus ~<span class="br0">&#93;</span>$ <span class="kw2">cat</span> sedmastery</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="sy0">&lt;</span>a <span class="re2">href=</span><span class="st0">&quot;#&quot;</span> <span class="re2">id=</span><span class="st0">&quot;hibernate&quot;</span><span class="sy0">&gt;</span>Hibernate<span class="sy0">&lt;/</span>a<span class="sy0">&gt;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="sy0">&lt;</span>a <span class="re2">href=</span><span class="st0">&quot;#&quot;</span> <span class="re2">id=</span><span class="st0">&quot;html&quot;</span><span class="sy0">&gt;</span>HTML<span class="sy0">&lt;/</span>a<span class="sy0">&gt;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="sy0">&lt;</span>a <span class="re2">href=</span><span class="st0">&quot;#&quot;</span> <span class="re2">id=</span><span class="st0">&quot;js&quot;</span><span class="sy0">&gt;</span>JavaScript<span class="sy0">&lt;/</span>a<span class="sy0">&gt;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="br0">&#91;</span>ktoso<span class="sy0">@</span>homunculus ~<span class="br0">&#93;</span>$ <span class="kw2">sed</span> <span class="st0">&#39;s|<span class="es0">\(</span>[^#]*<span class="es0">\)</span>#<span class="es0">\(</span>[^&gt;]*<span class="es0">\)</span>&gt;<span class="es0">\(</span>[^&lt; ]*<span class="es0">\)</span>|<span class="es0">\1</span>/<span class="es0">\3</span><span class="es0">\2</span>&gt;<span class="es0">\3</span>|g&#39;</span> sedmastery</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="sy0">&lt;</span>a <span class="re2">href=</span><span class="st0">&quot;/Hibernate&quot;</span> <span class="re2">id=</span><span class="st0">&quot;hibernate&quot;</span><span class="sy0">&gt;</span>Hibernate<span class="sy0">&lt;/</span>a<span class="sy0">&gt;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="sy0">&lt;</span>a <span class="re2">href=</span><span class="st0">&quot;/HTML&quot;</span> <span class="re2">id=</span><span class="st0">&quot;html&quot;</span><span class="sy0">&gt;</span>HTML<span class="sy0">&lt;/</span>a<span class="sy0">&gt;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp;<span class="sy0">&lt;</span>a <span class="re2">href=</span><span class="st0">&quot;/JavaScript&quot;</span> <span class="re2">id=</span><span class="st0">&quot;js&quot;</span><span class="sy0">&gt;</span>JavaScript<span class="sy0">&lt;/</span>a<span class="sy0">&gt;</span></div>
</li>
</ol>
</div>
<p>Yup, that&#8217;s basically it. You may also apply this <strong>directly in vim</strong> <a href="http://www.youtube.com/watch?v=MzxEt9sK5eM" onclick="urchinTracker('/outgoing/www.youtube.com/watch?v=MzxEt9sK5eM&amp;referer=');">as I&#8217;ve showed here a few years ago</a> and you&#8217;ll probably need to <a href="http://www.ibm.com/developerworks/linux/library/l-sed2.html" onclick="urchinTracker('/outgoing/www.ibm.com/developerworks/linux/library/l-sed2.html?referer=');">look some stuff up here</a> or on this <a href="http://www.grymoire.com/Unix/Sed.html#uh-4" onclick="urchinTracker('/outgoing/www.grymoire.com/Unix/Sed.html_uh-4?referer=');">awesome sed guide</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.blog.project13.pl/index.php/terminal-heroes/884/terminal-heroes-sed-mastery-group-catching/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Creating an polish.dic for IntelliJ IDEA</title>
		<link>http://www.blog.project13.pl/index.php/coding/784/creating-an-polish-dic-for-intellij-idea/</link>
		<comments>http://www.blog.project13.pl/index.php/coding/784/creating-an-polish-dic-for-intellij-idea/#comments</comments>
		<pubDate>Sat, 28 Aug 2010 13:01:58 +0000</pubDate>
		<dc:creator>Ktoso</dc:creator>
				<category><![CDATA[coding]]></category>
		<category><![CDATA[english]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[polish]]></category>
		<category><![CDATA[terminal heroes]]></category>

		<guid isPermaLink="false">http://www.blog.project13.pl/?p=784</guid>
		<description><![CDATA[I&#8217;ve been coding a lot GWT/Android lately, and was using IntelliJ IDEA for this &#8211; a very nice IDE. (Yup, I&#8217;ve even got an personal license now). That said, the spellchecking is really important to me, sadly I couldnt find an ready do download polish.dic file which IntelliJ would then use to spellcheck our i18n [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been coding a lot GWT/Android lately, and was using IntelliJ IDEA for this &#8211; a very nice IDE. (Yup, I&#8217;ve even got an personal license now). That said, the<strong> spellchecking</strong> is really important to me, sadly I couldnt find an ready do download<strong> polish.dic</strong> file which IntelliJ would then use to spellcheck our<strong> i18n</strong> strings &#8211; bur fear not, hese is an cool one liner that will create such polish dictionary:</p>
<pre>aspell --lang pl dump master | aspell --lang pl expand | tr ' ' '\n' &gt; polish.dic</pre>
<p>You&#8217;ll have to install the polish aspell package of your distro of course before you launch this command ;-) Then just create an dedicated folder dor *.dic files and show IntelliJ to use it. Done &#8211; perfect spell checking in your IDE&#8230; and even while committing changes: <a href="http://blogs.jetbrains.com/idea/2010/08/no-more-misspellings-in-your-vcs-commit-comments/" onclick="urchinTracker('/outgoing/blogs.jetbrains.com/idea/2010/08/no-more-misspellings-in-your-vcs-commit-comments/?referer=');">http://blogs.jetbrains.com/idea/2010/08/no-more-misspellings-in-your-vcs-commit-comments/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.blog.project13.pl/index.php/coding/784/creating-an-polish-dic-for-intellij-idea/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Terminal Heroes 8: Memory usage scripts</title>
		<link>http://www.blog.project13.pl/index.php/coding/442/memory-usage-scripts/</link>
		<comments>http://www.blog.project13.pl/index.php/coding/442/memory-usage-scripts/#comments</comments>
		<pubDate>Wed, 24 Feb 2010 10:54:21 +0000</pubDate>
		<dc:creator>Ktoso</dc:creator>
				<category><![CDATA[coding]]></category>
		<category><![CDATA[terminal heroes]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[centos]]></category>
		<category><![CDATA[gnu]]></category>
		<category><![CDATA[gnu/linux]]></category>
		<category><![CDATA[shell]]></category>
		<category><![CDATA[terminal]]></category>
		<category><![CDATA[tricks]]></category>

		<guid isPermaLink="false">http://www.blog.project13.pl/?p=442</guid>
		<description><![CDATA[I have a low-memory VPS running online and thus always have to worry about what uses how much memory&#8230; Of course top and my favorite htop are very good tools to check this, but sometimes I just want to get a super simple report if I&#8217;m overusing memory or not yet. The bellow scripts (most [...]]]></description>
			<content:encoded><![CDATA[<p>I have a low-memory VPS running online and thus always have to worry about what uses how much memory&#8230; Of course top and my favorite <strong>htop</strong> are very good tools to check this, but sometimes I just want to get a super simple report if I&#8217;m overusing memory or not yet. The bellow scripts (most of them was found online or hacked up from multiple scripts to fit my needs) print simple yet very readable memory usage information.</p>
<h2>memused</h2>
<div class="geshi no bash">
<div class="head">#!/bin/bash</div>
<ol>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="co0">#if [ $1 = &#39;&#39;]; then</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co0">#    ps auxf | awk &#39;{sum=sum+$6}; END {print sum/1024}&#39;;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co0">#else</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co0">#    ps auxf | grep $1 | awk &#39;{sum=sum+$6}; END {print sum/1024}&#39;;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co0">#fi</span></div>
</li>
<li class="li1">
<div class="de1"><span class="re2">bean=</span>`<span class="kw2">cat</span> <span class="sy0">/</span>proc<span class="sy0">/</span>user_beancounters` <span class="re2">guar=</span>`<span class="kw3">echo</span> <span class="st0">&quot;$bean&quot;</span> <span class="sy0">|</span> <span class="kw2">grep</span> vmguar <span class="sy0">|</span> <span class="kw2">awk</span> <span class="st0">&#39;{ print $4;}&#39;</span>` <span class="re2">burst=</span>`<span class="kw3">echo</span> <span class="st0">&quot;$bean&quot;</span> <span class="sy0">|</span> <span class="kw2">grep</span> privvm <span class="sy0">|</span> <span class="kw2">awk</span> <span class="st0">&#39;{ print $5;}&#39;</span>` <span class="re2">priv=</span>`<span class="kw3">echo</span> <span class="st0">&quot;$bean&quot;</span> <span class="sy0">|</span> <span class="kw2">grep</span> privvm <span class="sy0">|</span> <span class="kw2">awk</span> <span class="st0">&#39;{ print $2;}&#39;</span>`</div>
</li>
<li class="li1">
<div class="de1"><span class="kw3">let</span> <span class="re2">total=</span>guar<span class="sy0">/</span><span class="nu0">256</span> <span class="kw3">let</span> <span class="re2">used=</span>priv<span class="sy0">/</span><span class="nu0">256</span> <span class="kw3">let</span> <span class="re2">burst=</span>burst<span class="sy0">/</span><span class="nu0">256</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw3">echo</span> <span class="st0">&quot;VPS memory usage:&quot;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw3">echo</span> <span class="st0">&quot;Used: $used MB&quot;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw3">echo</span> <span class="st0">&quot;Total: $total MB&quot;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw3">echo</span> <span class="st0">&quot;Burstable to: $burst MB&quot;</span></div>
</li>
</ol>
</div>
<p>Sample output:<br />
<code>VPS memory usage:<br />
Used: 296 MB<br />
Total: 256 MB<br />
Burstable to: 512 MB</code></p>
<h2>memfree</h2>
<div class="geshi no bash">
<div class="head">#!/bin/bash</div>
<ol>
<li class="li1">
<div class="de1"><span class="co0">#</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co0"># Revised 02-Feb-2007: include kernel memory (kmemsize) in &#39;used&#39; calculation</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co0"># and show percentages in output.</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co0">#</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="re2">BEAN=</span>`<span class="kw2">cat</span> <span class="sy0">/</span>proc<span class="sy0">/</span>user_beancounters`</div>
</li>
<li class="li1">
<div class="de1"><span class="re2">GUAR=</span>`<span class="kw3">echo</span> <span class="st0">&quot;$BEAN&quot;</span> <span class="sy0">|</span> <span class="kw2">grep</span> vmguar <span class="sy0">|</span> <span class="kw2">awk</span> <span class="st0">&#39;{ print $4;}&#39;</span>`</div>
</li>
<li class="li1">
<div class="de1"><span class="re2">PRIV=</span>`<span class="kw3">echo</span> <span class="st0">&quot;$BEAN&quot;</span> <span class="sy0">|</span> <span class="kw2">grep</span> privvm <span class="sy0">|</span> <span class="kw2">awk</span> <span class="st0">&#39;{ print $2;}&#39;</span>`</div>
</li>
<li class="li1">
<div class="de1"><span class="re2">KMEM=</span>`<span class="kw3">echo</span> <span class="st0">&quot;$BEAN&quot;</span> <span class="sy0">|</span> <span class="kw2">grep</span> kmem <span class="sy0">|</span> <span class="kw2">awk</span> <span class="st0">&#39;{ print $3;}&#39;</span>`</div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw3">let</span> <span class="re2">TOTL=</span><span class="re1">$GUAR</span><span class="sy0">/</span><span class="nu0">256</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw3">let</span> <span class="re2">KMMB=</span><span class="re1">$KMEM</span><span class="sy0">/</span><span class="nu0">1048576</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw3">let</span> <span class="re2">PVMB=</span><span class="re1">$PRIV</span><span class="sy0">/</span><span class="nu0">256</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw3">let</span> <span class="re2">USED=</span><span class="re1">$KMMB</span>+<span class="re1">$PVMB</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw3">let</span> <span class="re2">FREE=</span><span class="re1">$TOTL</span>-<span class="re1">$USED</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">if</span> <span class="br0">&#91;</span> <span class="st0">&quot;$FREE&quot;</span> -gt <span class="st0">&quot;0&quot;</span> <span class="br0">&#93;</span>; <span class="kw1">then</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw3">let</span> <span class="re2">UPER=</span><span class="re1">$USED</span><span class="sy0">*</span><span class="nu0">100</span><span class="sy0">/</span><span class="re1">$TOTL</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw3">let</span> <span class="re2">FPER=</span><span class="nu0">100</span>-<span class="re1">$UPER</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">else</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw3">let</span> <span class="re2">UPER=</span><span class="st0">&quot;100&quot;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; <span class="kw3">let</span> <span class="re2">FPER=</span><span class="st0">&quot;0&quot;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">fi</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw3">echo</span> <span class="st0">&quot;VPS Memory:&quot;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw3">echo</span> <span class="st0">&quot; Total: $TOTL mb Used: $USED mb (${UPER}%) Free: $FREE mb (${FPER}%)&quot;</span></div>
</li>
</ol>
</div>
<p>Sample output:<br />
<code>VPS Memory:<br />
Total: 256 mb Used: 302 mb (100%) Free: -46 mb (0%)</code></p>
<h2>memheld</h2>
<div class="geshi no bash">
<div class="head">#!/bin/bash</div>
<ol>
<li class="li1">
<div class="de1"><span class="kw2">grep</span> oomguarpages <span class="sy0">/</span>proc<span class="sy0">/</span>user_beancounters <span class="sy0">|</span> <span class="kw2">awk</span> <span class="st0">&#39;{s=$2;t=$3;u=$4; {print &quot;VPS Memory Usage<span class="es0">\n</span>Current Held: &quot; s/256 &quot;MB<span class="es0">\n</span>Max Held: &quot; t/256 &quot;MB<span class="es0">\n</span>Barrier: &quot;u/256&quot;MB&quot; }}&#39;</span></div>
</li>
</ol>
</div>
<p>Sample output:<br />
<code>VPS Memory Usage<br />
Current Held: 160.832MB<br />
Max Held: 294.605MB<br />
Barrier: 256MB</code></p>
<h2>memps</h2>
<div class="geshi no bash">
<div class="head">#!/bin/bash</div>
<ol>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw3">echo</span> <span class="st0">&quot;ps axo pmem,pcpu,comm | sort&quot;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">ps</span> axo pmem,pcpu,<span class="kw2">comm</span> <span class="sy0">|</span> <span class="kw2">sort</span></div>
</li>
</ol>
</div>
<p>Sample output:<br />
<code>ps axo pmem,pcpu,comm | sort<br />
0.0  0.0 script<br />
0.0  0.0 script<br />
0.1  0.0 init<br />
#...<br />
2.2  0.0 httpd<br />
4.0  0.0 mysqld<br />
7.3  0.0 httpd<br />
8.0  0.0 httpd<br />
%MEM %CPU COMMAND</code></p>
<h2>memprivmpages</h2>
<div class="geshi no bash">
<div class="head">#!/bin/bash</div>
<ol>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="re2">beans=</span>`<span class="kw2">cat</span> <span class="sy0">/</span>proc<span class="sy0">/</span>user_beancounters <span class="sy0">|</span> <span class="kw2">grep</span> priv`</div>
</li>
<li class="li1">
<div class="de1"><span class="re2">max=</span>`<span class="kw3">echo</span> <span class="re1">$beans</span> <span class="sy0">|</span> <span class="kw2">awk</span> <span class="st0">&#39;{ print $4;}&#39;</span>`</div>
</li>
<li class="li1">
<div class="de1"><span class="re2">use=</span>`<span class="kw3">echo</span> <span class="re1">$beans</span> <span class="sy0">|</span> <span class="kw2">awk</span> <span class="st0">&#39;{ print $2;}&#39;</span>`</div>
</li>
<li class="li1">
<div class="de1"><span class="kw3">let</span> <span class="st0">&quot;per=$use*100/$max&quot;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw3">let</span> <span class="st0">&quot;mb=$use/256&quot;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="kw3">let</span> <span class="st0">&quot;mmb=$max/256&quot;</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw3">echo</span> <span class="st0">&quot;privvmpages usage: $mb MB ($per% of $mmb)&quot;</span></div>
</li>
</ol>
</div>
<p>Sample output:<br />
<code>privvmpages usage: 296 MB (57% of 512)</code><br />
For those wondering, yes I do have memory usage <em>above &#8220;100%&#8221; </em>in the output of some of these scripts, and it&#8217;s partially true. A VPS does usually have some guaranteed memory, and some &#8220;burstable&#8221; &#8211; so you can use more than just the guaranteed memory for some period of time. On the mashine I ran this I have 256 guaranteed and a &#8220;total&#8221; of 512MB &#8211; including the burstable memory.</p>
<p>If you like any of these, feel free to use them. I use them by creating a scripts directory and adding it to the PATH, so I can simply invoke them from anywhere.</p>
<p>PS: For more <strong>detailed memory usage information</strong> (as graphs etc), I&#8217;m using <a href="http://munin.projects.linpro.no/" onclick="urchinTracker('/outgoing/munin.projects.linpro.no/?referer=');"><strong>Munin</strong></a> and really recommend it. The graphs it draws are really nice, and it <strong>doesn&#8217;t</strong> inflict heavy load on the server, and it can <strong>monitor remote hosts</strong> if needed!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.blog.project13.pl/index.php/coding/442/memory-usage-scripts/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>(Almost) Automatically convert files into PDF</title>
		<link>http://www.blog.project13.pl/index.php/fun/285/almost-automatically-convert-files-into-pdf/</link>
		<comments>http://www.blog.project13.pl/index.php/fun/285/almost-automatically-convert-files-into-pdf/#comments</comments>
		<pubDate>Mon, 16 Nov 2009 00:56:55 +0000</pubDate>
		<dc:creator>Ktoso</dc:creator>
				<category><![CDATA[coding]]></category>
		<category><![CDATA[freedom]]></category>
		<category><![CDATA[fun]]></category>
		<category><![CDATA[terminal heroes]]></category>
		<category><![CDATA[cool]]></category>
		<category><![CDATA[gnu]]></category>
		<category><![CDATA[gnu/linux]]></category>
		<category><![CDATA[hack]]></category>
		<category><![CDATA[hacking]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[shell]]></category>
		<category><![CDATA[terminal]]></category>
		<category><![CDATA[tip]]></category>
		<category><![CDATA[trick]]></category>
		<category><![CDATA[tricks]]></category>
		<category><![CDATA[wget]]></category>

		<guid isPermaLink="false">http://www.blog.project13.pl/?p=285</guid>
		<description><![CDATA[I&#8217;m learning Numerical Analysis right now and a friend of mine found some really nice PS files by dr Marian Bubek ( http://www.icsr.agh.edu.pl/~mownit/mownit.html ). I was really happy to see some *.ps but some people from my fellow students started complaining that they&#8217;d rather have pdf&#8217;s and not ghostscript files (who knows why they&#8217;d do..?). [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m learning Numerical Analysis right now and a friend of mine found some really nice PS files by dr Marian Bubek ( <a href="http://www.icsr.agh.edu.pl/~mownit/mownit.html" onclick="urchinTracker('/outgoing/www.icsr.agh.edu.pl/_mownit/mownit.html?referer=');">http://www.icsr.agh.edu.pl/~mownit/mownit.html</a> ). I was really happy to see some *.ps but some people from my fellow students started complaining that they&#8217;d rather have pdf&#8217;s and not ghostscript files <em>(who knows why they&#8217;d do..?)</em>. Anyways, they all had &#8220;manual&#8221; repetitious methods for converting the files &#8211; even uploading to somewebsite to have them converted over there &#8220;in the cloud&#8221;&#8230; I though of a slightly quicker and more efficient way, here it is, hope you&#8217;ll like it. Ah, there is One &#8220;non standard&#8221; requirement for this to work, you have to install <strong>cups-pdf</strong> :-)</p>
<div class="geshi no bash">
<div class="head">wget http://www.icsr.agh.edu.pl/~mownit/mownit.html -r &#8211;level 1 -A.ps &#8211;cut-dirs 4</div>
<ol>
<li class="li1">
<div class="de1"><span class="kw2">mv</span> www.icsr.agh.edu.pl<span class="sy0">/*</span> .</div>
</li>
<li class="li1">
<div class="de1"><span class="kw2">rm</span> -rf www.icsr.agh.edu.pl<span class="sy0">/</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">for</span> <span class="kw2">file</span> <span class="kw1">in</span> `<span class="kw2">dir</span> -f <span class="sy0">*</span>` ; <span class="kw1">do</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp;<span class="kw2">lpr</span> -P <span class="st0">&#39;cups-PDF&#39;</span> <span class="re1">$file</span>;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp;<span class="kw3">echo</span> <span class="st0">&quot;press enter when cups is done printing&#8230;&quot;</span> <span class="co0">#yeah, i got lazy here, one could watch lpq for changes etc.</span></div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp;<span class="kw2">read</span> oczekiwanie;</div>
</li>
<li class="li1">
<div class="de1">&nbsp; &nbsp; &nbsp;<span class="kw2">mv</span> <span class="sy0">/</span>home<span class="sy0">/</span>ktoso<span class="sy0">/</span>Pulpit<span class="sy0">/</span>cups-pdf<span class="sy0">/</span>template.pdf .<span class="sy0">/</span><span class="re1">$file</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="kw1">done</span>;</div>
</li>
<li class="li1">
<div class="de1"><span class="co0"># ________________ </span></div>
</li>
<li class="li1">
<div class="de1"><span class="co0">#&lt; Happy hacking! &gt;</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co0"># &#8212;&#8212;&#8212;&#8212;&#8212;- </span></div>
</li>
<li class="li1">
<div class="de1"><span class="co0"># &nbsp; &nbsp; &nbsp; &nbsp;\ &nbsp; ^__^</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co0"># &nbsp; &nbsp; &nbsp; &nbsp; \ &nbsp;(oo)\_______</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co0"># &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;(__)\ &nbsp; &nbsp; &nbsp; )\/\</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co0"># &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;||&#8212;-w |</span></div>
</li>
<li class="li1">
<div class="de1"><span class="co0"># &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;|| &nbsp; &nbsp; ||</span></div>
</li>
</ol>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.blog.project13.pl/index.php/fun/285/almost-automatically-convert-files-into-pdf/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

