<?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>Think In Geek</title>
	<atom:link href="http://thinkingeek.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://thinkingeek.com</link>
	<description>In geek we trust</description>
	<lastBuildDate>Wed, 01 Feb 2012 14:45:59 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Give your Ruby console a dash of colour</title>
		<link>http://thinkingeek.com/2012/02/01/give-ruby-console-dash-colour/</link>
		<comments>http://thinkingeek.com/2012/02/01/give-ruby-console-dash-colour/#comments</comments>
		<pubDate>Wed, 01 Feb 2012 14:45:59 +0000</pubDate>
		<dc:creator>brafales</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[irb]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[ruby on rails]]></category>
		<category><![CDATA[wirble]]></category>

		<guid isPermaLink="false">http://thinkingeek.com/?p=232</guid>
		<description><![CDATA[When you&#8217;re developing an application in Rails (or Ruby), you spend lots of time in the IRB, the Interactive Ruby Shell. Usually just to test some Ruby code, start an application console or debug something going on inside the project. Yesterday, looking at a coworker screen, I saw he had his console with lots of [...]]]></description>
			<content:encoded><![CDATA[<p>
When you&#8217;re developing an application in Rails (or Ruby), you spend lots of time in the <em>IRB</em>, the Interactive Ruby Shell. Usually just to test some Ruby code, start an application console or debug something going on inside the project. Yesterday, looking at a coworker screen, I saw he had his console with lots of color hints, and I thought it was pretty nice. I asked him about that and he told me he was using a special gem for that.
</p>
<p>
The gem is called <a href="http://pablotron.org/software/wirble/" onclick="pageTracker._trackPageview('/outgoing/pablotron.org/software/wirble/?referer=');">wirble</a>. It has some nice defaults and allows you to configure the colors as you wish. To use it in your consoles, just add this lines to your <code>~/.irbrc</code> file:
</p>
<p>
<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">begin</span>
  <span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'rubygems'</span>
  <span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'wirble'</span>
  Wirble.<span style="color:#9900CC;">init</span>
  Wirble.<span style="color:#9900CC;">colorize</span>
<span style="color:#9966CC; font-weight:bold;">rescue</span> <span style="color:#CC00FF; font-weight:bold;">LoadError</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> err
  warn <span style="color:#996600;">&quot;Couldn't load Wirble: #{err}&quot;</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

</p>
<p>
Of course, you&#8217;ll need to install the gem. Just issue a <code>gem install wirble</code> and you&#8217;ll be good to go!</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fthinkingeek.com%2F2012%2F02%2F01%2Fgive-ruby-console-dash-colour%2F&amp;title=Give%20your%20Ruby%20console%20a%20dash%20of%20colour" id="wpa2a_2" onclick="pageTracker._trackPageview('/outgoing/www.addtoany.com/share_save_url=http_3A_2F_2Fthinkingeek.com_2F2012_2F02_2F01_2Fgive-ruby-console-dash-colour_2F_amp_title=Give_20your_20Ruby_20console_20a_20dash_20of_20colour?referer=');"><img src="http://thinkingeek.com/wp-content/plugins/add-to-any/share_save_120_16.gif" width="120" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://thinkingeek.com/2012/02/01/give-ruby-console-dash-colour/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Fix Java GUI applications in xmonad</title>
		<link>http://thinkingeek.com/2012/01/24/fix-java-gui-applications-xmonad/</link>
		<comments>http://thinkingeek.com/2012/01/24/fix-java-gui-applications-xmonad/#comments</comments>
		<pubDate>Tue, 24 Jan 2012 15:00:12 +0000</pubDate>
		<dc:creator>brafales</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[gui]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[ruby on rails]]></category>
		<category><![CDATA[rubymine]]></category>
		<category><![CDATA[xmonad]]></category>

		<guid isPermaLink="false">http://thinkingeek.com/?p=228</guid>
		<description><![CDATA[If you ever try to run a GUI Java application when using xmonad as the Window Manager, you&#8217;ll probably end up with a nice flat grey window where your buttons, toolbars and other desktop GUI goodies should be. I ran into that problem the other day when trying to evaluate the RubyMine Ruby on Rails [...]]]></description>
			<content:encoded><![CDATA[<p>
If you ever try to run a GUI Java application when using <a href="http://www.xmonad.org" onclick="pageTracker._trackPageview('/outgoing/www.xmonad.org?referer=');">xmonad</a> as the Window Manager, you&#8217;ll probably end up with a nice flat grey window where your buttons, toolbars and other desktop GUI goodies should be. I ran into that problem the other day when trying to evaluate the <a href="http://www.jetbrains.com/ruby/" onclick="pageTracker._trackPageview('/outgoing/www.jetbrains.com/ruby/?referer=');">RubyMine Ruby on Rails IDE</a> from which I heard such good things. After a rather painful installation of the official Java 6 JDK from Oracle in Ubuntu Lucid Lynx (which I&#8217;ll write about in some other time), I managed to start up RubyMine just to find out I was seeing absolutely nothing on the screen.
</p>
<p>
I Googled a bit and essentially I found out that the problem was with the Java GUI Toolkit rather than RubyMine, because <a href="http://www.haskell.org/haskellwiki/Xmonad/Frequently_asked_questions#Problems_with_Java_applications.2C_Applet_java_console" onclick="pageTracker._trackPageview('/outgoing/www.haskell.org/haskellwiki/Xmonad/Frequently_asked_questions_Problems_with_Java_applications.2C_Applet_java_console?referer=');">the framework relies on a list of window managers to handle some things, and xmonad is not in that list</a>.
</p>
<p>
So since I was not using OpenJDK, I opted for the <code>setWMName</code> option and added this final line into my <code>xmonad.hs</code> file:</p>

<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;">    xmonad <span style="color: #339933; font-weight: bold;">$</span> defaultConfig
      <span style="color: green;">&#123;</span> terminal            <span style="color: #339933; font-weight: bold;">=</span> myTerminal
      <span style="color: #339933; font-weight: bold;">,</span> workspaces          <span style="color: #339933; font-weight: bold;">=</span> myWorkspaces
      <span style="color: #339933; font-weight: bold;">,</span> keys                <span style="color: #339933; font-weight: bold;">=</span> keys'
      <span style="color: #339933; font-weight: bold;">,</span> modMask             <span style="color: #339933; font-weight: bold;">=</span> modMask'
      <span style="color: #339933; font-weight: bold;">,</span> layoutHook          <span style="color: #339933; font-weight: bold;">=</span> layoutHook'
      <span style="color: #339933; font-weight: bold;">,</span> manageHook          <span style="color: #339933; font-weight: bold;">=</span> manageHook'
      <span style="color: #339933; font-weight: bold;">,</span> logHook             <span style="color: #339933; font-weight: bold;">=</span> myLogHook dzenLeftBar <span style="color: #339933; font-weight: bold;">&gt;&gt;</span> fadeInactiveLogHook 0xdddddddd
      <span style="color: #339933; font-weight: bold;">,</span> normalBorderColor   <span style="color: #339933; font-weight: bold;">=</span> colorNormalBorder
      <span style="color: #339933; font-weight: bold;">,</span> focusedBorderColor  <span style="color: #339933; font-weight: bold;">=</span> colorFocusedBorder
      <span style="color: #339933; font-weight: bold;">,</span> borderWidth         <span style="color: #339933; font-weight: bold;">=</span> <span style="color: red;">2</span>
      <span style="color: #339933; font-weight: bold;">,</span> startupHook         <span style="color: #339933; font-weight: bold;">=</span> setWMName <span style="background-color: #3cb371;">&quot;LG3D&quot;</span>
<span style="color: green;">&#125;</span></pre></div></div>

</p>
<p>
Setting the window manager name to <em>LG3D</em> will trick the Java GUI Toolkit and the application will be painted correctly.
</p>
<p>
Enjoy your Java applications with the power of xmonad!</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fthinkingeek.com%2F2012%2F01%2F24%2Ffix-java-gui-applications-xmonad%2F&amp;title=Fix%20Java%20GUI%20applications%20in%20xmonad" id="wpa2a_4" onclick="pageTracker._trackPageview('/outgoing/www.addtoany.com/share_save_url=http_3A_2F_2Fthinkingeek.com_2F2012_2F01_2F24_2Ffix-java-gui-applications-xmonad_2F_amp_title=Fix_20Java_20GUI_20applications_20in_20xmonad?referer=');"><img src="http://thinkingeek.com/wp-content/plugins/add-to-any/share_save_120_16.gif" width="120" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://thinkingeek.com/2012/01/24/fix-java-gui-applications-xmonad/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ruby on Rails Many To Many associations with multiple databases</title>
		<link>http://thinkingeek.com/2012/01/24/ruby-rails-associations-multiple-databases/</link>
		<comments>http://thinkingeek.com/2012/01/24/ruby-rails-associations-multiple-databases/#comments</comments>
		<pubDate>Tue, 24 Jan 2012 12:54:53 +0000</pubDate>
		<dc:creator>brafales</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[activerecord]]></category>
		<category><![CDATA[databases]]></category>
		<category><![CDATA[github]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[ruby on rails]]></category>

		<guid isPermaLink="false">http://thinkingeek.com/?p=220</guid>
		<description><![CDATA[Sometimes you need to use multiple databases in your Rails projects. Usually when some data must be shared between different applications. When this happens you usually have some models in a shared database, and some other models in the specific application database. This can be easily done using the establish_connection method in the shared models [...]]]></description>
			<content:encoded><![CDATA[<p>
Sometimes you need to use multiple databases in your Rails projects. Usually when some data must be shared between different applications. When this happens you usually have some models in a shared database, and some other models in the specific application database. This can be easily done using the <a href="http://apidock.com/rails/ActiveRecord/Base/establish_connection/class" onclick="pageTracker._trackPageview('/outgoing/apidock.com/rails/ActiveRecord/Base/establish_connection/class?referer=');">establish_connection</a> method in the shared models to tell them they have to connect to a different database.
</p>
<p>
However, when you need some interaction between those <em>shared models</em> and the models of your specific application, like a <a href="http://apidock.com/rails/ActiveRecord/Associations/ClassMethods/has_many" onclick="pageTracker._trackPageview('/outgoing/apidock.com/rails/ActiveRecord/Associations/ClassMethods/has_many?referer=');">has_many, :through</a> association, some problems arise. The typical <em>Many To Many</em> association uses an intermediate database table that links the relation between two models, and allows you to add some extra information on that relation. When navigating through the association, Rails tries to make an SQL query that joins the model with this intermediate table. For example, imagine you have a <em>Team</em> model, which has many <em>Players</em>, but a player can also be on more than one team. We use an intermediate model <em>TeamPlayers</em> (and we can also use it to save the role of that player into that team, for example). You would have those three tables:</p>
<ul>
<li>teams</li>
<li>players</li>
<li>teams_players</li>
</ul>
<p>When asking for the players of a given Team, Rails would do something similar to this:</p>

<div class="wp_syntax"><div class="code"><pre class="sql" style="font-family:monospace;"><span style="color: #993333; font-weight: bold;">SELECT</span> <span style="color: #ff0000;">&quot;players&quot;</span><span style="color: #66cc66;">.*</span> <span style="color: #993333; font-weight: bold;">FROM</span> <span style="color: #ff0000;">&quot;players&quot;</span> <span style="color: #993333; font-weight: bold;">INNER</span> <span style="color: #993333; font-weight: bold;">JOIN</span> teams_players<span style="color: #ff0000;">&quot; ON &quot;</span>players<span style="color: #ff0000;">&quot;.id = &quot;</span>teams_players<span style="color: #ff0000;">&quot;.player_id WHERE &quot;</span>players<span style="color: #ff0000;">&quot;.team_id = 1</span></pre></div></div>

<p>Where <code>1</code> is the <em>id</em> of the team you asked for. This [obviously] works perfectly fine when everything is in the same database, and it&#8217;s as efficient as the SQL database manager you&#8217;re using. What happens, however, when we have the Player model in another database? It will miserably fail because Rails will try to join with a  table that doesn&#8217;t exist.
</p>
<p>
Unfortunately, there&#8217;s no efficient way to solve this problem, that is, using SQL, as you can&#8217;t work with tables from different databases. However, there&#8217;s a rather elegant solution that <a href="http://emphaticsolutions.com/2009/11/23/has_many_through_across_databases.html" onclick="pageTracker._trackPageview('/outgoing/emphaticsolutions.com/2009/11/23/has_many_through_across_databases.html?referer=');">Brian Doll</a> cared to implement as a <a href="https://github.com/briandoll/st-elsewhere" onclick="pageTracker._trackPageview('/outgoing/github.com/briandoll/st-elsewhere?referer=');">gem</a> a while ago. As indicated in the GitHub readme, you just have to use a <code>has_many_elsewhere</code> relation instead of the usual one, and make sure that the model referenced has the connection established to the shared database. And that&#8217;s all.
</p>
<p>
The <em>magic</em> donde behind the scenes is pretty simple: this gem just replicates the same methods that the <code>ActiveRecord::Base</code> class does in the <em>has_many</em> method call, changing the failing unique SQL calls to double SQL calls, one for each database, fetching the intermediate models first, and then fetching the remote models using those ids.
</p>
<p>
This method is not perfect, as probably not all the goodness of the original association can be done with it, but for simple scenarios is more than enough.</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fthinkingeek.com%2F2012%2F01%2F24%2Fruby-rails-associations-multiple-databases%2F&amp;title=Ruby%20on%20Rails%20Many%20To%20Many%20associations%20with%20multiple%20databases" id="wpa2a_6" onclick="pageTracker._trackPageview('/outgoing/www.addtoany.com/share_save_url=http_3A_2F_2Fthinkingeek.com_2F2012_2F01_2F24_2Fruby-rails-associations-multiple-databases_2F_amp_title=Ruby_20on_20Rails_20Many_20To_20Many_20associations_20with_20multiple_20databases?referer=');"><img src="http://thinkingeek.com/wp-content/plugins/add-to-any/share_save_120_16.gif" width="120" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://thinkingeek.com/2012/01/24/ruby-rails-associations-multiple-databases/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Creating your own Job Managers in Ubiquo</title>
		<link>http://thinkingeek.com/2011/12/02/creating-job-managers-ubiquo/</link>
		<comments>http://thinkingeek.com/2011/12/02/creating-job-managers-ubiquo/#comments</comments>
		<pubDate>Fri, 02 Dec 2011 11:00:02 +0000</pubDate>
		<dc:creator>brafales</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[ruby on rails]]></category>
		<category><![CDATA[ubiquo]]></category>

		<guid isPermaLink="false">http://thinkingeek.com/?p=203</guid>
		<description><![CDATA[Ubiquo is a Ruby on Rails, MIT Licensed Open Source CMS we develop and use at gnuine for a variety of projects. One of the features of Ubiquo is the ability to run jobs separately from the http requests to the site. Today I&#8217;m going to show you how to customize the Ubiquo Jobs plugin [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.ubiquo.me" onclick="pageTracker._trackPageview('/outgoing/www.ubiquo.me?referer=');">Ubiquo</a> is a <a href="http://rubyonrails.org/" onclick="pageTracker._trackPageview('/outgoing/rubyonrails.org/?referer=');">Ruby on Rails</a>, <a href="http://www.opensource.org/licenses/mit-license.php" onclick="pageTracker._trackPageview('/outgoing/www.opensource.org/licenses/mit-license.php?referer=');">MIT Licensed</a> Open Source <a href="http://en.wikipedia.org/wiki/Content_management_system" onclick="pageTracker._trackPageview('/outgoing/en.wikipedia.org/wiki/Content_management_system?referer=');">CMS</a> we develop and use at <a href="http://www.gnuine.com" onclick="pageTracker._trackPageview('/outgoing/www.gnuine.com?referer=');">gnuine</a> for a variety of projects. One of the features of Ubiquo is the ability to run jobs separately from the http requests to the site. Today I&#8217;m going to show you how to customize the Ubiquo Jobs plugin to create your own types of jobs and managers to launch them.</p>
<p>Sometimes can be useful to create different managers. An example of this situation is when you want to run different kind of jobs in different circumstances.</p>
<p>Ubiquo Jobs provides a default manager which will get <tt>ActiveJob</tt> jobs depending on priorities and schedule times:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">def</span> <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">get</span><span style="color:#006600; font-weight:bold;">&#40;</span>runner<span style="color:#006600; font-weight:bold;">&#41;</span>
  recovery<span style="color:#006600; font-weight:bold;">&#40;</span>runner<span style="color:#006600; font-weight:bold;">&#41;</span>
  candidate_jobs = job_class.<span style="color:#9900CC;">all</span><span style="color:#006600; font-weight:bold;">&#40;</span>
    <span style="color:#ff3333; font-weight:bold;">:conditions</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#91;</span>
      <span style="color:#996600;">'planified_at &lt;= ? AND state = ?'</span>,
      <span style="color:#CC00FF; font-weight:bold;">Time</span>.<span style="color:#9900CC;">now</span>.<span style="color:#9900CC;">utc</span>,
      <span style="color:#6666ff; font-weight:bold;">UbiquoJobs::Jobs::Base::STATES</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:waiting</span><span style="color:#006600; font-weight:bold;">&#93;</span>
    <span style="color:#006600; font-weight:bold;">&#93;</span>,
    <span style="color:#ff3333; font-weight:bold;">:order</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'priority asc'</span>
  <span style="color:#006600; font-weight:bold;">&#41;</span>
  job = first_without_dependencies<span style="color:#006600; font-weight:bold;">&#40;</span>candidate_jobs<span style="color:#006600; font-weight:bold;">&#41;</span>
  job.<span style="color:#9900CC;">update_attributes</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#123;</span>
      <span style="color:#ff3333; font-weight:bold;">:state</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#6666ff; font-weight:bold;">UbiquoJobs::Jobs::Base::STATES</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:instantiated</span><span style="color:#006600; font-weight:bold;">&#93;</span>,
      <span style="color:#ff3333; font-weight:bold;">:runner</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> runner
    <span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">if</span> job
  job
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>The <tt>job_class</tt> variable defaults to <tt>UbiquoJobs::Jobs::ActiveJob</tt>. If you want to make your own manager to handle special jobs, or change the way the jobs are picked, the best way to do so is to implement your own manager. A nice rails-like way to do that is include them in the <tt>lib/</tt> folder of your ubiquo project.<br />
The class you should inherit from is <tt>UbiquoJobs::Managers::ActiveManager</tt>. If you wanted the manager to just pick up a specific subclass of ubiquo jobs, it would suffice to reimplement the <tt>self.job_class</tt> class method to return your own kind of job:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">def</span> <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">job_class</span>
  <span style="color:#6666ff; font-weight:bold;">UbiquoJobs::Jobs::YourJobClass</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>However, there&#8217;s a better way to do this. For this special case, the default <tt>UbiquoJob</tt> class provides a special member which stores the job&#8217;s class name, allowing you to select all objects subclasses of <tt>ActiveJob</tt> by its classname. For example, imagine you have a kind of job for special tasks that you know for sure will take a long time to complete. Seems reasonable to have a different manager to handle those jobs. You would create a new job in the file <tt>app/jobs/very_long_job.rb</tt>:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">class</span> VeryLongJob <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#6666ff; font-weight:bold;">UbiquoJobs::Jobs::ActiveJob</span>
  <span style="color:#9966CC; font-weight:bold;">def</span> do_job_work
    <span style="color:#008000; font-style:italic;">#Do what needs to be done here</span>
    <span style="color:#0000FF; font-weight:bold;">return</span> <span style="color:#006666;">0</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>Then you could create a manager that handles only those kind of jobs by implementing your own subclass of the <tt>UbiquoJobs::Managers::ActiveManager</tt> class:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">module</span> JobManagers
  <span style="color:#9966CC; font-weight:bold;">class</span> VeryLongJobManager <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#6666ff; font-weight:bold;">UbiquoJobs::Managers::ActiveManager</span>
    <span style="color:#9966CC; font-weight:bold;">def</span> <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">get</span><span style="color:#006600; font-weight:bold;">&#40;</span>runner<span style="color:#006600; font-weight:bold;">&#41;</span>
      recovery<span style="color:#006600; font-weight:bold;">&#40;</span>runner<span style="color:#006600; font-weight:bold;">&#41;</span>
      candidate_jobs = job_class.<span style="color:#9900CC;">all</span><span style="color:#006600; font-weight:bold;">&#40;</span>
        <span style="color:#ff3333; font-weight:bold;">:conditions</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#91;</span>
          <span style="color:#996600;">'planified_at &lt;= ? AND state = ? AND type = ?'</span>, 
          <span style="color:#CC00FF; font-weight:bold;">Time</span>.<span style="color:#9900CC;">now</span>.<span style="color:#9900CC;">utc</span>,
          <span style="color:#6666ff; font-weight:bold;">UbiquoJobs::Jobs::Base::STATES</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:waiting</span><span style="color:#006600; font-weight:bold;">&#93;</span>,
          <span style="color:#996600;">'VeryLongJob'</span>
        <span style="color:#006600; font-weight:bold;">&#93;</span>,
        <span style="color:#ff3333; font-weight:bold;">:order</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'priority asc'</span>
      <span style="color:#006600; font-weight:bold;">&#41;</span>
      job = first_without_dependencies<span style="color:#006600; font-weight:bold;">&#40;</span>candidate_jobs<span style="color:#006600; font-weight:bold;">&#41;</span>
      job.<span style="color:#9900CC;">update_attributes</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#123;</span>
          <span style="color:#ff3333; font-weight:bold;">:state</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#6666ff; font-weight:bold;">UbiquoJobs::Jobs::Base::STATES</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:instantiated</span><span style="color:#006600; font-weight:bold;">&#93;</span>,
          <span style="color:#ff3333; font-weight:bold;">:runner</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> runner
        <span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">if</span> job
      job
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>The code is exactly the same as the default <tt>ActiveManager</tt> class, but the finder will take an extra parameter, <tt>'VeryLongJob'</tt>, to indicate that only the <tt>ActiveJob</tt> objects that are of the subclass <tt>VerylongJob</tt> should be taken.</p>
<p>After that, you need to modify the task that calls the workers so it takes your manager, or create a new task that will run your manager. The default task that will<br />
start a worker looks as this:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">desc <span style="color:#996600;">&quot;Starts a new ubiquo worker&quot;</span>
task <span style="color:#ff3333; font-weight:bold;">:start</span>, <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:name</span>, <span style="color:#ff3333; font-weight:bold;">:interval</span><span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:environment</span><span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>t, args<span style="color:#006600; font-weight:bold;">|</span>
  options = <span style="color:#006600; font-weight:bold;">&#123;</span>
    <span style="color:#ff3333; font-weight:bold;">:sleep_time</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> args.<span style="color:#9900CC;">interval</span>.<span style="color:#9900CC;">to_f</span>
  <span style="color:#006600; font-weight:bold;">&#125;</span>.<span style="color:#9900CC;">delete_if</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#006600; font-weight:bold;">|</span>k,v<span style="color:#006600; font-weight:bold;">|</span> v.<span style="color:#9900CC;">blank</span>? <span style="color:#006600; font-weight:bold;">&#125;</span>
  UbiquoWorker.<span style="color:#9900CC;">init</span><span style="color:#006600; font-weight:bold;">&#40;</span>args.<span style="color:#9900CC;">name</span>, options<span style="color:#006600; font-weight:bold;">&#41;</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>This uses a special configuration parameter to determine the manager to use. This configuration option is stored in <tt>Ubiquo::Config.context(:ubiquo_jobs)</tt>, the name of the configuration option is <tt>:job_manager_class</tt>, and takes the manager class as a value. So in order to create a task that will use your manager, you should create a new task like this one:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">desc <span style="color:#996600;">&quot;Starts a new ubiquo worker&quot;</span>
task <span style="color:#ff3333; font-weight:bold;">:start_very_long_jobs</span>, <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:name</span>, <span style="color:#ff3333; font-weight:bold;">:interval</span><span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:environment</span><span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>t, args<span style="color:#006600; font-weight:bold;">|</span>
  options = <span style="color:#006600; font-weight:bold;">&#123;</span>
    <span style="color:#ff3333; font-weight:bold;">:sleep_time</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> args.<span style="color:#9900CC;">interval</span>.<span style="color:#9900CC;">to_f</span>
  <span style="color:#006600; font-weight:bold;">&#125;</span>.<span style="color:#9900CC;">delete_if</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#006600; font-weight:bold;">|</span>k,v<span style="color:#006600; font-weight:bold;">|</span> v.<span style="color:#9900CC;">blank</span>? <span style="color:#006600; font-weight:bold;">&#125;</span>
  <span style="color:#6666ff; font-weight:bold;">Ubiquo::Config</span>.<span style="color:#9900CC;">context</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:ubiquo_jobs</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">set</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:job_manager_class</span>, <span style="color:#6666ff; font-weight:bold;">JobManagers::VeryLongJobManager</span><span style="color:#006600; font-weight:bold;">&#41;</span>
  UbiquoWorker.<span style="color:#9900CC;">init</span><span style="color:#006600; font-weight:bold;">&#40;</span>args.<span style="color:#9900CC;">name</span>, options<span style="color:#006600; font-weight:bold;">&#41;</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>Your should call this task like this (assuming it&#8217;s on the same namespace as the default task):</p>
<p><code><br />
rake ubiquo:worker:start_very_long_jobs[name,interval]<br />
</code></p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fthinkingeek.com%2F2011%2F12%2F02%2Fcreating-job-managers-ubiquo%2F&amp;title=Creating%20your%20own%20Job%20Managers%20in%20Ubiquo" id="wpa2a_8" onclick="pageTracker._trackPageview('/outgoing/www.addtoany.com/share_save_url=http_3A_2F_2Fthinkingeek.com_2F2011_2F12_2F02_2Fcreating-job-managers-ubiquo_2F_amp_title=Creating_20your_20own_20Job_20Managers_20in_20Ubiquo?referer=');"><img src="http://thinkingeek.com/wp-content/plugins/add-to-any/share_save_120_16.gif" width="120" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://thinkingeek.com/2011/12/02/creating-job-managers-ubiquo/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Simple guide to configure xmonad, dzen2 and conky</title>
		<link>http://thinkingeek.com/2011/11/21/simple-guide-configure-xmonad-dzen2-conky/</link>
		<comments>http://thinkingeek.com/2011/11/21/simple-guide-configure-xmonad-dzen2-conky/#comments</comments>
		<pubDate>Mon, 21 Nov 2011 13:39:44 +0000</pubDate>
		<dc:creator>brafales</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[haskell]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[xmonad]]></category>

		<guid isPermaLink="false">http://thinkingeek.com/?p=192</guid>
		<description><![CDATA[I&#8217;ll guide you through the different steps I took to install a working desktop environment in Debian using xmonad, conky and dzen2. The final result of this configuration should look like this: Installing the prerequisites The first thing you should do is install the Haskell compiler and interpreter (I&#8217;m assuming you&#8217;re using Debian Sid). To [...]]]></description>
			<content:encoded><![CDATA[<p>
I&#8217;ll guide you through the different steps I took to install a working desktop environment in Debian using xmonad, conky and dzen2.
</p>
<p>
The final result of this configuration should look like this:<br />
<div id="attachment_194" class="wp-caption alignnone" style="width: 310px"><a href="http://thinkingeek.com/wp-content/uploads/2011/11/2011-11-21-141251_3120x1050_scrot.png"  rel="lightbox[roadtrip]"><img src="http://thinkingeek.com/wp-content/uploads/2011/11/2011-11-21-141251_3120x1050_scrot-300x100.png" alt="xmonad with dzen2 and conky" title="xmonad with dzen2 and conky" width="300" height="100" class="size-medium wp-image-194" /></a><p class="wp-caption-text">xmonad with dzen2 and conky</p></div>
</p>
<p><span id="more-192"></span></p>
<h2>Installing the prerequisites</h2>
<p>
The first thing you should do is install the Haskell compiler and interpreter (I&#8217;m assuming you&#8217;re using Debian Sid). To do that, use your beloved aptitude package manager:
</p>
<p>
<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">aptitude</span> <span style="color: #c20cb9; font-weight: bold;">install</span> ghc6</pre></div></div>

</p>
<p>
To install Xmonad I recommend using the Haskell package manager cabal:
</p>
<p>
<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">aptitude</span> <span style="color: #c20cb9; font-weight: bold;">install</span> cabal</pre></div></div>

</p>
<p>
After cabal is installed, you&#8217;ll have to update the package list by running <em>cabal update</em>. However, when doing this, cabal might tell you that there is newer version of the package manager to be installed. Follow the on screen instructions and upgrade to the latest cabal:
</p>
<p>
<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">cabal <span style="color: #c20cb9; font-weight: bold;">install</span> cabal-install</pre></div></div>

</p>
<p>
This will install the latest cabal into your home directory. From now on, make sure that <em>/home/&lt;your_username&gt;/.cabal/bin</em> is on the path to be using this newly installed cabal build. Run <em>cabal update</em> again to have the package list updated.
</p>
<h2>Installing Xmonad</h2>
<p>
Installing xmonad is as easy as running <em>cabal install xmonad</em>. This will try to download, compile and install xmonad and all the prerequisites. However, you may have some compile errors. This is because to compile Xmonad you need to have some development libraries installed. Typically you&#8217;ll need <em>libx11-dev</em>, <em>libxinerama-dev</em> and <em>libxext-dev</em>, among others. To install those dependencies just look for them in the apt respositories and install them using aptitude or apt-get:
</p>
<p>
<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">aptitude</span> <span style="color: #c20cb9; font-weight: bold;">install</span> libx11-dev libxinerama-dev libxext-dev</pre></div></div>

</p>
<p>
After installing xmonad, is recommended you also install <em>xmonad-contrib</em>, which includes some extra functionalities to Xmonad tant we will find useful later. Note that to install xmonad-contrib you&#8217;ll need to install the <em>xft</em> development libraries, too:
</p>
<p>
<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">aptitude</span> <span style="color: #c20cb9; font-weight: bold;">install</span> libxft-dev
cabal <span style="color: #c20cb9; font-weight: bold;">install</span> xmonad-contrib</pre></div></div>

</p>
<p>
Ok, with this steps you already have a fully functional xmonad version installed and ready to be run. We will need to add some eye candy to it now, however, to make it more usable. If you want to have it a try now, though, to see if everything works as expected, just edit your <em>~/.xsession</em> file to make it look like this:
</p>
<p>
<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">exec</span> xmonad</pre></div></div>

</p>
<p>
And now just start your X with <em>startx</em> (or make your display manager to use the default session). You should see&#8230; nothing. If everything worked fine, an empty X screen will be shown. Type <em>Alt+Shift+Enter</em> and an <em>xterm</em> should appear occupying the entire screen.
</p>
<h2>Installing conky and dzen2</h2>
<p>
Again, you can install both those packages from source or via the package manager. I&#8217;ll show you how to install the latest versions from source.
</p>
<h3>Installing conky</h3>
<p>
Download the source tarball (at the time of the writing 1.8.1 was the latest version) from <a href="http://sourceforge.net/projects/conky/files/conky/" onclick="pageTracker._trackPageview('/outgoing/sourceforge.net/projects/conky/files/conky/?referer=');">sourceforge</a> and decompress it wherever you want:
</p>
<p>
<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">tar</span> xvzf conky-1.8.1.tar.gz</pre></div></div>

</p>
<p>
Now run the typical commands to configure and install the package:
</p>
<p>
<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">.<span style="color: #000000; font-weight: bold;">/</span>configure
<span style="color: #c20cb9; font-weight: bold;">make</span>
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">make</span> <span style="color: #c20cb9; font-weight: bold;">install</span></pre></div></div>

</p>
<p>
Note that you might need to install additional development libraries to configure and compile conky with all its bells and whistles, like <em>libxdamage-dev</em>, <em>libmpd-dev</em> and others. Do so with aptitude.
</p>
<h3>Installing dzen2</h3>
<p>
Download the latest source tarball (0.8.5 at the time of writing) from the <a href="https://sites.google.com/site/gotmor/dzen#Download" onclick="pageTracker._trackPageview('/outgoing/sites.google.com/site/gotmor/dzen_Download?referer=');">official home page</a> and uncompress it wherever you want:
</p>
<p>
<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">tar</span> xvzf dzen2-latest.tar.gz</pre></div></div>

</p>
<p>
And then just compile and install it (have a look at the README if you want to add xft and xinerama support to it):
</p>
<p>
<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">make</span>
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">make</span> <span style="color: #c20cb9; font-weight: bold;">install</span></pre></div></div>

</p>
<h2>The funny part begins: configuring xmonad and putting it all together</h2>
<p>
First of all, let me clarify some concepts. We will use xmonad as the Window Manager, dzen2 as the status bar and conky as a system data provider. Some people prefer to use <em>xmobar</em> instead of dzen2 + conky.
</p>
<p>
First of all, let me give credits to the resources I&#8217;ve used to craft xmonad the way I wanted:</p>
<ul>
<li><em>kveras</em> at Github gave me the overall skeleton of the configuration. Make sure to check his <a href="https://github.com/kveras/configs" onclick="pageTracker._trackPageview('/outgoing/github.com/kveras/configs?referer=');">configs</a> repository to have a look at his configs.</li>
<li><a href="http://haskell.org/haskellwiki/Xmonad/Config_archive/John_Goerzen's_Configuration" onclick="pageTracker._trackPageview('/outgoing/haskell.org/haskellwiki/Xmonad/Config_archive/John_Goerzen_s_Configuration?referer=');">Haskell Wiki</a> xmonad Config Archive, which provided some insights.</li>
</ul>
<p>
Xmonad configuration is done via a file in the <em>.xmonad</em> user folder called <em>xmonad.hs</em>. This file is Haskell code, and having a slight understanding of the Haskell syntax is recommended, although I managed to make this one without really having much Haskell knowledge.
</p>
<p>
Basically when you configure xmonad what you&#8217;re really doing is compiling it with the options you pass to it, via that configuration file. There are several things (AFAIK) that can be configured:</p>
<ul>
<li>The default terminal</li>
<li>The workspaces</li>
<li>The keybindings</li>
<li>The mod key</li>
<li>The Layout Hook</li>
<li>The Manage Hook</li>
<li>The Log Hook</li>
<li>Window border options</li>
</ul>
<p>The way everything is tied together is done when calling the main method of the configuration file:
</p>
<p>
<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;">main <span style="color: #339933; font-weight: bold;">=</span> <span style="color: #06c; font-weight: bold;">do</span>
    xmonad <span style="color: #339933; font-weight: bold;">$</span> defaultConfig
      <span style="color: green;">&#123;</span> terminal            <span style="color: #339933; font-weight: bold;">=</span> myTerminal
      <span style="color: #339933; font-weight: bold;">,</span> workspaces          <span style="color: #339933; font-weight: bold;">=</span> myWorkspaces
      <span style="color: #339933; font-weight: bold;">,</span> keys                <span style="color: #339933; font-weight: bold;">=</span> keys
      <span style="color: #339933; font-weight: bold;">,</span> modMask             <span style="color: #339933; font-weight: bold;">=</span> modMask
      <span style="color: #339933; font-weight: bold;">,</span> layoutHook          <span style="color: #339933; font-weight: bold;">=</span> layoutHook
      <span style="color: #339933; font-weight: bold;">,</span> manageHook          <span style="color: #339933; font-weight: bold;">=</span> manageHook
      <span style="color: #339933; font-weight: bold;">,</span> logHook             <span style="color: #339933; font-weight: bold;">=</span> myLogHook
      <span style="color: #339933; font-weight: bold;">,</span> normalBorderColor   <span style="color: #339933; font-weight: bold;">=</span> colorNormalBorder
      <span style="color: #339933; font-weight: bold;">,</span> focusedBorderColor  <span style="color: #339933; font-weight: bold;">=</span> colorFocusedBorder
      <span style="color: #339933; font-weight: bold;">,</span> borderWidth         <span style="color: #339933; font-weight: bold;">=</span> <span style="color: red;">2</span>
<span style="color: green;">&#125;</span></pre></div></div>

</p>
<p>
In that main method you use the defaultConfig and pass a list of the different parameters you want to customize. I&#8217;ll explain briefly every configuration aspect.
</p>
<h3>The default terminal</h3>
<p>
xmonad has a special function that is intended to be used to spawn a terminal. As a daily Linux programmer this is probably very useful. With the terminal parameter, then, you can specify the program that xmonad will launch when this action is invoked. Assigning this variable to the program name (assuming it&#8217;s in the path) is enough for it to work:
</p>
<p>
<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;">myTerminal <span style="color: #339933; font-weight: bold;">=</span> <span style="background-color: #3cb371;">&quot;gnome-terminal&quot;</span></pre></div></div>

</p>
<h3>The workspaces</h3>
<p>
xmonad allows you to group your windows into <em>workspaces</em>. The concept of workspace is very similar to the virtual desktops we have in Gnome, or the Spaces we have in Mac OS X. Each window will belong to a workspace, each workspace has a name and it&#8217;s own configuration, and one and only one workspace can be active (and shown) on one screen at the same time.
</p>
<p>
In the workspaces variable, we&#8217;ll tell xmonad our default list of workspaces we want to work with, in a form of a string list. In my configuration I&#8217;ve preceded every workspace name with a number:
</p>
<p>
<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;">myWorkspaces <span style="color: #339933; font-weight: bold;">=</span> <span style="color: green;">&#91;</span><span style="background-color: #3cb371;">&quot;1:main&quot;</span><span style="color: #339933; font-weight: bold;">,</span><span style="background-color: #3cb371;">&quot;2:web&quot;</span><span style="color: #339933; font-weight: bold;">,</span><span style="background-color: #3cb371;">&quot;3:vim&quot;</span><span style="color: #339933; font-weight: bold;">,</span><span style="background-color: #3cb371;">&quot;4:chat&quot;</span><span style="color: #339933; font-weight: bold;">,</span><span style="background-color: #3cb371;">&quot;5:music&quot;</span><span style="color: #339933; font-weight: bold;">,</span> <span style="background-color: #3cb371;">&quot;6:gimp&quot;</span><span style="color: green;">&#93;</span></pre></div></div>

</p>
<h3>The keybindings</h3>
<p>
Key binding is a crucial part of the configuration. One of the goals of xmonad is being able to do all window management without having to use the mouse, so your hands are always on the keyboard. Choosing a good key layout is then very important, and having a look at all the things you can do in xmonad is important, too, so you can check what you think it may be more useful to you. The key binding configuration is a bit strange in haskell, and I don&#8217;t entirely understand it myself, but I&#8217;ll try to guide you through the basics. Basically you have 3 modifiers: the <em>windows</em> key, <em>ctrl</em>, <em>shift</em> and <em>alt</em> (in fact I think you can deifne any key as a valid modifier, but those are the most used). You then configure pair of key-action, telling xmonad what should it do when certain keys are pressed. Those pairs have this syntax:
</p>

<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;"><span style="color: green;">&#40;</span><span style="color: green;">&#40;</span>modMask <span style="color: #339933; font-weight: bold;">.|.</span> shiftMask<span style="color: #339933; font-weight: bold;">,</span>      xK<span style="color: #339933; font-weight: bold;">_</span>Return   <span style="color: green;">&#41;</span><span style="color: #339933; font-weight: bold;">,</span> spawn <span style="color: #339933; font-weight: bold;">$</span> XMonad<span style="color: #339933; font-weight: bold;">.</span>terminal conf<span style="color: green;">&#41;</span></pre></div></div>

</p>
<p>
The first part tells xmonad the key press, while the second the action to be performed. The key press is expressed in the form of <em>modifier-key</em>. The modifiers can be chained, so you can assign some action when more than a modifier is pressed. In the example, we have <em>modMask .|. shiftMask, xK_Return</em>. This line means <em>press the modKey and the shift key, and then the return key</em>. As you can see, the operator to chain modifiers is <em>.|.</em>. When you want a key binding without modifier, you put a <em>0</em> instead. For instance, to bind a key to print the screen, you could use something like this: <em>((0, xK_Print), spawn &#8220;scrot -e &#8216;mv $f ~/screenshots/&#8217;&#8221;)</em>. This command tells xmonad to run the <em>scrot</em> program when the <em>Print Screen</em> key is pressed.
</p>
<p>
Some xmonad actions require a special attention: those used to manipulate the windows and the workspaces. I&#8217;ll tell you the most used ones (at least in the default configurations).</p>
<ul>
<li><em>sendMessage nextLayout</em> is used to tell xmonad to switch to the next layout in the current workspace</li>
<li><em>setLayout $ XMonad.layoutHook conf</em> will reset the current layout to the default one of the current workspace</li>
<li><em>sendMessage ToggleStruts</em> is used to switch between struts mode on and off. If I&#8217;m not mistaken, struts are margins put between windows (which by default are not shown)</li>
<li><em>windows W.focusDown</em> sets the focused window to the next window in the stack, allowing you to navigate the focus through different windows</li>
<li><em>windows W.focusUp</em> does the same as above but in the reverse order</li>
<li><em>windows W.swapDown</em> will swap the current window to the space occupied by the next window on the stack, useful to move windows between the different positions on the workspace</li>
<li><em>windows W.swapUp</em>, again, does the same as above in the reverse order</li>
<li><em>windows W.swapMaster</em> is very useful: it will put the focused window into the main space of the current layout (which is usually bigger than the other frames)</li>
<li><em>sendMessage Shrink</em> is used to shrink the size of the main frame size</li>
<li><em>sendMessage Expand</em>, on the other side, is used to expand the main frame size</li>
<li><em>sendMessage (IncMasterN number)</em> will increase the number of panes of the master pane by the given number (which can be a positive or negative integer)</li>
<li><em>nextWS</em> will switch to the next workspace</li>
<li><em>prevWS</em> will switch to the previous workspace</li>
<li><em>shiftToNext</em> will move the focused windo to the next workspace</li>
<li><em>shiftToPrev</em> will move the focused window to the previous workspace</li>
<li><em>W.shift workspace</em> will put the focused window to the selected workspace</li>
<li><em>W.view workspace</em> will put the selected workspace as the workspace of the screen</li>
</ul>
<p>
Here&#8217;s how the entire keys variable is assigned:
</p>

<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;">keys' conf<span style="color: #339933; font-weight: bold;">@</span><span style="color: green;">&#40;</span>XConfig <span style="color: green;">&#123;</span>XMonad<span style="color: #339933; font-weight: bold;">.</span>modMask <span style="color: #339933; font-weight: bold;">=</span> modMask<span style="color: green;">&#125;</span><span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">=</span> M<span style="color: #339933; font-weight: bold;">.</span>fromList <span style="color: #339933; font-weight: bold;">$</span>
    <span style="color: green;">&#91;</span> <span style="color: green;">&#40;</span><span style="color: green;">&#40;</span>modMask<span style="color: #339933; font-weight: bold;">,</span>                    xK<span style="color: #339933; font-weight: bold;">_</span>p        <span style="color: green;">&#41;</span><span style="color: #339933; font-weight: bold;">,</span> runOrRaisePrompt largeXPConfig<span style="color: green;">&#41;</span>
    <span style="color: #339933; font-weight: bold;">,</span> <span style="color: green;">&#40;</span><span style="color: green;">&#40;</span>modMask <span style="color: #339933; font-weight: bold;">.|.</span> shiftMask<span style="color: #339933; font-weight: bold;">,</span>      xK<span style="color: #339933; font-weight: bold;">_</span>Return   <span style="color: green;">&#41;</span><span style="color: #339933; font-weight: bold;">,</span> spawn <span style="color: #339933; font-weight: bold;">$</span> XMonad<span style="color: #339933; font-weight: bold;">.</span>terminal conf<span style="color: green;">&#41;</span>
    <span style="color: #339933; font-weight: bold;">,</span> <span style="color: green;">&#40;</span><span style="color: green;">&#40;</span>modMask<span style="color: #339933; font-weight: bold;">,</span>                    xK<span style="color: #339933; font-weight: bold;">_</span>F2       <span style="color: green;">&#41;</span><span style="color: #339933; font-weight: bold;">,</span> spawn <span style="background-color: #3cb371;">&quot;gmrun&quot;</span><span style="color: green;">&#41;</span>
    <span style="color: #339933; font-weight: bold;">,</span> <span style="color: green;">&#40;</span><span style="color: green;">&#40;</span>modMask <span style="color: #339933; font-weight: bold;">.|.</span> shiftMask<span style="color: #339933; font-weight: bold;">,</span>      xK<span style="color: #339933; font-weight: bold;">_</span>c        <span style="color: green;">&#41;</span><span style="color: #339933; font-weight: bold;">,</span> kill<span style="color: green;">&#41;</span>
    <span style="color: #339933; font-weight: bold;">,</span> <span style="color: green;">&#40;</span><span style="color: green;">&#40;</span>modMask <span style="color: #339933; font-weight: bold;">.|.</span> shiftMask<span style="color: #339933; font-weight: bold;">,</span>      xK<span style="color: #339933; font-weight: bold;">_</span>l        <span style="color: green;">&#41;</span><span style="color: #339933; font-weight: bold;">,</span> spawn <span style="background-color: #3cb371;">&quot;slock&quot;</span><span style="color: green;">&#41;</span>
    <span style="color: #5d478b; font-style: italic;">-- Programs</span>
    <span style="color: #339933; font-weight: bold;">,</span> <span style="color: green;">&#40;</span><span style="color: green;">&#40;</span><span style="color: red;">0</span><span style="color: #339933; font-weight: bold;">,</span>                          xK<span style="color: #339933; font-weight: bold;">_</span>Print    <span style="color: green;">&#41;</span><span style="color: #339933; font-weight: bold;">,</span> spawn <span style="background-color: #3cb371;">&quot;scrot -e 'mv $f ~/screenshots/'&quot;</span><span style="color: green;">&#41;</span>
    <span style="color: #339933; font-weight: bold;">,</span> <span style="color: green;">&#40;</span><span style="color: green;">&#40;</span>modMask<span style="color: #339933; font-weight: bold;">,</span>		            xK<span style="color: #339933; font-weight: bold;">_</span>o        <span style="color: green;">&#41;</span><span style="color: #339933; font-weight: bold;">,</span> spawn <span style="background-color: #3cb371;">&quot;chromium-browser&quot;</span><span style="color: green;">&#41;</span>
    <span style="color: #339933; font-weight: bold;">,</span> <span style="color: green;">&#40;</span><span style="color: green;">&#40;</span>modMask<span style="color: #339933; font-weight: bold;">,</span>                    xK<span style="color: #339933; font-weight: bold;">_</span>m        <span style="color: green;">&#41;</span><span style="color: #339933; font-weight: bold;">,</span> spawn <span style="background-color: #3cb371;">&quot;nautilus --no-desktop --browser&quot;</span><span style="color: green;">&#41;</span>
    <span style="color: #5d478b; font-style: italic;">-- Media Keys</span>
    <span style="color: #339933; font-weight: bold;">,</span> <span style="color: green;">&#40;</span><span style="color: green;">&#40;</span><span style="color: red;">0</span><span style="color: #339933; font-weight: bold;">,</span>                          0x1008ff12  <span style="color: green;">&#41;</span><span style="color: #339933; font-weight: bold;">,</span> spawn <span style="background-color: #3cb371;">&quot;amixer -q sset Headphone toggle&quot;</span><span style="color: green;">&#41;</span>        <span style="color: #5d478b; font-style: italic;">-- XF86AudioMute</span>
    <span style="color: #339933; font-weight: bold;">,</span> <span style="color: green;">&#40;</span><span style="color: green;">&#40;</span><span style="color: red;">0</span><span style="color: #339933; font-weight: bold;">,</span>                          0x1008ff11  <span style="color: green;">&#41;</span><span style="color: #339933; font-weight: bold;">,</span> spawn <span style="background-color: #3cb371;">&quot;amixer -q sset Headphone 5%-&quot;</span><span style="color: green;">&#41;</span>   <span style="color: #5d478b; font-style: italic;">-- XF86AudioLowerVolume</span>
    <span style="color: #339933; font-weight: bold;">,</span> <span style="color: green;">&#40;</span><span style="color: green;">&#40;</span><span style="color: red;">0</span><span style="color: #339933; font-weight: bold;">,</span>                          0x1008ff13  <span style="color: green;">&#41;</span><span style="color: #339933; font-weight: bold;">,</span> spawn <span style="background-color: #3cb371;">&quot;amixer -q sset Headphone 5%+&quot;</span><span style="color: green;">&#41;</span>   <span style="color: #5d478b; font-style: italic;">-- XF86AudioRaiseVolume</span>
    <span style="color: #339933; font-weight: bold;">,</span> <span style="color: green;">&#40;</span><span style="color: green;">&#40;</span><span style="color: red;">0</span><span style="color: #339933; font-weight: bold;">,</span>                          0x1008ff14  <span style="color: green;">&#41;</span><span style="color: #339933; font-weight: bold;">,</span> spawn <span style="background-color: #3cb371;">&quot;rhythmbox-client --play-pause&quot;</span><span style="color: green;">&#41;</span>
    <span style="color: #339933; font-weight: bold;">,</span> <span style="color: green;">&#40;</span><span style="color: green;">&#40;</span><span style="color: red;">0</span><span style="color: #339933; font-weight: bold;">,</span>                          0x1008ff17  <span style="color: green;">&#41;</span><span style="color: #339933; font-weight: bold;">,</span> spawn <span style="background-color: #3cb371;">&quot;rhythmbox-client --next&quot;</span><span style="color: green;">&#41;</span>
    <span style="color: #339933; font-weight: bold;">,</span> <span style="color: green;">&#40;</span><span style="color: green;">&#40;</span><span style="color: red;">0</span><span style="color: #339933; font-weight: bold;">,</span>                          0x1008ff16  <span style="color: green;">&#41;</span><span style="color: #339933; font-weight: bold;">,</span> spawn <span style="background-color: #3cb371;">&quot;rhythmbox-client --previous&quot;</span><span style="color: green;">&#41;</span>
&nbsp;
    <span style="color: #5d478b; font-style: italic;">-- layouts</span>
    <span style="color: #339933; font-weight: bold;">,</span> <span style="color: green;">&#40;</span><span style="color: green;">&#40;</span>modMask<span style="color: #339933; font-weight: bold;">,</span>                    xK<span style="color: #339933; font-weight: bold;">_</span>space    <span style="color: green;">&#41;</span><span style="color: #339933; font-weight: bold;">,</span> sendMessage NextLayout<span style="color: green;">&#41;</span>
    <span style="color: #339933; font-weight: bold;">,</span> <span style="color: green;">&#40;</span><span style="color: green;">&#40;</span>modMask <span style="color: #339933; font-weight: bold;">.|.</span> shiftMask<span style="color: #339933; font-weight: bold;">,</span>      xK<span style="color: #339933; font-weight: bold;">_</span>space    <span style="color: green;">&#41;</span><span style="color: #339933; font-weight: bold;">,</span> setLayout <span style="color: #339933; font-weight: bold;">$</span> XMonad<span style="color: #339933; font-weight: bold;">.</span>layoutHook conf<span style="color: green;">&#41;</span>          <span style="color: #5d478b; font-style: italic;">-- reset layout on current desktop to default</span>
    <span style="color: #339933; font-weight: bold;">,</span> <span style="color: green;">&#40;</span><span style="color: green;">&#40;</span>modMask<span style="color: #339933; font-weight: bold;">,</span>                    xK<span style="color: #339933; font-weight: bold;">_</span>b        <span style="color: green;">&#41;</span><span style="color: #339933; font-weight: bold;">,</span> sendMessage ToggleStruts<span style="color: green;">&#41;</span>
    <span style="color: #339933; font-weight: bold;">,</span> <span style="color: green;">&#40;</span><span style="color: green;">&#40;</span>modMask<span style="color: #339933; font-weight: bold;">,</span>                    xK<span style="color: #339933; font-weight: bold;">_</span>n        <span style="color: green;">&#41;</span><span style="color: #339933; font-weight: bold;">,</span> refresh<span style="color: green;">&#41;</span>
    <span style="color: #339933; font-weight: bold;">,</span> <span style="color: green;">&#40;</span><span style="color: green;">&#40;</span>modMask<span style="color: #339933; font-weight: bold;">,</span>                    xK<span style="color: #339933; font-weight: bold;">_</span>Tab      <span style="color: green;">&#41;</span><span style="color: #339933; font-weight: bold;">,</span> windows W<span style="color: #339933; font-weight: bold;">.</span>focusDown<span style="color: green;">&#41;</span>                         <span style="color: #5d478b; font-style: italic;">-- move focus to next window</span>
    <span style="color: #339933; font-weight: bold;">,</span> <span style="color: green;">&#40;</span><span style="color: green;">&#40;</span>modMask<span style="color: #339933; font-weight: bold;">,</span>                    xK<span style="color: #339933; font-weight: bold;">_</span>j        <span style="color: green;">&#41;</span><span style="color: #339933; font-weight: bold;">,</span> windows W<span style="color: #339933; font-weight: bold;">.</span>focusDown<span style="color: green;">&#41;</span>
    <span style="color: #339933; font-weight: bold;">,</span> <span style="color: green;">&#40;</span><span style="color: green;">&#40;</span>modMask<span style="color: #339933; font-weight: bold;">,</span>                    xK<span style="color: #339933; font-weight: bold;">_</span>k        <span style="color: green;">&#41;</span><span style="color: #339933; font-weight: bold;">,</span> windows W<span style="color: #339933; font-weight: bold;">.</span>focusUp  <span style="color: green;">&#41;</span>
    <span style="color: #339933; font-weight: bold;">,</span> <span style="color: green;">&#40;</span><span style="color: green;">&#40;</span>modMask <span style="color: #339933; font-weight: bold;">.|.</span> shiftMask<span style="color: #339933; font-weight: bold;">,</span>      xK<span style="color: #339933; font-weight: bold;">_</span>j        <span style="color: green;">&#41;</span><span style="color: #339933; font-weight: bold;">,</span> windows W<span style="color: #339933; font-weight: bold;">.</span>swapDown<span style="color: green;">&#41;</span>                          <span style="color: #5d478b; font-style: italic;">-- swap the focused window with the next window</span>
    <span style="color: #339933; font-weight: bold;">,</span> <span style="color: green;">&#40;</span><span style="color: green;">&#40;</span>modMask <span style="color: #339933; font-weight: bold;">.|.</span> shiftMask<span style="color: #339933; font-weight: bold;">,</span>      xK<span style="color: #339933; font-weight: bold;">_</span>k        <span style="color: green;">&#41;</span><span style="color: #339933; font-weight: bold;">,</span> windows W<span style="color: #339933; font-weight: bold;">.</span>swapUp<span style="color: green;">&#41;</span>                            <span style="color: #5d478b; font-style: italic;">-- swap the focused window with the previous window</span>
    <span style="color: #339933; font-weight: bold;">,</span> <span style="color: green;">&#40;</span><span style="color: green;">&#40;</span>modMask<span style="color: #339933; font-weight: bold;">,</span>                    xK<span style="color: #339933; font-weight: bold;">_</span>Return   <span style="color: green;">&#41;</span><span style="color: #339933; font-weight: bold;">,</span> windows W<span style="color: #339933; font-weight: bold;">.</span>swapMaster<span style="color: green;">&#41;</span>
    <span style="color: #339933; font-weight: bold;">,</span> <span style="color: green;">&#40;</span><span style="color: green;">&#40;</span>modMask<span style="color: #339933; font-weight: bold;">,</span>                    xK<span style="color: #339933; font-weight: bold;">_</span>t        <span style="color: green;">&#41;</span><span style="color: #339933; font-weight: bold;">,</span> withFocused <span style="color: #339933; font-weight: bold;">$</span> windows <span style="color: #339933; font-weight: bold;">.</span> W<span style="color: #339933; font-weight: bold;">.</span>sink<span style="color: green;">&#41;</span>              <span style="color: #5d478b; font-style: italic;">-- Push window back into tiling</span>
    <span style="color: #339933; font-weight: bold;">,</span> <span style="color: green;">&#40;</span><span style="color: green;">&#40;</span>modMask<span style="color: #339933; font-weight: bold;">,</span>                    xK<span style="color: #339933; font-weight: bold;">_</span>h        <span style="color: green;">&#41;</span><span style="color: #339933; font-weight: bold;">,</span> sendMessage Shrink<span style="color: green;">&#41;</span>                          <span style="color: #5d478b; font-style: italic;">-- %! Shrink a master area</span>
    <span style="color: #339933; font-weight: bold;">,</span> <span style="color: green;">&#40;</span><span style="color: green;">&#40;</span>modMask<span style="color: #339933; font-weight: bold;">,</span>                    xK<span style="color: #339933; font-weight: bold;">_</span>l        <span style="color: green;">&#41;</span><span style="color: #339933; font-weight: bold;">,</span> sendMessage Expand<span style="color: green;">&#41;</span>                          <span style="color: #5d478b; font-style: italic;">-- %! Expand a master area</span>
    <span style="color: #339933; font-weight: bold;">,</span> <span style="color: green;">&#40;</span><span style="color: green;">&#40;</span>modMask<span style="color: #339933; font-weight: bold;">,</span>                    xK<span style="color: #339933; font-weight: bold;">_</span>comma    <span style="color: green;">&#41;</span><span style="color: #339933; font-weight: bold;">,</span> sendMessage <span style="color: green;">&#40;</span>IncMasterN <span style="color: red;">1</span><span style="color: green;">&#41;</span><span style="color: green;">&#41;</span>
    <span style="color: #339933; font-weight: bold;">,</span> <span style="color: green;">&#40;</span><span style="color: green;">&#40;</span>modMask<span style="color: #339933; font-weight: bold;">,</span>                    xK<span style="color: #339933; font-weight: bold;">_</span>period   <span style="color: green;">&#41;</span><span style="color: #339933; font-weight: bold;">,</span> sendMessage <span style="color: green;">&#40;</span>IncMasterN <span style="color: green;">&#40;</span><span style="color: #339933; font-weight: bold;">-</span><span style="color: red;">1</span><span style="color: green;">&#41;</span><span style="color: green;">&#41;</span><span style="color: green;">&#41;</span>
&nbsp;
&nbsp;
    <span style="color: #5d478b; font-style: italic;">-- workspaces</span>
    <span style="color: #339933; font-weight: bold;">,</span> <span style="color: green;">&#40;</span><span style="color: green;">&#40;</span>modMask <span style="color: #339933; font-weight: bold;">.|.</span> controlMask<span style="color: #339933; font-weight: bold;">,</span>   xK<span style="color: #339933; font-weight: bold;">_</span>Right     <span style="color: green;">&#41;</span><span style="color: #339933; font-weight: bold;">,</span> nextWS<span style="color: green;">&#41;</span>
    <span style="color: #339933; font-weight: bold;">,</span> <span style="color: green;">&#40;</span><span style="color: green;">&#40;</span>modMask <span style="color: #339933; font-weight: bold;">.|.</span> shiftMask<span style="color: #339933; font-weight: bold;">,</span>     xK<span style="color: #339933; font-weight: bold;">_</span>Right     <span style="color: green;">&#41;</span><span style="color: #339933; font-weight: bold;">,</span> shiftToNext<span style="color: green;">&#41;</span>
    <span style="color: #339933; font-weight: bold;">,</span> <span style="color: green;">&#40;</span><span style="color: green;">&#40;</span>modMask <span style="color: #339933; font-weight: bold;">.|.</span> controlMask<span style="color: #339933; font-weight: bold;">,</span>   xK<span style="color: #339933; font-weight: bold;">_</span>Left      <span style="color: green;">&#41;</span><span style="color: #339933; font-weight: bold;">,</span> prevWS<span style="color: green;">&#41;</span>
    <span style="color: #339933; font-weight: bold;">,</span> <span style="color: green;">&#40;</span><span style="color: green;">&#40;</span>modMask <span style="color: #339933; font-weight: bold;">.|.</span> shiftMask<span style="color: #339933; font-weight: bold;">,</span>     xK<span style="color: #339933; font-weight: bold;">_</span>Left      <span style="color: green;">&#41;</span><span style="color: #339933; font-weight: bold;">,</span> shiftToPrev<span style="color: green;">&#41;</span>
&nbsp;
    <span style="color: #5d478b; font-style: italic;">-- quit, or restart</span>
    <span style="color: #339933; font-weight: bold;">,</span> <span style="color: green;">&#40;</span><span style="color: green;">&#40;</span>modMask <span style="color: #339933; font-weight: bold;">.|.</span> shiftMask<span style="color: #339933; font-weight: bold;">,</span>      xK<span style="color: #339933; font-weight: bold;">_</span>q        <span style="color: green;">&#41;</span><span style="color: #339933; font-weight: bold;">,</span> io <span style="color: green;">&#40;</span>exitWith ExitSuccess<span style="color: green;">&#41;</span><span style="color: green;">&#41;</span>
    <span style="color: #339933; font-weight: bold;">,</span> <span style="color: green;">&#40;</span><span style="color: green;">&#40;</span>modMask<span style="color: #339933; font-weight: bold;">,</span>                    xK<span style="color: #339933; font-weight: bold;">_</span>q        <span style="color: green;">&#41;</span><span style="color: #339933; font-weight: bold;">,</span> spawn <span style="background-color: #3cb371;">&quot;killall conky dzen2 &amp;&amp; /home/brafales/.cabal/bin/xmonad --recompile &amp;&amp; /home/brafales/.cabal/bin/xmonad --restart&quot;</span><span style="color: green;">&#41;</span>
    <span style="color: green;">&#93;</span>
    <span style="color: #339933; font-weight: bold;">++</span>
    <span style="color: #5d478b; font-style: italic;">-- mod-[1..9] %! Switch to workspace N</span>
    <span style="color: #5d478b; font-style: italic;">-- mod-shift-[1..9] %! Move client to workspace N</span>
    <span style="color: green;">&#91;</span><span style="color: green;">&#40;</span><span style="color: green;">&#40;</span>m <span style="color: #339933; font-weight: bold;">.|.</span> modMask<span style="color: #339933; font-weight: bold;">,</span> k<span style="color: green;">&#41;</span><span style="color: #339933; font-weight: bold;">,</span> windows <span style="color: #339933; font-weight: bold;">$</span> f i<span style="color: green;">&#41;</span>
        <span style="color: #339933; font-weight: bold;">|</span> <span style="color: green;">&#40;</span>i<span style="color: #339933; font-weight: bold;">,</span> k<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">&lt;-</span> <span style="font-weight: bold;">zip</span> <span style="color: green;">&#40;</span>XMonad<span style="color: #339933; font-weight: bold;">.</span>workspaces conf<span style="color: green;">&#41;</span> <span style="color: green;">&#91;</span>xK<span style="color: #339933; font-weight: bold;">_</span>1 <span style="color: #339933; font-weight: bold;">..</span> xK<span style="color: #339933; font-weight: bold;">_</span>9<span style="color: green;">&#93;</span>
        <span style="color: #339933; font-weight: bold;">,</span> <span style="color: green;">&#40;</span>f<span style="color: #339933; font-weight: bold;">,</span> m<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">&lt;-</span> <span style="color: green;">&#91;</span><span style="color: green;">&#40;</span>W<span style="color: #339933; font-weight: bold;">.</span>greedyView<span style="color: #339933; font-weight: bold;">,</span> <span style="color: red;">0</span><span style="color: green;">&#41;</span><span style="color: #339933; font-weight: bold;">,</span> <span style="color: green;">&#40;</span>W<span style="color: #339933; font-weight: bold;">.</span>shift<span style="color: #339933; font-weight: bold;">,</span> shiftMask<span style="color: green;">&#41;</span><span style="color: green;">&#93;</span><span style="color: green;">&#93;</span>
    <span style="color: #339933; font-weight: bold;">++</span>
&nbsp;
    <span style="color: #5d478b; font-style: italic;">--</span>
    <span style="color: #5d478b; font-style: italic;">-- mod-{w,e,r}, Switch to physical/Xinerama screens 1, 2, or 3</span>
    <span style="color: #5d478b; font-style: italic;">-- mod-shift-{w,e,r}, Move client to screen 1, 2, or 3</span>
    <span style="color: #5d478b; font-style: italic;">--</span>
    <span style="color: green;">&#91;</span><span style="color: green;">&#40;</span><span style="color: green;">&#40;</span>m <span style="color: #339933; font-weight: bold;">.|.</span> modMask<span style="color: #339933; font-weight: bold;">,</span> key<span style="color: green;">&#41;</span><span style="color: #339933; font-weight: bold;">,</span> screenWorkspace sc <span style="color: #339933; font-weight: bold;">&gt;&gt;=</span> <span style="font-weight: bold;">flip</span> whenJust <span style="color: green;">&#40;</span>windows <span style="color: #339933; font-weight: bold;">.</span> f<span style="color: green;">&#41;</span><span style="color: green;">&#41;</span>
        <span style="color: #339933; font-weight: bold;">|</span> <span style="color: green;">&#40;</span>key<span style="color: #339933; font-weight: bold;">,</span> sc<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">&lt;-</span> <span style="font-weight: bold;">zip</span> <span style="color: green;">&#91;</span>xK<span style="color: #339933; font-weight: bold;">_</span>w<span style="color: #339933; font-weight: bold;">,</span> xK<span style="color: #339933; font-weight: bold;">_</span>e<span style="color: #339933; font-weight: bold;">,</span> xK<span style="color: #339933; font-weight: bold;">_</span>r<span style="color: green;">&#93;</span> <span style="color: green;">&#91;</span><span style="color: red;">0</span><span style="color: #339933; font-weight: bold;">..</span><span style="color: green;">&#93;</span>
        <span style="color: #339933; font-weight: bold;">,</span> <span style="color: green;">&#40;</span>f<span style="color: #339933; font-weight: bold;">,</span> m<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">&lt;-</span> <span style="color: green;">&#91;</span><span style="color: green;">&#40;</span>W<span style="color: #339933; font-weight: bold;">.</span>view<span style="color: #339933; font-weight: bold;">,</span> <span style="color: red;">0</span><span style="color: green;">&#41;</span><span style="color: #339933; font-weight: bold;">,</span> <span style="color: green;">&#40;</span>W<span style="color: #339933; font-weight: bold;">.</span>shift<span style="color: #339933; font-weight: bold;">,</span> shiftMask<span style="color: green;">&#41;</span><span style="color: green;">&#93;</span><span style="color: green;">&#93;</span></pre></div></div>

</p>
<h3>The mod key</h3>
<p>
The mod key is the default key xmonad uses to prepend all the keybindings (usually). Some users configure it to <em>alt</em>, others to <em>ctrl</em>, others to the <em>windows key</em>. It&#8217;s up to you. In my config I have it configured to the windows key:
</p>
<p>
<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;">modMask' <span style="color: #339933; font-weight: bold;">::</span> KeyMask
modMask' <span style="color: #339933; font-weight: bold;">=</span> mod4Mask</pre></div></div>

</p>
<h3>The Layout Hook</h3>
<p>
The layout hook is used to manage the layouts of the workspaces. xmonad is very configurable regarding the layouts you can use. By default, the windows are tiled by using half the screen (vertically) for the main frame, and equally sized horizontal windows for the other frames, but you can set it up however you want.
</p>
<p>
The syntax to configure the layouts is simple, you concatenate which layout you want to use for each workspace, leaving the last one as the default one:
</p>

<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;">layoutHook'  <span style="color: #339933; font-weight: bold;">=</span>  onWorkspaces <span style="color: green;">&#91;</span><span style="background-color: #3cb371;">&quot;1:main&quot;</span><span style="color: #339933; font-weight: bold;">,</span><span style="background-color: #3cb371;">&quot;5:music&quot;</span><span style="color: green;">&#93;</span> customLayout <span style="color: #339933; font-weight: bold;">$</span> 
                onWorkspaces <span style="color: green;">&#91;</span><span style="background-color: #3cb371;">&quot;6:gimp&quot;</span><span style="color: green;">&#93;</span> gimpLayout <span style="color: #339933; font-weight: bold;">$</span> 
                onWorkspaces <span style="color: green;">&#91;</span><span style="background-color: #3cb371;">&quot;4:chat&quot;</span><span style="color: green;">&#93;</span> imLayout <span style="color: #339933; font-weight: bold;">$</span>
                customLayout2</pre></div></div>

</p>
<p>
What&#8217;s not so easy is to configure those variables we used (customLayout, gimpLayout, imLayout, etc.), but you get the idea: you can configure each workspace to have its own layout, which is very useful. Here&#8217;s my <em>customLayout</em> variable so you can see how a layout is configured:
</p>

<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;">customLayout <span style="color: #339933; font-weight: bold;">=</span> avoidStruts <span style="color: #339933; font-weight: bold;">$</span> tiled <span style="color: #339933; font-weight: bold;">|||</span> Mirror tiled <span style="color: #339933; font-weight: bold;">|||</span> Full <span style="color: #339933; font-weight: bold;">|||</span> simpleFloat
  <span style="color: #06c; font-weight: bold;">where</span>
    tiled   <span style="color: #339933; font-weight: bold;">=</span> ResizableTall <span style="color: red;">1</span> <span style="color: green;">&#40;</span><span style="color: red;">2</span><span style="color: #339933; font-weight: bold;">/</span><span style="color: red;">100</span><span style="color: green;">&#41;</span> <span style="color: green;">&#40;</span><span style="color: red;">1</span><span style="color: #339933; font-weight: bold;">/</span><span style="color: red;">2</span><span style="color: green;">&#41;</span> <span style="color: green;">&#91;</span><span style="color: green;">&#93;</span></pre></div></div>

</p>
<p>
What I&#8217;m doing here is using <em>avoidstruts</em> to have a layout without margins between windows, and then passing a list of the different available layouts for the workspace, separated by the <em>|||</em> operator. This means that the default layout will be <em>tiled</em>, then <em>Mirror tiled</em>, etc. In this case, what Mirror does is swap the type of split, from vertical to horizontal. After that, I tell the config what I mean by <em>tiled</em>, in this case <em>ResizableTall 1 (2/200) (1/2) []</em>. What this means is to use the layout <em>ResizableTall</em> with 1 master window, the size of each resizing step, the width of the master panel and the slaves window height. You can check the full documentation for ResizableTall in the <a href="http://xmonad.org/xmonad-docs/xmonad-contrib/XMonad-Layout-ResizableTile.html" onclick="pageTracker._trackPageview('/outgoing/xmonad.org/xmonad-docs/xmonad-contrib/XMonad-Layout-ResizableTile.html?referer=');">XMonad.Layout.ResizableTile</a> documentation page.
</p>
<p>
The same way we&#8217;ve used ResizableTall for this customlayout, lots of extensions exist in xmonad that do all sorts of layout positioning.
</p>
<h3>The Manage Hook</h3>
<p>
The manage hook handles how new windows are positioned by default. xmonad allows you to put some windows into their own workspace, or in its own mode. This way, for example, you can have all Firefox windows to open in the &#8220;2:web&#8221; workspace, or have special program windows not to be tiled, but floated instead.
</p>
<p>
While I still don&#8217;t fully understand all the configuration options, this is a typical line to configure a manage hook:
</p>
<p>
<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;"><span style="color: green;">&#91;</span>className    <span style="color: #339933; font-weight: bold;">=?</span> c            <span style="color: #339933; font-weight: bold;">--&gt;</span> doShift  <span style="background-color: #3cb371;">&quot;1:main&quot;</span>   <span style="color: #339933; font-weight: bold;">|</span>   c   <span style="color: #339933; font-weight: bold;">&lt;-</span> myDev    <span style="color: green;">&#93;</span> <span style="color: #5d478b; font-style: italic;">-- move dev to main</span></pre></div></div>

</p>
<p>
What we&#8217;re doing with this line is tell xmonad that all windows which has a <em>classname</em> included in the <em>myDev</em> list must be shifted to the &#8220;1:main&#8221; workspace. I don&#8217;t know all the criteria you can use to identify a window, but the most used ones are the className and the role. You can check those X properties using the program <em>xprop</em> and clicking on the desired window.
</p>
<p>
Here&#8217;s my whole manage hook configuration:
</p>

<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;">manageHook' <span style="color: #339933; font-weight: bold;">::</span> ManageHook
manageHook' <span style="color: #339933; font-weight: bold;">=</span> <span style="color: green;">&#40;</span>composeAll <span style="color: #339933; font-weight: bold;">.</span> <span style="font-weight: bold;">concat</span> <span style="color: #339933; font-weight: bold;">$</span>
    <span style="color: green;">&#91;</span> <span style="color: green;">&#91;</span>resource     <span style="color: #339933; font-weight: bold;">=?</span> r            <span style="color: #339933; font-weight: bold;">--&gt;</span> doIgnore            <span style="color: #339933; font-weight: bold;">|</span>   r   <span style="color: #339933; font-weight: bold;">&lt;-</span> myIgnores<span style="color: green;">&#93;</span> <span style="color: #5d478b; font-style: italic;">-- ignore desktop</span>
    <span style="color: #339933; font-weight: bold;">,</span> <span style="color: green;">&#91;</span>className    <span style="color: #339933; font-weight: bold;">=?</span> c            <span style="color: #339933; font-weight: bold;">--&gt;</span> doShift  <span style="background-color: #3cb371;">&quot;1:main&quot;</span>   <span style="color: #339933; font-weight: bold;">|</span>   c   <span style="color: #339933; font-weight: bold;">&lt;-</span> myDev    <span style="color: green;">&#93;</span> <span style="color: #5d478b; font-style: italic;">-- move dev to main</span>
    <span style="color: #339933; font-weight: bold;">,</span> <span style="color: green;">&#91;</span>className    <span style="color: #339933; font-weight: bold;">=?</span> c            <span style="color: #339933; font-weight: bold;">--&gt;</span> doShift  <span style="background-color: #3cb371;">&quot;2:web&quot;</span>    <span style="color: #339933; font-weight: bold;">|</span>   c   <span style="color: #339933; font-weight: bold;">&lt;-</span> myWebs   <span style="color: green;">&#93;</span> <span style="color: #5d478b; font-style: italic;">-- move webs to main</span>
    <span style="color: #339933; font-weight: bold;">,</span> <span style="color: green;">&#91;</span>className    <span style="color: #339933; font-weight: bold;">=?</span> c            <span style="color: #339933; font-weight: bold;">--&gt;</span> doShift  <span style="background-color: #3cb371;">&quot;3:vim&quot;</span>    <span style="color: #339933; font-weight: bold;">|</span>   c   <span style="color: #339933; font-weight: bold;">&lt;-</span> myVim    <span style="color: green;">&#93;</span> <span style="color: #5d478b; font-style: italic;">-- move webs to main</span>
    <span style="color: #339933; font-weight: bold;">,</span> <span style="color: green;">&#91;</span>className    <span style="color: #339933; font-weight: bold;">=?</span> c            <span style="color: #339933; font-weight: bold;">--&gt;</span> doShift	 <span style="background-color: #3cb371;">&quot;4:chat&quot;</span>   <span style="color: #339933; font-weight: bold;">|</span>   c   <span style="color: #339933; font-weight: bold;">&lt;-</span> myChat   <span style="color: green;">&#93;</span> <span style="color: #5d478b; font-style: italic;">-- move chat to chat</span>
    <span style="color: #339933; font-weight: bold;">,</span> <span style="color: green;">&#91;</span>className    <span style="color: #339933; font-weight: bold;">=?</span> c            <span style="color: #339933; font-weight: bold;">--&gt;</span> doShift  <span style="background-color: #3cb371;">&quot;5:music&quot;</span>  <span style="color: #339933; font-weight: bold;">|</span>   c   <span style="color: #339933; font-weight: bold;">&lt;-</span> myMusic  <span style="color: green;">&#93;</span> <span style="color: #5d478b; font-style: italic;">-- move music to music</span>
    <span style="color: #339933; font-weight: bold;">,</span> <span style="color: green;">&#91;</span>className    <span style="color: #339933; font-weight: bold;">=?</span> c            <span style="color: #339933; font-weight: bold;">--&gt;</span> doShift  <span style="background-color: #3cb371;">&quot;6:gimp&quot;</span>   <span style="color: #339933; font-weight: bold;">|</span>   c   <span style="color: #339933; font-weight: bold;">&lt;-</span> myGimp   <span style="color: green;">&#93;</span> <span style="color: #5d478b; font-style: italic;">-- move img to div</span>
    <span style="color: #339933; font-weight: bold;">,</span> <span style="color: green;">&#91;</span>className    <span style="color: #339933; font-weight: bold;">=?</span> c            <span style="color: #339933; font-weight: bold;">--&gt;</span> doCenterFloat       <span style="color: #339933; font-weight: bold;">|</span>   c   <span style="color: #339933; font-weight: bold;">&lt;-</span> myFloats <span style="color: green;">&#93;</span> <span style="color: #5d478b; font-style: italic;">-- float my floats</span>
    <span style="color: #339933; font-weight: bold;">,</span> <span style="color: green;">&#91;</span>name         <span style="color: #339933; font-weight: bold;">=?</span> n            <span style="color: #339933; font-weight: bold;">--&gt;</span> doCenterFloat       <span style="color: #339933; font-weight: bold;">|</span>   n   <span style="color: #339933; font-weight: bold;">&lt;-</span> myNames  <span style="color: green;">&#93;</span> <span style="color: #5d478b; font-style: italic;">-- float my names</span>
    <span style="color: #339933; font-weight: bold;">,</span> <span style="color: green;">&#91;</span>isFullscreen                 <span style="color: #339933; font-weight: bold;">--&gt;</span> myDoFullFloat                           <span style="color: green;">&#93;</span>
    <span style="color: green;">&#93;</span><span style="color: green;">&#41;</span> 
&nbsp;
    <span style="color: #06c; font-weight: bold;">where</span>
&nbsp;
        role      <span style="color: #339933; font-weight: bold;">=</span> stringProperty <span style="background-color: #3cb371;">&quot;WM_WINDOW_ROLE&quot;</span>
        name      <span style="color: #339933; font-weight: bold;">=</span> stringProperty <span style="background-color: #3cb371;">&quot;WM_NAME&quot;</span>
&nbsp;
        <span style="color: #5d478b; font-style: italic;">-- classnames</span>
        myFloats  <span style="color: #339933; font-weight: bold;">=</span> <span style="color: green;">&#91;</span><span style="background-color: #3cb371;">&quot;Smplayer&quot;</span><span style="color: #339933; font-weight: bold;">,</span><span style="background-color: #3cb371;">&quot;MPlayer&quot;</span><span style="color: #339933; font-weight: bold;">,</span><span style="background-color: #3cb371;">&quot;VirtualBox&quot;</span><span style="color: #339933; font-weight: bold;">,</span><span style="background-color: #3cb371;">&quot;Xmessage&quot;</span><span style="color: #339933; font-weight: bold;">,</span><span style="background-color: #3cb371;">&quot;XFontSel&quot;</span><span style="color: #339933; font-weight: bold;">,</span><span style="background-color: #3cb371;">&quot;Downloads&quot;</span><span style="color: #339933; font-weight: bold;">,</span><span style="background-color: #3cb371;">&quot;Nm-connection-editor&quot;</span><span style="color: green;">&#93;</span>
        myWebs    <span style="color: #339933; font-weight: bold;">=</span> <span style="color: green;">&#91;</span><span style="background-color: #3cb371;">&quot;Firefox&quot;</span><span style="color: #339933; font-weight: bold;">,</span><span style="background-color: #3cb371;">&quot;Google-chrome&quot;</span><span style="color: #339933; font-weight: bold;">,</span><span style="background-color: #3cb371;">&quot;Chromium&quot;</span><span style="color: #339933; font-weight: bold;">,</span> <span style="background-color: #3cb371;">&quot;Chromium-browser&quot;</span><span style="color: green;">&#93;</span>
        myMovie   <span style="color: #339933; font-weight: bold;">=</span> <span style="color: green;">&#91;</span><span style="background-color: #3cb371;">&quot;Boxee&quot;</span><span style="color: #339933; font-weight: bold;">,</span><span style="background-color: #3cb371;">&quot;Trine&quot;</span><span style="color: green;">&#93;</span>
        myMusic	  <span style="color: #339933; font-weight: bold;">=</span> <span style="color: green;">&#91;</span><span style="background-color: #3cb371;">&quot;Rhythmbox&quot;</span><span style="color: #339933; font-weight: bold;">,</span><span style="background-color: #3cb371;">&quot;Spotify&quot;</span><span style="color: green;">&#93;</span>
        myChat	  <span style="color: #339933; font-weight: bold;">=</span> <span style="color: green;">&#91;</span><span style="background-color: #3cb371;">&quot;Pidgin&quot;</span><span style="color: #339933; font-weight: bold;">,</span><span style="background-color: #3cb371;">&quot;Buddy List&quot;</span><span style="color: green;">&#93;</span>
        myGimp	  <span style="color: #339933; font-weight: bold;">=</span> <span style="color: green;">&#91;</span><span style="background-color: #3cb371;">&quot;Gimp&quot;</span><span style="color: green;">&#93;</span>
        myDev	  <span style="color: #339933; font-weight: bold;">=</span> <span style="color: green;">&#91;</span><span style="background-color: #3cb371;">&quot;gnome-terminal&quot;</span><span style="color: green;">&#93;</span>
        myVim	  <span style="color: #339933; font-weight: bold;">=</span> <span style="color: green;">&#91;</span><span style="background-color: #3cb371;">&quot;Gvim&quot;</span><span style="color: green;">&#93;</span>
&nbsp;
        <span style="color: #5d478b; font-style: italic;">-- resources</span>
        myIgnores <span style="color: #339933; font-weight: bold;">=</span> <span style="color: green;">&#91;</span><span style="background-color: #3cb371;">&quot;desktop&quot;</span><span style="color: #339933; font-weight: bold;">,</span><span style="background-color: #3cb371;">&quot;desktop_window&quot;</span><span style="color: #339933; font-weight: bold;">,</span><span style="background-color: #3cb371;">&quot;notify-osd&quot;</span><span style="color: #339933; font-weight: bold;">,</span><span style="background-color: #3cb371;">&quot;stalonetray&quot;</span><span style="color: #339933; font-weight: bold;">,</span><span style="background-color: #3cb371;">&quot;trayer&quot;</span><span style="color: green;">&#93;</span>
&nbsp;
        <span style="color: #5d478b; font-style: italic;">-- names</span>
        myNames   <span style="color: #339933; font-weight: bold;">=</span> <span style="color: green;">&#91;</span><span style="background-color: #3cb371;">&quot;bashrun&quot;</span><span style="color: #339933; font-weight: bold;">,</span><span style="background-color: #3cb371;">&quot;Google Chrome Options&quot;</span><span style="color: #339933; font-weight: bold;">,</span><span style="background-color: #3cb371;">&quot;Chromium Options&quot;</span><span style="color: green;">&#93;</span>
&nbsp;
        <span style="color: #5d478b; font-style: italic;">-- a trick for fullscreen but stil allow focusing of other WSs</span>
        myDoFullFloat <span style="color: #339933; font-weight: bold;">::</span> ManageHook
        myDoFullFloat <span style="color: #339933; font-weight: bold;">=</span> doF W<span style="color: #339933; font-weight: bold;">.</span>focusDown <span style="color: #339933; font-weight: bold;">&lt;+&gt;</span> doFullFloat</pre></div></div>

</p>
<h3>The Log Hook</h3>
<p>
The log hook is what xmonad uses to tell us information about itself. Usually this hook is used in conjunction with other modules such as <em>xmobar</em> or, in my case, <em>dzen2</em>. It tells us info about the status of the different workspaces, selected windows, etcetera. When configuring this hook, you usually pipe its result to the pipe you want to use to show the info.
</p>
<p>
The log hook is also very customizable, you can select colors and icons to be shown. The <a href="http://xmonad.org/xmonad-docs/xmonad-contrib/XMonad-Hooks-DynamicLog.html#v:dynamicLogWithPP" onclick="pageTracker._trackPageview('/outgoing/xmonad.org/xmonad-docs/xmonad-contrib/XMonad-Hooks-DynamicLog.html_v_dynamicLogWithPP?referer=');">documentation page for dynamicLogWithPP</a> shows you all the options. In my configuration, because I use dzen2 as a status bar, I also use some helpers for the colors:
</p>
<p>
<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;">myLogHook <span style="color: #339933; font-weight: bold;">::</span> Handle <span style="color: #339933; font-weight: bold;">-&gt;</span> X <span style="color: green;">&#40;</span><span style="color: green;">&#41;</span>
myLogHook h <span style="color: #339933; font-weight: bold;">=</span> dynamicLogWithPP <span style="color: #339933; font-weight: bold;">$</span> defaultPP
    <span style="color: green;">&#123;</span>
        ppCurrent           <span style="color: #339933; font-weight: bold;">=</span>   dzenColor <span style="background-color: #3cb371;">&quot;#ebac54&quot;</span> <span style="background-color: #3cb371;">&quot;#1B1D1E&quot;</span> <span style="color: #339933; font-weight: bold;">.</span> pad
      <span style="color: #339933; font-weight: bold;">,</span> ppVisible           <span style="color: #339933; font-weight: bold;">=</span>   dzenColor <span style="background-color: #3cb371;">&quot;white&quot;</span> <span style="background-color: #3cb371;">&quot;#1B1D1E&quot;</span> <span style="color: #339933; font-weight: bold;">.</span> pad
      <span style="color: #339933; font-weight: bold;">,</span> ppHidden            <span style="color: #339933; font-weight: bold;">=</span>   dzenColor <span style="background-color: #3cb371;">&quot;white&quot;</span> <span style="background-color: #3cb371;">&quot;#1B1D1E&quot;</span> <span style="color: #339933; font-weight: bold;">.</span> pad
      <span style="color: #339933; font-weight: bold;">,</span> ppHiddenNoWindows   <span style="color: #339933; font-weight: bold;">=</span>   dzenColor <span style="background-color: #3cb371;">&quot;#7b7b7b&quot;</span> <span style="background-color: #3cb371;">&quot;#1B1D1E&quot;</span> <span style="color: #339933; font-weight: bold;">.</span> pad
      <span style="color: #339933; font-weight: bold;">,</span> ppUrgent            <span style="color: #339933; font-weight: bold;">=</span>   dzenColor <span style="background-color: #3cb371;">&quot;#ff0000&quot;</span> <span style="background-color: #3cb371;">&quot;#1B1D1E&quot;</span> <span style="color: #339933; font-weight: bold;">.</span> pad
      <span style="color: #339933; font-weight: bold;">,</span> ppWsSep             <span style="color: #339933; font-weight: bold;">=</span>   <span style="background-color: #3cb371;">&quot; &quot;</span>
      <span style="color: #339933; font-weight: bold;">,</span> ppSep               <span style="color: #339933; font-weight: bold;">=</span>   <span style="background-color: #3cb371;">&quot;  |  &quot;</span>
      <span style="color: #339933; font-weight: bold;">,</span> ppLayout            <span style="color: #339933; font-weight: bold;">=</span>   dzenColor <span style="background-color: #3cb371;">&quot;#ebac54&quot;</span> <span style="background-color: #3cb371;">&quot;#1B1D1E&quot;</span> <span style="color: #339933; font-weight: bold;">.</span>
                                <span style="color: green;">&#40;</span>\x <span style="color: #339933; font-weight: bold;">-&gt;</span> <span style="color: #06c; font-weight: bold;">case</span> x <span style="color: #06c; font-weight: bold;">of</span>
                                    <span style="background-color: #3cb371;">&quot;ResizableTall&quot;</span>             <span style="color: #339933; font-weight: bold;">-&gt;</span>      <span style="background-color: #3cb371;">&quot;^i(&quot;</span> <span style="color: #339933; font-weight: bold;">++</span> myBitmapsDir <span style="color: #339933; font-weight: bold;">++</span> <span style="background-color: #3cb371;">&quot;/tall.xbm)&quot;</span>
                                    <span style="background-color: #3cb371;">&quot;Mirror ResizableTall&quot;</span>      <span style="color: #339933; font-weight: bold;">-&gt;</span>      <span style="background-color: #3cb371;">&quot;^i(&quot;</span> <span style="color: #339933; font-weight: bold;">++</span> myBitmapsDir <span style="color: #339933; font-weight: bold;">++</span> <span style="background-color: #3cb371;">&quot;/mtall.xbm)&quot;</span>
                                    <span style="background-color: #3cb371;">&quot;Full&quot;</span>                      <span style="color: #339933; font-weight: bold;">-&gt;</span>      <span style="background-color: #3cb371;">&quot;^i(&quot;</span> <span style="color: #339933; font-weight: bold;">++</span> myBitmapsDir <span style="color: #339933; font-weight: bold;">++</span> <span style="background-color: #3cb371;">&quot;/full.xbm)&quot;</span>
                                    <span style="background-color: #3cb371;">&quot;Simple Float&quot;</span>              <span style="color: #339933; font-weight: bold;">-&gt;</span>      <span style="background-color: #3cb371;">&quot;~&quot;</span>
                                    <span style="color: #339933; font-weight: bold;">_</span>                           <span style="color: #339933; font-weight: bold;">-&gt;</span>      x
                                <span style="color: green;">&#41;</span>
      <span style="color: #339933; font-weight: bold;">,</span> ppTitle             <span style="color: #339933; font-weight: bold;">=</span>   <span style="color: green;">&#40;</span><span style="background-color: #3cb371;">&quot; &quot;</span> <span style="color: #339933; font-weight: bold;">++</span><span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">.</span> dzenColor <span style="background-color: #3cb371;">&quot;white&quot;</span> <span style="background-color: #3cb371;">&quot;#1B1D1E&quot;</span> <span style="color: #339933; font-weight: bold;">.</span> dzenEscape
      <span style="color: #339933; font-weight: bold;">,</span> ppOutput            <span style="color: #339933; font-weight: bold;">=</span>   hPutStrLn h
    <span style="color: green;">&#125;</span></pre></div></div>

</p>
<p>
As you can see, I can set the colors for the different workspace statuses, and some icons to be able to know which is the current workspace layout. The last line is very important, as it&#8217;s the line that outputs the results to wherever we choose.
</p>
<h3>dzen2 and conky</h3>
<p>
As I told you at the beginning, I&#8217;m using dzen2 as a status bar, and conky to get some fancy system information. To configure this, we have to tell xmonad to spawn the dzen2 and conky processes at the beginning. This can be done inside the main method, and here&#8217;s how it looks like in my configuration:
</p>

<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;">myXmonadBar <span style="color: #339933; font-weight: bold;">=</span> <span style="background-color: #3cb371;">&quot;dzen2 -x '1440' -y '0' -h '24' -w '640' -ta 'l' -fg '#FFFFFF' -bg '#1B1D1E'&quot;</span>
myStatusBar <span style="color: #339933; font-weight: bold;">=</span> <span style="background-color: #3cb371;">&quot;conky -c /home/my_user/.xmonad/.conky_dzen | dzen2 -x '2080' -w '1040' -h '24' -ta 'r' -bg '#1B1D1E' -fg '#FFFFFF' -y '0'&quot;</span>
main <span style="color: #339933; font-weight: bold;">=</span> <span style="color: #06c; font-weight: bold;">do</span>
    dzenLeftBar <span style="color: #339933; font-weight: bold;">&lt;-</span> spawnPipe myXmonadBar
    dzenRightBar <span style="color: #339933; font-weight: bold;">&lt;-</span> spawnPipe myStatusBar
    xmonad <span style="color: #339933; font-weight: bold;">$</span> defaultConfig
      <span style="color: green;">&#123;</span> terminal            <span style="color: #339933; font-weight: bold;">=</span> myTerminal
      <span style="color: #339933; font-weight: bold;">,</span> workspaces          <span style="color: #339933; font-weight: bold;">=</span> myWorkspaces
      <span style="color: #339933; font-weight: bold;">,</span> keys                <span style="color: #339933; font-weight: bold;">=</span> keys'
      <span style="color: #339933; font-weight: bold;">,</span> modMask             <span style="color: #339933; font-weight: bold;">=</span> modMask'
      <span style="color: #339933; font-weight: bold;">,</span> layoutHook          <span style="color: #339933; font-weight: bold;">=</span> layoutHook'
      <span style="color: #339933; font-weight: bold;">,</span> manageHook          <span style="color: #339933; font-weight: bold;">=</span> manageHook'
      <span style="color: #339933; font-weight: bold;">,</span> logHook             <span style="color: #339933; font-weight: bold;">=</span> myLogHook dzenLeftBar <span style="color: #339933; font-weight: bold;">&gt;&gt;</span> fadeInactiveLogHook 0xdddddddd
      <span style="color: #339933; font-weight: bold;">,</span> normalBorderColor   <span style="color: #339933; font-weight: bold;">=</span> colorNormalBorder
      <span style="color: #339933; font-weight: bold;">,</span> focusedBorderColor  <span style="color: #339933; font-weight: bold;">=</span> colorFocusedBorder
      <span style="color: #339933; font-weight: bold;">,</span> borderWidth         <span style="color: #339933; font-weight: bold;">=</span> <span style="color: red;">2</span>
<span style="color: green;">&#125;</span></pre></div></div>

</p>
<p>
Notice that I use two different bars. I&#8217;ll use the left one for xmonad info and the right one for system info. What&#8217;s most important here are the coordinates and size of the bars, and also the configuration file for conky. After spawning the processes, in the main method we tell xmonad to use the <em>dzenLeftBar</em> pipe to output the log info.
</p>
<p>
The right bar is piped to use the conky output, as configured in the <em>.conky_dzen</em> configuration. Conky has lots of options, covered in the <a href="http://conky.sourceforge.net/variables.html" onclick="pageTracker._trackPageview('/outgoing/conky.sourceforge.net/variables.html?referer=');">Conky Objects</a> documentation page. Here&#8217;s my config:
</p>
<p>
<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">background yes
out_to_console yes
out_to_x no
# Update interval in seconds
update_interval 1
&nbsp;
TEXT
^i(/home/my_user/.xmonad/dzen2/cpu.xbm) ^fg(\#FFFFFF)${cpu}% ^i(/home/my_user/.xmonad/dzen2/mem.xbm) ^fg(\#FFFFFF)${memperc}% ^fg(\#ebac54) ${if_existing /proc/net/route eth1} ^i(/home/my_user/.xmonad/dzen2/net_wired.xbm) ^fg(\#00aa4a) ^i(/home/my_user/.xmonad/dzen2/net_down_03.xbm)${downspeed eth1} ^fg(\#ff3333) ^i(/home/my_user/.xmonad/dzen2/net_up_03.xbm)${upspeed eth1} ^fg(\#ebac54) ^i(/home/my_user/.xmonad/dzen2/mpd.xbm) ^fg(\#00ffff)${exec rhythmbox-client --print-playing-format &quot;%aa-%at-%tt&quot; | cut -c-70} ^fg(\#ebac54) ^i(/home/my_user/.xmonad/dzen2/volume.xbm) ^fg(\#00ffff)${exec amixer get Headphone | egrep -o &quot;[0-9]+%&quot; | head -1 | egrep -o &quot;[0-9]*&quot;}% ^fg(\#ebac54) ^i(/home/my_user/.xmonad/dzen2/clock.xbm) ^fg(\#FFFFFF) ${time %d %m %Y} ^fg(\#ebac54) ${time %R}</pre></div></div>

</p>
<p>
The important things here are the background line and the out_to_x line, which tell conky to run in the background and not to output the results directly to the X. You can then configure the <em>TEXT</em> variable to display whatever variables you want.
</p>
<h3>Putting it all together</h3>
<p>
After all the work is done, it&#8217;s time to finally put it all together. Here&#8217;s the final configuration file that I currently use and that I&#8217;ve been showing you in this post:
</p>

<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;"><span style="color: #5d478b; font-style: italic;">-- ~/.xmonad/xmonad.hs</span>
<span style="color: #5d478b; font-style: italic;">-- Imports {{{</span>
<span style="color: #06c; font-weight: bold;">import</span> XMonad
<span style="color: #5d478b; font-style: italic;">-- Prompt</span>
<span style="color: #06c; font-weight: bold;">import</span> XMonad<span style="color: #339933; font-weight: bold;">.</span>Prompt
<span style="color: #06c; font-weight: bold;">import</span> XMonad<span style="color: #339933; font-weight: bold;">.</span>Prompt<span style="color: #339933; font-weight: bold;">.</span>RunOrRaise <span style="color: green;">&#40;</span>runOrRaisePrompt<span style="color: green;">&#41;</span>
<span style="color: #06c; font-weight: bold;">import</span> XMonad<span style="color: #339933; font-weight: bold;">.</span>Prompt<span style="color: #339933; font-weight: bold;">.</span>AppendFile <span style="color: green;">&#40;</span>appendFilePrompt<span style="color: green;">&#41;</span>
<span style="color: #5d478b; font-style: italic;">-- Hooks</span>
<span style="color: #06c; font-weight: bold;">import</span> XMonad<span style="color: #339933; font-weight: bold;">.</span>Operations
&nbsp;
<span style="color: #06c; font-weight: bold;">import</span> System<span style="color: #339933; font-weight: bold;">.</span><span style="color: #cccc00; font-weight: bold;">IO</span>
<span style="color: #06c; font-weight: bold;">import</span> System<span style="color: #339933; font-weight: bold;">.</span>Exit
&nbsp;
<span style="color: #06c; font-weight: bold;">import</span> XMonad<span style="color: #339933; font-weight: bold;">.</span>Util<span style="color: #339933; font-weight: bold;">.</span>Run
&nbsp;
&nbsp;
<span style="color: #06c; font-weight: bold;">import</span> XMonad<span style="color: #339933; font-weight: bold;">.</span>Actions<span style="color: #339933; font-weight: bold;">.</span>CycleWS
&nbsp;
<span style="color: #06c; font-weight: bold;">import</span> XMonad<span style="color: #339933; font-weight: bold;">.</span>Hooks<span style="color: #339933; font-weight: bold;">.</span>ManageDocks
<span style="color: #06c; font-weight: bold;">import</span> XMonad<span style="color: #339933; font-weight: bold;">.</span>Hooks<span style="color: #339933; font-weight: bold;">.</span>ManageHelpers
<span style="color: #06c; font-weight: bold;">import</span> XMonad<span style="color: #339933; font-weight: bold;">.</span>Hooks<span style="color: #339933; font-weight: bold;">.</span>SetWMName
<span style="color: #06c; font-weight: bold;">import</span> XMonad<span style="color: #339933; font-weight: bold;">.</span>Hooks<span style="color: #339933; font-weight: bold;">.</span>DynamicLog
<span style="color: #06c; font-weight: bold;">import</span> XMonad<span style="color: #339933; font-weight: bold;">.</span>Hooks<span style="color: #339933; font-weight: bold;">.</span>UrgencyHook
<span style="color: #06c; font-weight: bold;">import</span> XMonad<span style="color: #339933; font-weight: bold;">.</span>Hooks<span style="color: #339933; font-weight: bold;">.</span>FadeInactive
<span style="color: #06c; font-weight: bold;">import</span> XMonad<span style="color: #339933; font-weight: bold;">.</span>Hooks<span style="color: #339933; font-weight: bold;">.</span>EwmhDesktops
&nbsp;
<span style="color: #06c; font-weight: bold;">import</span> XMonad<span style="color: #339933; font-weight: bold;">.</span>Layout<span style="color: #339933; font-weight: bold;">.</span>NoBorders <span style="color: green;">&#40;</span>smartBorders<span style="color: #339933; font-weight: bold;">,</span> noBorders<span style="color: green;">&#41;</span>
<span style="color: #06c; font-weight: bold;">import</span> XMonad<span style="color: #339933; font-weight: bold;">.</span>Layout<span style="color: #339933; font-weight: bold;">.</span>PerWorkspace <span style="color: green;">&#40;</span>onWorkspace<span style="color: #339933; font-weight: bold;">,</span> onWorkspaces<span style="color: green;">&#41;</span>
<span style="color: #06c; font-weight: bold;">import</span> XMonad<span style="color: #339933; font-weight: bold;">.</span>Layout<span style="color: #339933; font-weight: bold;">.</span>Reflect <span style="color: green;">&#40;</span>reflectHoriz<span style="color: green;">&#41;</span>
<span style="color: #06c; font-weight: bold;">import</span> XMonad<span style="color: #339933; font-weight: bold;">.</span>Layout<span style="color: #339933; font-weight: bold;">.</span>IM
<span style="color: #06c; font-weight: bold;">import</span> XMonad<span style="color: #339933; font-weight: bold;">.</span>Layout<span style="color: #339933; font-weight: bold;">.</span>SimpleFloat
<span style="color: #06c; font-weight: bold;">import</span> XMonad<span style="color: #339933; font-weight: bold;">.</span>Layout<span style="color: #339933; font-weight: bold;">.</span>Spacing
<span style="color: #06c; font-weight: bold;">import</span> XMonad<span style="color: #339933; font-weight: bold;">.</span>Layout<span style="color: #339933; font-weight: bold;">.</span>ResizableTile
<span style="color: #06c; font-weight: bold;">import</span> XMonad<span style="color: #339933; font-weight: bold;">.</span>Layout<span style="color: #339933; font-weight: bold;">.</span>LayoutHints
<span style="color: #06c; font-weight: bold;">import</span> XMonad<span style="color: #339933; font-weight: bold;">.</span>Layout<span style="color: #339933; font-weight: bold;">.</span>LayoutModifier
<span style="color: #06c; font-weight: bold;">import</span> XMonad<span style="color: #339933; font-weight: bold;">.</span>Layout<span style="color: #339933; font-weight: bold;">.</span>Grid
&nbsp;
<span style="color: #06c; font-weight: bold;">import</span> Data<span style="color: #339933; font-weight: bold;">.</span>Ratio <span style="color: green;">&#40;</span><span style="color: green;">&#40;</span><span style="color: #339933; font-weight: bold;">%</span><span style="color: green;">&#41;</span><span style="color: green;">&#41;</span>
&nbsp;
<span style="color: #06c; font-weight: bold;">import</span> <span style="color: #06c; font-weight: bold;">qualified</span> XMonad<span style="color: #339933; font-weight: bold;">.</span>StackSet <span style="color: #06c; font-weight: bold;">as</span> W
<span style="color: #06c; font-weight: bold;">import</span> <span style="color: #06c; font-weight: bold;">qualified</span> Data<span style="color: #339933; font-weight: bold;">.</span>Map <span style="color: #06c; font-weight: bold;">as</span> M
&nbsp;
<span style="color: #5d478b; font-style: italic;">--}}}</span>
&nbsp;
<span style="color: #5d478b; font-style: italic;">-- Config {{{</span>
<span style="color: #5d478b; font-style: italic;">-- Define Terminal</span>
myTerminal      <span style="color: #339933; font-weight: bold;">=</span> <span style="background-color: #3cb371;">&quot;gnome-terminal&quot;</span>
<span style="color: #5d478b; font-style: italic;">-- Define modMask</span>
modMask' <span style="color: #339933; font-weight: bold;">::</span> KeyMask
modMask' <span style="color: #339933; font-weight: bold;">=</span> mod4Mask
<span style="color: #5d478b; font-style: italic;">-- Define workspaces</span>
myWorkspaces    <span style="color: #339933; font-weight: bold;">=</span> <span style="color: green;">&#91;</span><span style="background-color: #3cb371;">&quot;1:main&quot;</span><span style="color: #339933; font-weight: bold;">,</span><span style="background-color: #3cb371;">&quot;2:web&quot;</span><span style="color: #339933; font-weight: bold;">,</span><span style="background-color: #3cb371;">&quot;3:vim&quot;</span><span style="color: #339933; font-weight: bold;">,</span><span style="background-color: #3cb371;">&quot;4:chat&quot;</span><span style="color: #339933; font-weight: bold;">,</span><span style="background-color: #3cb371;">&quot;5:music&quot;</span><span style="color: #339933; font-weight: bold;">,</span> <span style="background-color: #3cb371;">&quot;6:gimp&quot;</span><span style="color: green;">&#93;</span>
<span style="color: #5d478b; font-style: italic;">-- Dzen/Conky</span>
myXmonadBar <span style="color: #339933; font-weight: bold;">=</span> <span style="background-color: #3cb371;">&quot;dzen2 -x '1440' -y '0' -h '24' -w '640' -ta 'l' -fg '#FFFFFF' -bg '#1B1D1E'&quot;</span>
myStatusBar <span style="color: #339933; font-weight: bold;">=</span> <span style="background-color: #3cb371;">&quot;conky -c /home/my_user/.xmonad/.conky_dzen | dzen2 -x '2080' -w '1040' -h '24' -ta 'r' -bg '#1B1D1E' -fg '#FFFFFF' -y '0'&quot;</span>
myBitmapsDir <span style="color: #339933; font-weight: bold;">=</span> <span style="background-color: #3cb371;">&quot;/home/my_user/.xmonad/dzen2&quot;</span>
<span style="color: #5d478b; font-style: italic;">--}}}</span>
<span style="color: #5d478b; font-style: italic;">-- Main {{{</span>
main <span style="color: #339933; font-weight: bold;">=</span> <span style="color: #06c; font-weight: bold;">do</span>
    dzenLeftBar <span style="color: #339933; font-weight: bold;">&lt;-</span> spawnPipe myXmonadBar
    dzenRightBar <span style="color: #339933; font-weight: bold;">&lt;-</span> spawnPipe myStatusBar
    xmonad <span style="color: #339933; font-weight: bold;">$</span> defaultConfig
      <span style="color: green;">&#123;</span> terminal            <span style="color: #339933; font-weight: bold;">=</span> myTerminal
      <span style="color: #339933; font-weight: bold;">,</span> workspaces          <span style="color: #339933; font-weight: bold;">=</span> myWorkspaces
      <span style="color: #339933; font-weight: bold;">,</span> keys                <span style="color: #339933; font-weight: bold;">=</span> keys'
      <span style="color: #339933; font-weight: bold;">,</span> modMask             <span style="color: #339933; font-weight: bold;">=</span> modMask'
      <span style="color: #339933; font-weight: bold;">,</span> layoutHook          <span style="color: #339933; font-weight: bold;">=</span> layoutHook'
      <span style="color: #339933; font-weight: bold;">,</span> manageHook          <span style="color: #339933; font-weight: bold;">=</span> manageHook'
      <span style="color: #339933; font-weight: bold;">,</span> logHook             <span style="color: #339933; font-weight: bold;">=</span> myLogHook dzenLeftBar <span style="color: #339933; font-weight: bold;">&gt;&gt;</span> fadeInactiveLogHook 0xdddddddd
      <span style="color: #339933; font-weight: bold;">,</span> normalBorderColor   <span style="color: #339933; font-weight: bold;">=</span> colorNormalBorder
      <span style="color: #339933; font-weight: bold;">,</span> focusedBorderColor  <span style="color: #339933; font-weight: bold;">=</span> colorFocusedBorder
      <span style="color: #339933; font-weight: bold;">,</span> borderWidth         <span style="color: #339933; font-weight: bold;">=</span> <span style="color: red;">2</span>
<span style="color: green;">&#125;</span>
<span style="color: #5d478b; font-style: italic;">--}}}</span>
&nbsp;
&nbsp;
<span style="color: #5d478b; font-style: italic;">-- Hooks {{{</span>
<span style="color: #5d478b; font-style: italic;">-- ManageHook {{{</span>
manageHook' <span style="color: #339933; font-weight: bold;">::</span> ManageHook
manageHook' <span style="color: #339933; font-weight: bold;">=</span> <span style="color: green;">&#40;</span>composeAll <span style="color: #339933; font-weight: bold;">.</span> <span style="font-weight: bold;">concat</span> <span style="color: #339933; font-weight: bold;">$</span>
    <span style="color: green;">&#91;</span> <span style="color: green;">&#91;</span>resource     <span style="color: #339933; font-weight: bold;">=?</span> r            <span style="color: #339933; font-weight: bold;">--&gt;</span> doIgnore            <span style="color: #339933; font-weight: bold;">|</span>   r   <span style="color: #339933; font-weight: bold;">&lt;-</span> myIgnores<span style="color: green;">&#93;</span> <span style="color: #5d478b; font-style: italic;">-- ignore desktop</span>
    <span style="color: #339933; font-weight: bold;">,</span> <span style="color: green;">&#91;</span>className    <span style="color: #339933; font-weight: bold;">=?</span> c            <span style="color: #339933; font-weight: bold;">--&gt;</span> doShift  <span style="background-color: #3cb371;">&quot;1:main&quot;</span>   <span style="color: #339933; font-weight: bold;">|</span>   c   <span style="color: #339933; font-weight: bold;">&lt;-</span> myDev    <span style="color: green;">&#93;</span> <span style="color: #5d478b; font-style: italic;">-- move dev to main</span>
    <span style="color: #339933; font-weight: bold;">,</span> <span style="color: green;">&#91;</span>className    <span style="color: #339933; font-weight: bold;">=?</span> c            <span style="color: #339933; font-weight: bold;">--&gt;</span> doShift  <span style="background-color: #3cb371;">&quot;2:web&quot;</span>    <span style="color: #339933; font-weight: bold;">|</span>   c   <span style="color: #339933; font-weight: bold;">&lt;-</span> myWebs   <span style="color: green;">&#93;</span> <span style="color: #5d478b; font-style: italic;">-- move webs to main</span>
    <span style="color: #339933; font-weight: bold;">,</span> <span style="color: green;">&#91;</span>className    <span style="color: #339933; font-weight: bold;">=?</span> c            <span style="color: #339933; font-weight: bold;">--&gt;</span> doShift  <span style="background-color: #3cb371;">&quot;3:vim&quot;</span>    <span style="color: #339933; font-weight: bold;">|</span>   c   <span style="color: #339933; font-weight: bold;">&lt;-</span> myVim    <span style="color: green;">&#93;</span> <span style="color: #5d478b; font-style: italic;">-- move webs to main</span>
    <span style="color: #339933; font-weight: bold;">,</span> <span style="color: green;">&#91;</span>className    <span style="color: #339933; font-weight: bold;">=?</span> c            <span style="color: #339933; font-weight: bold;">--&gt;</span> doShift	 <span style="background-color: #3cb371;">&quot;4:chat&quot;</span>   <span style="color: #339933; font-weight: bold;">|</span>   c   <span style="color: #339933; font-weight: bold;">&lt;-</span> myChat   <span style="color: green;">&#93;</span> <span style="color: #5d478b; font-style: italic;">-- move chat to chat</span>
    <span style="color: #339933; font-weight: bold;">,</span> <span style="color: green;">&#91;</span>className    <span style="color: #339933; font-weight: bold;">=?</span> c            <span style="color: #339933; font-weight: bold;">--&gt;</span> doShift  <span style="background-color: #3cb371;">&quot;5:music&quot;</span>  <span style="color: #339933; font-weight: bold;">|</span>   c   <span style="color: #339933; font-weight: bold;">&lt;-</span> myMusic  <span style="color: green;">&#93;</span> <span style="color: #5d478b; font-style: italic;">-- move music to music</span>
    <span style="color: #339933; font-weight: bold;">,</span> <span style="color: green;">&#91;</span>className    <span style="color: #339933; font-weight: bold;">=?</span> c            <span style="color: #339933; font-weight: bold;">--&gt;</span> doShift  <span style="background-color: #3cb371;">&quot;6:gimp&quot;</span>   <span style="color: #339933; font-weight: bold;">|</span>   c   <span style="color: #339933; font-weight: bold;">&lt;-</span> myGimp   <span style="color: green;">&#93;</span> <span style="color: #5d478b; font-style: italic;">-- move img to div</span>
    <span style="color: #339933; font-weight: bold;">,</span> <span style="color: green;">&#91;</span>className    <span style="color: #339933; font-weight: bold;">=?</span> c            <span style="color: #339933; font-weight: bold;">--&gt;</span> doCenterFloat       <span style="color: #339933; font-weight: bold;">|</span>   c   <span style="color: #339933; font-weight: bold;">&lt;-</span> myFloats <span style="color: green;">&#93;</span> <span style="color: #5d478b; font-style: italic;">-- float my floats</span>
    <span style="color: #339933; font-weight: bold;">,</span> <span style="color: green;">&#91;</span>name         <span style="color: #339933; font-weight: bold;">=?</span> n            <span style="color: #339933; font-weight: bold;">--&gt;</span> doCenterFloat       <span style="color: #339933; font-weight: bold;">|</span>   n   <span style="color: #339933; font-weight: bold;">&lt;-</span> myNames  <span style="color: green;">&#93;</span> <span style="color: #5d478b; font-style: italic;">-- float my names</span>
    <span style="color: #339933; font-weight: bold;">,</span> <span style="color: green;">&#91;</span>isFullscreen                 <span style="color: #339933; font-weight: bold;">--&gt;</span> myDoFullFloat                           <span style="color: green;">&#93;</span>
    <span style="color: green;">&#93;</span><span style="color: green;">&#41;</span> 
&nbsp;
    <span style="color: #06c; font-weight: bold;">where</span>
&nbsp;
        role      <span style="color: #339933; font-weight: bold;">=</span> stringProperty <span style="background-color: #3cb371;">&quot;WM_WINDOW_ROLE&quot;</span>
        name      <span style="color: #339933; font-weight: bold;">=</span> stringProperty <span style="background-color: #3cb371;">&quot;WM_NAME&quot;</span>
&nbsp;
        <span style="color: #5d478b; font-style: italic;">-- classnames</span>
        myFloats  <span style="color: #339933; font-weight: bold;">=</span> <span style="color: green;">&#91;</span><span style="background-color: #3cb371;">&quot;Smplayer&quot;</span><span style="color: #339933; font-weight: bold;">,</span><span style="background-color: #3cb371;">&quot;MPlayer&quot;</span><span style="color: #339933; font-weight: bold;">,</span><span style="background-color: #3cb371;">&quot;VirtualBox&quot;</span><span style="color: #339933; font-weight: bold;">,</span><span style="background-color: #3cb371;">&quot;Xmessage&quot;</span><span style="color: #339933; font-weight: bold;">,</span><span style="background-color: #3cb371;">&quot;XFontSel&quot;</span><span style="color: #339933; font-weight: bold;">,</span><span style="background-color: #3cb371;">&quot;Downloads&quot;</span><span style="color: #339933; font-weight: bold;">,</span><span style="background-color: #3cb371;">&quot;Nm-connection-editor&quot;</span><span style="color: green;">&#93;</span>
        myWebs    <span style="color: #339933; font-weight: bold;">=</span> <span style="color: green;">&#91;</span><span style="background-color: #3cb371;">&quot;Firefox&quot;</span><span style="color: #339933; font-weight: bold;">,</span><span style="background-color: #3cb371;">&quot;Google-chrome&quot;</span><span style="color: #339933; font-weight: bold;">,</span><span style="background-color: #3cb371;">&quot;Chromium&quot;</span><span style="color: #339933; font-weight: bold;">,</span> <span style="background-color: #3cb371;">&quot;Chromium-browser&quot;</span><span style="color: green;">&#93;</span>
        myMovie   <span style="color: #339933; font-weight: bold;">=</span> <span style="color: green;">&#91;</span><span style="background-color: #3cb371;">&quot;Boxee&quot;</span><span style="color: #339933; font-weight: bold;">,</span><span style="background-color: #3cb371;">&quot;Trine&quot;</span><span style="color: green;">&#93;</span>
        myMusic	  <span style="color: #339933; font-weight: bold;">=</span> <span style="color: green;">&#91;</span><span style="background-color: #3cb371;">&quot;Rhythmbox&quot;</span><span style="color: #339933; font-weight: bold;">,</span><span style="background-color: #3cb371;">&quot;Spotify&quot;</span><span style="color: green;">&#93;</span>
        myChat	  <span style="color: #339933; font-weight: bold;">=</span> <span style="color: green;">&#91;</span><span style="background-color: #3cb371;">&quot;Pidgin&quot;</span><span style="color: #339933; font-weight: bold;">,</span><span style="background-color: #3cb371;">&quot;Buddy List&quot;</span><span style="color: green;">&#93;</span>
        myGimp	  <span style="color: #339933; font-weight: bold;">=</span> <span style="color: green;">&#91;</span><span style="background-color: #3cb371;">&quot;Gimp&quot;</span><span style="color: green;">&#93;</span>
        myDev	  <span style="color: #339933; font-weight: bold;">=</span> <span style="color: green;">&#91;</span><span style="background-color: #3cb371;">&quot;gnome-terminal&quot;</span><span style="color: green;">&#93;</span>
        myVim	  <span style="color: #339933; font-weight: bold;">=</span> <span style="color: green;">&#91;</span><span style="background-color: #3cb371;">&quot;Gvim&quot;</span><span style="color: green;">&#93;</span>
&nbsp;
        <span style="color: #5d478b; font-style: italic;">-- resources</span>
        myIgnores <span style="color: #339933; font-weight: bold;">=</span> <span style="color: green;">&#91;</span><span style="background-color: #3cb371;">&quot;desktop&quot;</span><span style="color: #339933; font-weight: bold;">,</span><span style="background-color: #3cb371;">&quot;desktop_window&quot;</span><span style="color: #339933; font-weight: bold;">,</span><span style="background-color: #3cb371;">&quot;notify-osd&quot;</span><span style="color: #339933; font-weight: bold;">,</span><span style="background-color: #3cb371;">&quot;stalonetray&quot;</span><span style="color: #339933; font-weight: bold;">,</span><span style="background-color: #3cb371;">&quot;trayer&quot;</span><span style="color: green;">&#93;</span>
&nbsp;
        <span style="color: #5d478b; font-style: italic;">-- names</span>
        myNames   <span style="color: #339933; font-weight: bold;">=</span> <span style="color: green;">&#91;</span><span style="background-color: #3cb371;">&quot;bashrun&quot;</span><span style="color: #339933; font-weight: bold;">,</span><span style="background-color: #3cb371;">&quot;Google Chrome Options&quot;</span><span style="color: #339933; font-weight: bold;">,</span><span style="background-color: #3cb371;">&quot;Chromium Options&quot;</span><span style="color: green;">&#93;</span>
&nbsp;
<span style="color: #5d478b; font-style: italic;">-- a trick for fullscreen but stil allow focusing of other WSs</span>
myDoFullFloat <span style="color: #339933; font-weight: bold;">::</span> ManageHook
myDoFullFloat <span style="color: #339933; font-weight: bold;">=</span> doF W<span style="color: #339933; font-weight: bold;">.</span>focusDown <span style="color: #339933; font-weight: bold;">&lt;+&gt;</span> doFullFloat
<span style="color: #5d478b; font-style: italic;">-- }}}</span>
layoutHook'  <span style="color: #339933; font-weight: bold;">=</span>  onWorkspaces <span style="color: green;">&#91;</span><span style="background-color: #3cb371;">&quot;1:main&quot;</span><span style="color: #339933; font-weight: bold;">,</span><span style="background-color: #3cb371;">&quot;5:music&quot;</span><span style="color: green;">&#93;</span> customLayout <span style="color: #339933; font-weight: bold;">$</span> 
                onWorkspaces <span style="color: green;">&#91;</span><span style="background-color: #3cb371;">&quot;6:gimp&quot;</span><span style="color: green;">&#93;</span> gimpLayout <span style="color: #339933; font-weight: bold;">$</span> 
                onWorkspaces <span style="color: green;">&#91;</span><span style="background-color: #3cb371;">&quot;4:chat&quot;</span><span style="color: green;">&#93;</span> imLayout <span style="color: #339933; font-weight: bold;">$</span>
                customLayout2
&nbsp;
<span style="color: #5d478b; font-style: italic;">--Bar</span>
myLogHook <span style="color: #339933; font-weight: bold;">::</span> Handle <span style="color: #339933; font-weight: bold;">-&gt;</span> X <span style="color: green;">&#40;</span><span style="color: green;">&#41;</span>
myLogHook h <span style="color: #339933; font-weight: bold;">=</span> dynamicLogWithPP <span style="color: #339933; font-weight: bold;">$</span> defaultPP
    <span style="color: green;">&#123;</span>
        ppCurrent           <span style="color: #339933; font-weight: bold;">=</span>   dzenColor <span style="background-color: #3cb371;">&quot;#ebac54&quot;</span> <span style="background-color: #3cb371;">&quot;#1B1D1E&quot;</span> <span style="color: #339933; font-weight: bold;">.</span> pad
      <span style="color: #339933; font-weight: bold;">,</span> ppVisible           <span style="color: #339933; font-weight: bold;">=</span>   dzenColor <span style="background-color: #3cb371;">&quot;white&quot;</span> <span style="background-color: #3cb371;">&quot;#1B1D1E&quot;</span> <span style="color: #339933; font-weight: bold;">.</span> pad
      <span style="color: #339933; font-weight: bold;">,</span> ppHidden            <span style="color: #339933; font-weight: bold;">=</span>   dzenColor <span style="background-color: #3cb371;">&quot;white&quot;</span> <span style="background-color: #3cb371;">&quot;#1B1D1E&quot;</span> <span style="color: #339933; font-weight: bold;">.</span> pad
      <span style="color: #339933; font-weight: bold;">,</span> ppHiddenNoWindows   <span style="color: #339933; font-weight: bold;">=</span>   dzenColor <span style="background-color: #3cb371;">&quot;#7b7b7b&quot;</span> <span style="background-color: #3cb371;">&quot;#1B1D1E&quot;</span> <span style="color: #339933; font-weight: bold;">.</span> pad
      <span style="color: #339933; font-weight: bold;">,</span> ppUrgent            <span style="color: #339933; font-weight: bold;">=</span>   dzenColor <span style="background-color: #3cb371;">&quot;#ff0000&quot;</span> <span style="background-color: #3cb371;">&quot;#1B1D1E&quot;</span> <span style="color: #339933; font-weight: bold;">.</span> pad
      <span style="color: #339933; font-weight: bold;">,</span> ppWsSep             <span style="color: #339933; font-weight: bold;">=</span>   <span style="background-color: #3cb371;">&quot; &quot;</span>
      <span style="color: #339933; font-weight: bold;">,</span> ppSep               <span style="color: #339933; font-weight: bold;">=</span>   <span style="background-color: #3cb371;">&quot;  |  &quot;</span>
      <span style="color: #339933; font-weight: bold;">,</span> ppLayout            <span style="color: #339933; font-weight: bold;">=</span>   dzenColor <span style="background-color: #3cb371;">&quot;#ebac54&quot;</span> <span style="background-color: #3cb371;">&quot;#1B1D1E&quot;</span> <span style="color: #339933; font-weight: bold;">.</span>
                                <span style="color: green;">&#40;</span>\x <span style="color: #339933; font-weight: bold;">-&gt;</span> <span style="color: #06c; font-weight: bold;">case</span> x <span style="color: #06c; font-weight: bold;">of</span>
                                    <span style="background-color: #3cb371;">&quot;ResizableTall&quot;</span>             <span style="color: #339933; font-weight: bold;">-&gt;</span>      <span style="background-color: #3cb371;">&quot;^i(&quot;</span> <span style="color: #339933; font-weight: bold;">++</span> myBitmapsDir <span style="color: #339933; font-weight: bold;">++</span> <span style="background-color: #3cb371;">&quot;/tall.xbm)&quot;</span>
                                    <span style="background-color: #3cb371;">&quot;Mirror ResizableTall&quot;</span>      <span style="color: #339933; font-weight: bold;">-&gt;</span>      <span style="background-color: #3cb371;">&quot;^i(&quot;</span> <span style="color: #339933; font-weight: bold;">++</span> myBitmapsDir <span style="color: #339933; font-weight: bold;">++</span> <span style="background-color: #3cb371;">&quot;/mtall.xbm)&quot;</span>
                                    <span style="background-color: #3cb371;">&quot;Full&quot;</span>                      <span style="color: #339933; font-weight: bold;">-&gt;</span>      <span style="background-color: #3cb371;">&quot;^i(&quot;</span> <span style="color: #339933; font-weight: bold;">++</span> myBitmapsDir <span style="color: #339933; font-weight: bold;">++</span> <span style="background-color: #3cb371;">&quot;/full.xbm)&quot;</span>
                                    <span style="background-color: #3cb371;">&quot;Simple Float&quot;</span>              <span style="color: #339933; font-weight: bold;">-&gt;</span>      <span style="background-color: #3cb371;">&quot;~&quot;</span>
                                    <span style="color: #339933; font-weight: bold;">_</span>                           <span style="color: #339933; font-weight: bold;">-&gt;</span>      x
                                <span style="color: green;">&#41;</span>
      <span style="color: #339933; font-weight: bold;">,</span> ppTitle             <span style="color: #339933; font-weight: bold;">=</span>   <span style="color: green;">&#40;</span><span style="background-color: #3cb371;">&quot; &quot;</span> <span style="color: #339933; font-weight: bold;">++</span><span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">.</span> dzenColor <span style="background-color: #3cb371;">&quot;white&quot;</span> <span style="background-color: #3cb371;">&quot;#1B1D1E&quot;</span> <span style="color: #339933; font-weight: bold;">.</span> dzenEscape
      <span style="color: #339933; font-weight: bold;">,</span> ppOutput            <span style="color: #339933; font-weight: bold;">=</span>   hPutStrLn h
    <span style="color: green;">&#125;</span>
&nbsp;
<span style="color: #5d478b; font-style: italic;">-- Layout</span>
customLayout <span style="color: #339933; font-weight: bold;">=</span> avoidStruts <span style="color: #339933; font-weight: bold;">$</span> tiled <span style="color: #339933; font-weight: bold;">|||</span> Mirror tiled <span style="color: #339933; font-weight: bold;">|||</span> Full <span style="color: #339933; font-weight: bold;">|||</span> simpleFloat
  <span style="color: #06c; font-weight: bold;">where</span>
    tiled   <span style="color: #339933; font-weight: bold;">=</span> ResizableTall <span style="color: red;">1</span> <span style="color: green;">&#40;</span><span style="color: red;">2</span><span style="color: #339933; font-weight: bold;">/</span><span style="color: red;">100</span><span style="color: green;">&#41;</span> <span style="color: green;">&#40;</span><span style="color: red;">1</span><span style="color: #339933; font-weight: bold;">/</span><span style="color: red;">2</span><span style="color: green;">&#41;</span> <span style="color: green;">&#91;</span><span style="color: green;">&#93;</span>
&nbsp;
customLayout2 <span style="color: #339933; font-weight: bold;">=</span> avoidStruts <span style="color: #339933; font-weight: bold;">$</span> Full <span style="color: #339933; font-weight: bold;">|||</span> tiled <span style="color: #339933; font-weight: bold;">|||</span> Mirror tiled <span style="color: #339933; font-weight: bold;">|||</span> simpleFloat
  <span style="color: #06c; font-weight: bold;">where</span>
    tiled   <span style="color: #339933; font-weight: bold;">=</span> ResizableTall <span style="color: red;">1</span> <span style="color: green;">&#40;</span><span style="color: red;">2</span><span style="color: #339933; font-weight: bold;">/</span><span style="color: red;">100</span><span style="color: green;">&#41;</span> <span style="color: green;">&#40;</span><span style="color: red;">1</span><span style="color: #339933; font-weight: bold;">/</span><span style="color: red;">2</span><span style="color: green;">&#41;</span> <span style="color: green;">&#91;</span><span style="color: green;">&#93;</span>
&nbsp;
gimpLayout  <span style="color: #339933; font-weight: bold;">=</span> avoidStruts <span style="color: #339933; font-weight: bold;">$</span> withIM <span style="color: green;">&#40;</span><span style="color: red;">0.11</span><span style="color: green;">&#41;</span> <span style="color: green;">&#40;</span>Role <span style="background-color: #3cb371;">&quot;gimp-toolbox&quot;</span><span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">$</span>
              reflectHoriz <span style="color: #339933; font-weight: bold;">$</span>
              withIM <span style="color: green;">&#40;</span><span style="color: red;">0.15</span><span style="color: green;">&#41;</span> <span style="color: green;">&#40;</span>Role <span style="background-color: #3cb371;">&quot;gimp-dock&quot;</span><span style="color: green;">&#41;</span> Full
&nbsp;
imLayout    <span style="color: #339933; font-weight: bold;">=</span> avoidStruts <span style="color: #339933; font-weight: bold;">$</span> withIM <span style="color: green;">&#40;</span><span style="color: red;">1</span><span style="color: #339933; font-weight: bold;">%</span>5<span style="color: green;">&#41;</span> <span style="color: green;">&#40;</span>And <span style="color: green;">&#40;</span>ClassName <span style="background-color: #3cb371;">&quot;Pidgin&quot;</span><span style="color: green;">&#41;</span> <span style="color: green;">&#40;</span>Role <span style="background-color: #3cb371;">&quot;buddy_list&quot;</span><span style="color: green;">&#41;</span><span style="color: green;">&#41;</span> Grid 
<span style="color: #5d478b; font-style: italic;">--}}}</span>
<span style="color: #5d478b; font-style: italic;">-- Theme {{{</span>
<span style="color: #5d478b; font-style: italic;">-- Color names are easier to remember:</span>
colorOrange         <span style="color: #339933; font-weight: bold;">=</span> <span style="background-color: #3cb371;">&quot;#FD971F&quot;</span>
colorDarkGray       <span style="color: #339933; font-weight: bold;">=</span> <span style="background-color: #3cb371;">&quot;#1B1D1E&quot;</span>
colorPink           <span style="color: #339933; font-weight: bold;">=</span> <span style="background-color: #3cb371;">&quot;#F92672&quot;</span>
colorGreen          <span style="color: #339933; font-weight: bold;">=</span> <span style="background-color: #3cb371;">&quot;#A6E22E&quot;</span>
colorBlue           <span style="color: #339933; font-weight: bold;">=</span> <span style="background-color: #3cb371;">&quot;#66D9EF&quot;</span>
colorYellow         <span style="color: #339933; font-weight: bold;">=</span> <span style="background-color: #3cb371;">&quot;#E6DB74&quot;</span>
colorWhite          <span style="color: #339933; font-weight: bold;">=</span> <span style="background-color: #3cb371;">&quot;#CCCCC6&quot;</span>
&nbsp;
colorNormalBorder   <span style="color: #339933; font-weight: bold;">=</span> <span style="background-color: #3cb371;">&quot;#CCCCC6&quot;</span>
colorFocusedBorder  <span style="color: #339933; font-weight: bold;">=</span> <span style="background-color: #3cb371;">&quot;#fd971f&quot;</span>
&nbsp;
&nbsp;
barFont  <span style="color: #339933; font-weight: bold;">=</span> <span style="background-color: #3cb371;">&quot;terminus&quot;</span>
barXFont <span style="color: #339933; font-weight: bold;">=</span> <span style="background-color: #3cb371;">&quot;inconsolata:size=12&quot;</span>
xftFont <span style="color: #339933; font-weight: bold;">=</span> <span style="background-color: #3cb371;">&quot;xft: inconsolata-14&quot;</span>
<span style="color: #5d478b; font-style: italic;">--}}}</span>
&nbsp;
<span style="color: #5d478b; font-style: italic;">-- Prompt Config {{{</span>
mXPConfig <span style="color: #339933; font-weight: bold;">::</span> XPConfig
mXPConfig <span style="color: #339933; font-weight: bold;">=</span>
    defaultXPConfig <span style="color: green;">&#123;</span> font                  <span style="color: #339933; font-weight: bold;">=</span> barFont
                    <span style="color: #339933; font-weight: bold;">,</span> bgColor               <span style="color: #339933; font-weight: bold;">=</span> colorDarkGray
                    <span style="color: #339933; font-weight: bold;">,</span> fgColor               <span style="color: #339933; font-weight: bold;">=</span> colorGreen
                    <span style="color: #339933; font-weight: bold;">,</span> bgHLight              <span style="color: #339933; font-weight: bold;">=</span> colorGreen
                    <span style="color: #339933; font-weight: bold;">,</span> fgHLight              <span style="color: #339933; font-weight: bold;">=</span> colorDarkGray
                    <span style="color: #339933; font-weight: bold;">,</span> promptBorderWidth     <span style="color: #339933; font-weight: bold;">=</span> <span style="color: red;">0</span>
                    <span style="color: #339933; font-weight: bold;">,</span> height                <span style="color: #339933; font-weight: bold;">=</span> <span style="color: red;">14</span>
                    <span style="color: #339933; font-weight: bold;">,</span> historyFilter         <span style="color: #339933; font-weight: bold;">=</span> deleteConsecutive
                    <span style="color: green;">&#125;</span>
&nbsp;
<span style="color: #5d478b; font-style: italic;">-- Run or Raise Menu</span>
largeXPConfig <span style="color: #339933; font-weight: bold;">::</span> XPConfig
largeXPConfig <span style="color: #339933; font-weight: bold;">=</span> mXPConfig
                <span style="color: green;">&#123;</span> font <span style="color: #339933; font-weight: bold;">=</span> xftFont
                <span style="color: #339933; font-weight: bold;">,</span> height <span style="color: #339933; font-weight: bold;">=</span> <span style="color: red;">22</span>
                <span style="color: green;">&#125;</span>
<span style="color: #5d478b; font-style: italic;">-- }}}</span>
<span style="color: #5d478b; font-style: italic;">-- Key mapping {{{</span>
keys' conf<span style="color: #339933; font-weight: bold;">@</span><span style="color: green;">&#40;</span>XConfig <span style="color: green;">&#123;</span>XMonad<span style="color: #339933; font-weight: bold;">.</span>modMask <span style="color: #339933; font-weight: bold;">=</span> modMask<span style="color: green;">&#125;</span><span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">=</span> M<span style="color: #339933; font-weight: bold;">.</span>fromList <span style="color: #339933; font-weight: bold;">$</span>
    <span style="color: green;">&#91;</span> <span style="color: green;">&#40;</span><span style="color: green;">&#40;</span>modMask<span style="color: #339933; font-weight: bold;">,</span>                    xK<span style="color: #339933; font-weight: bold;">_</span>p        <span style="color: green;">&#41;</span><span style="color: #339933; font-weight: bold;">,</span> runOrRaisePrompt largeXPConfig<span style="color: green;">&#41;</span>
    <span style="color: #339933; font-weight: bold;">,</span> <span style="color: green;">&#40;</span><span style="color: green;">&#40;</span>modMask <span style="color: #339933; font-weight: bold;">.|.</span> shiftMask<span style="color: #339933; font-weight: bold;">,</span>      xK<span style="color: #339933; font-weight: bold;">_</span>Return   <span style="color: green;">&#41;</span><span style="color: #339933; font-weight: bold;">,</span> spawn <span style="color: #339933; font-weight: bold;">$</span> XMonad<span style="color: #339933; font-weight: bold;">.</span>terminal conf<span style="color: green;">&#41;</span>
    <span style="color: #339933; font-weight: bold;">,</span> <span style="color: green;">&#40;</span><span style="color: green;">&#40;</span>modMask<span style="color: #339933; font-weight: bold;">,</span>                    xK<span style="color: #339933; font-weight: bold;">_</span>F2       <span style="color: green;">&#41;</span><span style="color: #339933; font-weight: bold;">,</span> spawn <span style="background-color: #3cb371;">&quot;gmrun&quot;</span><span style="color: green;">&#41;</span>
    <span style="color: #339933; font-weight: bold;">,</span> <span style="color: green;">&#40;</span><span style="color: green;">&#40;</span>modMask <span style="color: #339933; font-weight: bold;">.|.</span> shiftMask<span style="color: #339933; font-weight: bold;">,</span>      xK<span style="color: #339933; font-weight: bold;">_</span>c        <span style="color: green;">&#41;</span><span style="color: #339933; font-weight: bold;">,</span> kill<span style="color: green;">&#41;</span>
    <span style="color: #339933; font-weight: bold;">,</span> <span style="color: green;">&#40;</span><span style="color: green;">&#40;</span>modMask <span style="color: #339933; font-weight: bold;">.|.</span> shiftMask<span style="color: #339933; font-weight: bold;">,</span>      xK<span style="color: #339933; font-weight: bold;">_</span>l        <span style="color: green;">&#41;</span><span style="color: #339933; font-weight: bold;">,</span> spawn <span style="background-color: #3cb371;">&quot;slock&quot;</span><span style="color: green;">&#41;</span>
    <span style="color: #5d478b; font-style: italic;">-- Programs</span>
    <span style="color: #339933; font-weight: bold;">,</span> <span style="color: green;">&#40;</span><span style="color: green;">&#40;</span><span style="color: red;">0</span><span style="color: #339933; font-weight: bold;">,</span>                          xK<span style="color: #339933; font-weight: bold;">_</span>Print    <span style="color: green;">&#41;</span><span style="color: #339933; font-weight: bold;">,</span> spawn <span style="background-color: #3cb371;">&quot;scrot -e 'mv $f ~/screenshots/'&quot;</span><span style="color: green;">&#41;</span>
    <span style="color: #339933; font-weight: bold;">,</span> <span style="color: green;">&#40;</span><span style="color: green;">&#40;</span>modMask<span style="color: #339933; font-weight: bold;">,</span>		            xK<span style="color: #339933; font-weight: bold;">_</span>o        <span style="color: green;">&#41;</span><span style="color: #339933; font-weight: bold;">,</span> spawn <span style="background-color: #3cb371;">&quot;chromium-browser&quot;</span><span style="color: green;">&#41;</span>
    <span style="color: #339933; font-weight: bold;">,</span> <span style="color: green;">&#40;</span><span style="color: green;">&#40;</span>modMask<span style="color: #339933; font-weight: bold;">,</span>                    xK<span style="color: #339933; font-weight: bold;">_</span>m        <span style="color: green;">&#41;</span><span style="color: #339933; font-weight: bold;">,</span> spawn <span style="background-color: #3cb371;">&quot;nautilus --no-desktop --browser&quot;</span><span style="color: green;">&#41;</span>
    <span style="color: #5d478b; font-style: italic;">-- Media Keys</span>
    <span style="color: #339933; font-weight: bold;">,</span> <span style="color: green;">&#40;</span><span style="color: green;">&#40;</span><span style="color: red;">0</span><span style="color: #339933; font-weight: bold;">,</span>                          0x1008ff12  <span style="color: green;">&#41;</span><span style="color: #339933; font-weight: bold;">,</span> spawn <span style="background-color: #3cb371;">&quot;amixer -q sset Headphone toggle&quot;</span><span style="color: green;">&#41;</span>        <span style="color: #5d478b; font-style: italic;">-- XF86AudioMute</span>
    <span style="color: #339933; font-weight: bold;">,</span> <span style="color: green;">&#40;</span><span style="color: green;">&#40;</span><span style="color: red;">0</span><span style="color: #339933; font-weight: bold;">,</span>                          0x1008ff11  <span style="color: green;">&#41;</span><span style="color: #339933; font-weight: bold;">,</span> spawn <span style="background-color: #3cb371;">&quot;amixer -q sset Headphone 5%-&quot;</span><span style="color: green;">&#41;</span>   <span style="color: #5d478b; font-style: italic;">-- XF86AudioLowerVolume</span>
    <span style="color: #339933; font-weight: bold;">,</span> <span style="color: green;">&#40;</span><span style="color: green;">&#40;</span><span style="color: red;">0</span><span style="color: #339933; font-weight: bold;">,</span>                          0x1008ff13  <span style="color: green;">&#41;</span><span style="color: #339933; font-weight: bold;">,</span> spawn <span style="background-color: #3cb371;">&quot;amixer -q sset Headphone 5%+&quot;</span><span style="color: green;">&#41;</span>   <span style="color: #5d478b; font-style: italic;">-- XF86AudioRaiseVolume</span>
    <span style="color: #339933; font-weight: bold;">,</span> <span style="color: green;">&#40;</span><span style="color: green;">&#40;</span><span style="color: red;">0</span><span style="color: #339933; font-weight: bold;">,</span>                          0x1008ff14  <span style="color: green;">&#41;</span><span style="color: #339933; font-weight: bold;">,</span> spawn <span style="background-color: #3cb371;">&quot;rhythmbox-client --play-pause&quot;</span><span style="color: green;">&#41;</span>
    <span style="color: #339933; font-weight: bold;">,</span> <span style="color: green;">&#40;</span><span style="color: green;">&#40;</span><span style="color: red;">0</span><span style="color: #339933; font-weight: bold;">,</span>                          0x1008ff17  <span style="color: green;">&#41;</span><span style="color: #339933; font-weight: bold;">,</span> spawn <span style="background-color: #3cb371;">&quot;rhythmbox-client --next&quot;</span><span style="color: green;">&#41;</span>
    <span style="color: #339933; font-weight: bold;">,</span> <span style="color: green;">&#40;</span><span style="color: green;">&#40;</span><span style="color: red;">0</span><span style="color: #339933; font-weight: bold;">,</span>                          0x1008ff16  <span style="color: green;">&#41;</span><span style="color: #339933; font-weight: bold;">,</span> spawn <span style="background-color: #3cb371;">&quot;rhythmbox-client --previous&quot;</span><span style="color: green;">&#41;</span>
&nbsp;
    <span style="color: #5d478b; font-style: italic;">-- layouts</span>
    <span style="color: #339933; font-weight: bold;">,</span> <span style="color: green;">&#40;</span><span style="color: green;">&#40;</span>modMask<span style="color: #339933; font-weight: bold;">,</span>                    xK<span style="color: #339933; font-weight: bold;">_</span>space    <span style="color: green;">&#41;</span><span style="color: #339933; font-weight: bold;">,</span> sendMessage NextLayout<span style="color: green;">&#41;</span>
    <span style="color: #339933; font-weight: bold;">,</span> <span style="color: green;">&#40;</span><span style="color: green;">&#40;</span>modMask <span style="color: #339933; font-weight: bold;">.|.</span> shiftMask<span style="color: #339933; font-weight: bold;">,</span>      xK<span style="color: #339933; font-weight: bold;">_</span>space    <span style="color: green;">&#41;</span><span style="color: #339933; font-weight: bold;">,</span> setLayout <span style="color: #339933; font-weight: bold;">$</span> XMonad<span style="color: #339933; font-weight: bold;">.</span>layoutHook conf<span style="color: green;">&#41;</span>          <span style="color: #5d478b; font-style: italic;">-- reset layout on current desktop to default</span>
    <span style="color: #339933; font-weight: bold;">,</span> <span style="color: green;">&#40;</span><span style="color: green;">&#40;</span>modMask<span style="color: #339933; font-weight: bold;">,</span>                    xK<span style="color: #339933; font-weight: bold;">_</span>b        <span style="color: green;">&#41;</span><span style="color: #339933; font-weight: bold;">,</span> sendMessage ToggleStruts<span style="color: green;">&#41;</span>
    <span style="color: #339933; font-weight: bold;">,</span> <span style="color: green;">&#40;</span><span style="color: green;">&#40;</span>modMask<span style="color: #339933; font-weight: bold;">,</span>                    xK<span style="color: #339933; font-weight: bold;">_</span>n        <span style="color: green;">&#41;</span><span style="color: #339933; font-weight: bold;">,</span> refresh<span style="color: green;">&#41;</span>
    <span style="color: #339933; font-weight: bold;">,</span> <span style="color: green;">&#40;</span><span style="color: green;">&#40;</span>modMask<span style="color: #339933; font-weight: bold;">,</span>                    xK<span style="color: #339933; font-weight: bold;">_</span>Tab      <span style="color: green;">&#41;</span><span style="color: #339933; font-weight: bold;">,</span> windows W<span style="color: #339933; font-weight: bold;">.</span>focusDown<span style="color: green;">&#41;</span>                         <span style="color: #5d478b; font-style: italic;">-- move focus to next window</span>
    <span style="color: #339933; font-weight: bold;">,</span> <span style="color: green;">&#40;</span><span style="color: green;">&#40;</span>modMask<span style="color: #339933; font-weight: bold;">,</span>                    xK<span style="color: #339933; font-weight: bold;">_</span>j        <span style="color: green;">&#41;</span><span style="color: #339933; font-weight: bold;">,</span> windows W<span style="color: #339933; font-weight: bold;">.</span>focusDown<span style="color: green;">&#41;</span>
    <span style="color: #339933; font-weight: bold;">,</span> <span style="color: green;">&#40;</span><span style="color: green;">&#40;</span>modMask<span style="color: #339933; font-weight: bold;">,</span>                    xK<span style="color: #339933; font-weight: bold;">_</span>k        <span style="color: green;">&#41;</span><span style="color: #339933; font-weight: bold;">,</span> windows W<span style="color: #339933; font-weight: bold;">.</span>focusUp  <span style="color: green;">&#41;</span>
    <span style="color: #339933; font-weight: bold;">,</span> <span style="color: green;">&#40;</span><span style="color: green;">&#40;</span>modMask <span style="color: #339933; font-weight: bold;">.|.</span> shiftMask<span style="color: #339933; font-weight: bold;">,</span>      xK<span style="color: #339933; font-weight: bold;">_</span>j        <span style="color: green;">&#41;</span><span style="color: #339933; font-weight: bold;">,</span> windows W<span style="color: #339933; font-weight: bold;">.</span>swapDown<span style="color: green;">&#41;</span>                          <span style="color: #5d478b; font-style: italic;">-- swap the focused window with the next window</span>
    <span style="color: #339933; font-weight: bold;">,</span> <span style="color: green;">&#40;</span><span style="color: green;">&#40;</span>modMask <span style="color: #339933; font-weight: bold;">.|.</span> shiftMask<span style="color: #339933; font-weight: bold;">,</span>      xK<span style="color: #339933; font-weight: bold;">_</span>k        <span style="color: green;">&#41;</span><span style="color: #339933; font-weight: bold;">,</span> windows W<span style="color: #339933; font-weight: bold;">.</span>swapUp<span style="color: green;">&#41;</span>                            <span style="color: #5d478b; font-style: italic;">-- swap the focused window with the previous window</span>
    <span style="color: #339933; font-weight: bold;">,</span> <span style="color: green;">&#40;</span><span style="color: green;">&#40;</span>modMask<span style="color: #339933; font-weight: bold;">,</span>                    xK<span style="color: #339933; font-weight: bold;">_</span>Return   <span style="color: green;">&#41;</span><span style="color: #339933; font-weight: bold;">,</span> windows W<span style="color: #339933; font-weight: bold;">.</span>swapMaster<span style="color: green;">&#41;</span>
    <span style="color: #339933; font-weight: bold;">,</span> <span style="color: green;">&#40;</span><span style="color: green;">&#40;</span>modMask<span style="color: #339933; font-weight: bold;">,</span>                    xK<span style="color: #339933; font-weight: bold;">_</span>t        <span style="color: green;">&#41;</span><span style="color: #339933; font-weight: bold;">,</span> withFocused <span style="color: #339933; font-weight: bold;">$</span> windows <span style="color: #339933; font-weight: bold;">.</span> W<span style="color: #339933; font-weight: bold;">.</span>sink<span style="color: green;">&#41;</span>              <span style="color: #5d478b; font-style: italic;">-- Push window back into tiling</span>
    <span style="color: #339933; font-weight: bold;">,</span> <span style="color: green;">&#40;</span><span style="color: green;">&#40;</span>modMask<span style="color: #339933; font-weight: bold;">,</span>                    xK<span style="color: #339933; font-weight: bold;">_</span>h        <span style="color: green;">&#41;</span><span style="color: #339933; font-weight: bold;">,</span> sendMessage Shrink<span style="color: green;">&#41;</span>                          <span style="color: #5d478b; font-style: italic;">-- %! Shrink a master area</span>
    <span style="color: #339933; font-weight: bold;">,</span> <span style="color: green;">&#40;</span><span style="color: green;">&#40;</span>modMask<span style="color: #339933; font-weight: bold;">,</span>                    xK<span style="color: #339933; font-weight: bold;">_</span>l        <span style="color: green;">&#41;</span><span style="color: #339933; font-weight: bold;">,</span> sendMessage Expand<span style="color: green;">&#41;</span>                          <span style="color: #5d478b; font-style: italic;">-- %! Expand a master area</span>
    <span style="color: #339933; font-weight: bold;">,</span> <span style="color: green;">&#40;</span><span style="color: green;">&#40;</span>modMask<span style="color: #339933; font-weight: bold;">,</span>                    xK<span style="color: #339933; font-weight: bold;">_</span>comma    <span style="color: green;">&#41;</span><span style="color: #339933; font-weight: bold;">,</span> sendMessage <span style="color: green;">&#40;</span>IncMasterN <span style="color: red;">1</span><span style="color: green;">&#41;</span><span style="color: green;">&#41;</span>
    <span style="color: #339933; font-weight: bold;">,</span> <span style="color: green;">&#40;</span><span style="color: green;">&#40;</span>modMask<span style="color: #339933; font-weight: bold;">,</span>                    xK<span style="color: #339933; font-weight: bold;">_</span>period   <span style="color: green;">&#41;</span><span style="color: #339933; font-weight: bold;">,</span> sendMessage <span style="color: green;">&#40;</span>IncMasterN <span style="color: green;">&#40;</span><span style="color: #339933; font-weight: bold;">-</span><span style="color: red;">1</span><span style="color: green;">&#41;</span><span style="color: green;">&#41;</span><span style="color: green;">&#41;</span>
&nbsp;
&nbsp;
    <span style="color: #5d478b; font-style: italic;">-- workspaces</span>
    <span style="color: #339933; font-weight: bold;">,</span> <span style="color: green;">&#40;</span><span style="color: green;">&#40;</span>modMask <span style="color: #339933; font-weight: bold;">.|.</span> controlMask<span style="color: #339933; font-weight: bold;">,</span>   xK<span style="color: #339933; font-weight: bold;">_</span>Right     <span style="color: green;">&#41;</span><span style="color: #339933; font-weight: bold;">,</span> nextWS<span style="color: green;">&#41;</span>
    <span style="color: #339933; font-weight: bold;">,</span> <span style="color: green;">&#40;</span><span style="color: green;">&#40;</span>modMask <span style="color: #339933; font-weight: bold;">.|.</span> shiftMask<span style="color: #339933; font-weight: bold;">,</span>     xK<span style="color: #339933; font-weight: bold;">_</span>Right     <span style="color: green;">&#41;</span><span style="color: #339933; font-weight: bold;">,</span> shiftToNext<span style="color: green;">&#41;</span>
    <span style="color: #339933; font-weight: bold;">,</span> <span style="color: green;">&#40;</span><span style="color: green;">&#40;</span>modMask <span style="color: #339933; font-weight: bold;">.|.</span> controlMask<span style="color: #339933; font-weight: bold;">,</span>   xK<span style="color: #339933; font-weight: bold;">_</span>Left      <span style="color: green;">&#41;</span><span style="color: #339933; font-weight: bold;">,</span> prevWS<span style="color: green;">&#41;</span>
    <span style="color: #339933; font-weight: bold;">,</span> <span style="color: green;">&#40;</span><span style="color: green;">&#40;</span>modMask <span style="color: #339933; font-weight: bold;">.|.</span> shiftMask<span style="color: #339933; font-weight: bold;">,</span>     xK<span style="color: #339933; font-weight: bold;">_</span>Left      <span style="color: green;">&#41;</span><span style="color: #339933; font-weight: bold;">,</span> shiftToPrev<span style="color: green;">&#41;</span>
&nbsp;
    <span style="color: #5d478b; font-style: italic;">-- quit, or restart</span>
    <span style="color: #339933; font-weight: bold;">,</span> <span style="color: green;">&#40;</span><span style="color: green;">&#40;</span>modMask <span style="color: #339933; font-weight: bold;">.|.</span> shiftMask<span style="color: #339933; font-weight: bold;">,</span>      xK<span style="color: #339933; font-weight: bold;">_</span>q        <span style="color: green;">&#41;</span><span style="color: #339933; font-weight: bold;">,</span> io <span style="color: green;">&#40;</span>exitWith ExitSuccess<span style="color: green;">&#41;</span><span style="color: green;">&#41;</span>
    <span style="color: #339933; font-weight: bold;">,</span> <span style="color: green;">&#40;</span><span style="color: green;">&#40;</span>modMask<span style="color: #339933; font-weight: bold;">,</span>                    xK<span style="color: #339933; font-weight: bold;">_</span>q        <span style="color: green;">&#41;</span><span style="color: #339933; font-weight: bold;">,</span> spawn <span style="background-color: #3cb371;">&quot;killall conky dzen2 &amp;&amp; /home/my_user/.cabal/bin/xmonad --recompile &amp;&amp; /home/my_user/.cabal/bin/xmonad --restart&quot;</span><span style="color: green;">&#41;</span>
    <span style="color: green;">&#93;</span>
    <span style="color: #339933; font-weight: bold;">++</span>
    <span style="color: #5d478b; font-style: italic;">-- mod-[1..9] %! Switch to workspace N</span>
    <span style="color: #5d478b; font-style: italic;">-- mod-shift-[1..9] %! Move client to workspace N</span>
    <span style="color: green;">&#91;</span><span style="color: green;">&#40;</span><span style="color: green;">&#40;</span>m <span style="color: #339933; font-weight: bold;">.|.</span> modMask<span style="color: #339933; font-weight: bold;">,</span> k<span style="color: green;">&#41;</span><span style="color: #339933; font-weight: bold;">,</span> windows <span style="color: #339933; font-weight: bold;">$</span> f i<span style="color: green;">&#41;</span>
        <span style="color: #339933; font-weight: bold;">|</span> <span style="color: green;">&#40;</span>i<span style="color: #339933; font-weight: bold;">,</span> k<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">&lt;-</span> <span style="font-weight: bold;">zip</span> <span style="color: green;">&#40;</span>XMonad<span style="color: #339933; font-weight: bold;">.</span>workspaces conf<span style="color: green;">&#41;</span> <span style="color: green;">&#91;</span>xK<span style="color: #339933; font-weight: bold;">_</span>1 <span style="color: #339933; font-weight: bold;">..</span> xK<span style="color: #339933; font-weight: bold;">_</span>9<span style="color: green;">&#93;</span>
        <span style="color: #339933; font-weight: bold;">,</span> <span style="color: green;">&#40;</span>f<span style="color: #339933; font-weight: bold;">,</span> m<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">&lt;-</span> <span style="color: green;">&#91;</span><span style="color: green;">&#40;</span>W<span style="color: #339933; font-weight: bold;">.</span>greedyView<span style="color: #339933; font-weight: bold;">,</span> <span style="color: red;">0</span><span style="color: green;">&#41;</span><span style="color: #339933; font-weight: bold;">,</span> <span style="color: green;">&#40;</span>W<span style="color: #339933; font-weight: bold;">.</span>shift<span style="color: #339933; font-weight: bold;">,</span> shiftMask<span style="color: green;">&#41;</span><span style="color: green;">&#93;</span><span style="color: green;">&#93;</span>
    <span style="color: #339933; font-weight: bold;">++</span>
&nbsp;
    <span style="color: #5d478b; font-style: italic;">--</span>
    <span style="color: #5d478b; font-style: italic;">-- mod-{w,e,r}, Switch to physical/Xinerama screens 1, 2, or 3</span>
    <span style="color: #5d478b; font-style: italic;">-- mod-shift-{w,e,r}, Move client to screen 1, 2, or 3</span>
    <span style="color: #5d478b; font-style: italic;">--</span>
    <span style="color: green;">&#91;</span><span style="color: green;">&#40;</span><span style="color: green;">&#40;</span>m <span style="color: #339933; font-weight: bold;">.|.</span> modMask<span style="color: #339933; font-weight: bold;">,</span> key<span style="color: green;">&#41;</span><span style="color: #339933; font-weight: bold;">,</span> screenWorkspace sc <span style="color: #339933; font-weight: bold;">&gt;&gt;=</span> <span style="font-weight: bold;">flip</span> whenJust <span style="color: green;">&#40;</span>windows <span style="color: #339933; font-weight: bold;">.</span> f<span style="color: green;">&#41;</span><span style="color: green;">&#41;</span>
        <span style="color: #339933; font-weight: bold;">|</span> <span style="color: green;">&#40;</span>key<span style="color: #339933; font-weight: bold;">,</span> sc<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">&lt;-</span> <span style="font-weight: bold;">zip</span> <span style="color: green;">&#91;</span>xK<span style="color: #339933; font-weight: bold;">_</span>w<span style="color: #339933; font-weight: bold;">,</span> xK<span style="color: #339933; font-weight: bold;">_</span>e<span style="color: #339933; font-weight: bold;">,</span> xK<span style="color: #339933; font-weight: bold;">_</span>r<span style="color: green;">&#93;</span> <span style="color: green;">&#91;</span><span style="color: red;">0</span><span style="color: #339933; font-weight: bold;">..</span><span style="color: green;">&#93;</span>
        <span style="color: #339933; font-weight: bold;">,</span> <span style="color: green;">&#40;</span>f<span style="color: #339933; font-weight: bold;">,</span> m<span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">&lt;-</span> <span style="color: green;">&#91;</span><span style="color: green;">&#40;</span>W<span style="color: #339933; font-weight: bold;">.</span>view<span style="color: #339933; font-weight: bold;">,</span> <span style="color: red;">0</span><span style="color: green;">&#41;</span><span style="color: #339933; font-weight: bold;">,</span> <span style="color: green;">&#40;</span>W<span style="color: #339933; font-weight: bold;">.</span>shift<span style="color: #339933; font-weight: bold;">,</span> shiftMask<span style="color: green;">&#41;</span><span style="color: green;">&#93;</span><span style="color: green;">&#93;</span>
&nbsp;
<span style="color: #5d478b; font-style: italic;">--}}}</span>
<span style="color: #5d478b; font-style: italic;">-- vim:foldmethod=marker sw=4 sts=4 ts=4 tw=0 et ai nowrap</span></pre></div></div>

</p>
<p>
Copy this into your .xmonad folder, assuming you have everything needed, and you should see a desktop similar to the one shown on the image.
</p>
<p>
Feel free to check my <a href="http://github.com/brafales/xmonad-config" onclick="pageTracker._trackPageview('/outgoing/github.com/brafales/xmonad-config?referer=');">GitHub xmonad repository</a> to find updated configuration files.
</p>
<p>
Cheers!</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fthinkingeek.com%2F2011%2F11%2F21%2Fsimple-guide-configure-xmonad-dzen2-conky%2F&amp;title=Simple%20guide%20to%20configure%20xmonad%2C%20dzen2%20and%20conky" id="wpa2a_10" onclick="pageTracker._trackPageview('/outgoing/www.addtoany.com/share_save_url=http_3A_2F_2Fthinkingeek.com_2F2011_2F11_2F21_2Fsimple-guide-configure-xmonad-dzen2-conky_2F_amp_title=Simple_20guide_20to_20configure_20xmonad_2C_20dzen2_20and_20conky?referer=');"><img src="http://thinkingeek.com/wp-content/plugins/add-to-any/share_save_120_16.gif" width="120" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://thinkingeek.com/2011/11/21/simple-guide-configure-xmonad-dzen2-conky/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Iterate over a collection in groups, and other things</title>
		<link>http://thinkingeek.com/2011/10/20/iterate-collection-groups/</link>
		<comments>http://thinkingeek.com/2011/10/20/iterate-collection-groups/#comments</comments>
		<pubDate>Thu, 20 Oct 2011 15:44:51 +0000</pubDate>
		<dc:creator>brafales</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[enumerable]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[ruby on rails]]></category>

		<guid isPermaLink="false">http://thinkingeek.com/?p=188</guid>
		<description><![CDATA[One thing I find fascinating about Ruby is the fact that most common tasks are already programmed for you in its library. The Enumerable module is a clear example of that, providing you with lots of functionality to manipulate collections of objects. One of those useful methods I discovered the other day was each_slice. This [...]]]></description>
			<content:encoded><![CDATA[<p>
One thing I find fascinating about Ruby is the fact that most common tasks are already programmed for you in its library. The <em>Enumerable</em> module is a clear example of that, providing you with lots of functionality to manipulate collections of objects.
</p>
<p>
One of those useful methods I discovered the other day was <em><a href="http://www.ruby-doc.org/core-1.9.2/Enumerable.html#method-i-each_slice" onclick="pageTracker._trackPageview('/outgoing/www.ruby-doc.org/core-1.9.2/Enumerable.html_method-i-each_slice?referer=');">each_slice</a></em>. This method allows you to iterate over the collection, just as <em>each</em> does, but lets you do it changing how many elements of the collection you get on each iteration. This is the example you can get from the documentation page:
</p>
<p>
<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006666;">1</span>..<span style="color:#006666;">10</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">each_slice</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006666;">3</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">|</span>a<span style="color:#006600; font-weight:bold;">|</span> <span style="color:#CC0066; font-weight:bold;">p</span> a<span style="color:#006600; font-weight:bold;">&#125;</span>
<span style="color:#008000; font-style:italic;"># outputs below</span>
<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">1</span>, <span style="color:#006666;">2</span>, <span style="color:#006666;">3</span><span style="color:#006600; font-weight:bold;">&#93;</span>
<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">4</span>, <span style="color:#006666;">5</span>, <span style="color:#006666;">6</span><span style="color:#006600; font-weight:bold;">&#93;</span>
<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">7</span>, <span style="color:#006666;">8</span>, <span style="color:#006666;">9</span><span style="color:#006600; font-weight:bold;">&#93;</span>
<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#006666;">10</span><span style="color:#006600; font-weight:bold;">&#93;</span></pre></div></div>

</p>
<p>
You can see that from the original array from 1 to 10, on every iteration Ruby prints the numbers in groups of three, and the last one alone since the collection is not a multiple of 3. Now think about having to do this manually: it&#8217;s not that hard, but its error prone and you have to do all that typical arithmetic logic that should be easy but never is. How handy that Ruby has already done that job for you.
</p>
<p>
This method is also pretty useful when working in <em>Ruby on Rails</em>. One simple example is when you have to manually implement some kind of pagination, or show a list of elements in columns or rows of fixed size: you have to simply iterate with <em>each_slice</em> and put the page/row/column logic on the block, and <em>voilà</em>.
</p>
<p>
I strongly suggest you take a look at the <a href="http://www.ruby-doc.org/core-1.9.2/Enumerable.html" onclick="pageTracker._trackPageview('/outgoing/www.ruby-doc.org/core-1.9.2/Enumerable.html?referer=');">Enumerable</a> module reference to take a look at all the other flavours of <em>each</em> methods it has and I&#8217;m sure you&#8217;ll find all of them pretty useful in lots of situations!</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fthinkingeek.com%2F2011%2F10%2F20%2Fiterate-collection-groups%2F&amp;title=Iterate%20over%20a%20collection%20in%20groups%2C%20and%20other%20things" id="wpa2a_12" onclick="pageTracker._trackPageview('/outgoing/www.addtoany.com/share_save_url=http_3A_2F_2Fthinkingeek.com_2F2011_2F10_2F20_2Fiterate-collection-groups_2F_amp_title=Iterate_20over_20a_20collection_20in_20groups_2C_20and_20other_20things?referer=');"><img src="http://thinkingeek.com/wp-content/plugins/add-to-any/share_save_120_16.gif" width="120" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://thinkingeek.com/2011/10/20/iterate-collection-groups/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Easily select random records in rails</title>
		<link>http://thinkingeek.com/2011/07/04/easily-select-random-records-rails/</link>
		<comments>http://thinkingeek.com/2011/07/04/easily-select-random-records-rails/#comments</comments>
		<pubDate>Mon, 04 Jul 2011 18:26:50 +0000</pubDate>
		<dc:creator>brafales</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[activerecord]]></category>
		<category><![CDATA[array]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[ruby on rails]]></category>

		<guid isPermaLink="false">http://thinkingeek.com/?p=184</guid>
		<description><![CDATA[If you ever wondered how to easily retrieve a random record in an ActiveRecord model, here&#8217;s en easy way to do that: use the sample method. sample is a class method from the Array class that retrieves one or more random items from an array instance. It conveniently returns nil or an array lesser than [...]]]></description>
			<content:encoded><![CDATA[<p>If you ever wondered how to easily retrieve a random record in an <em>ActiveRecord</em> model, here&#8217;s en easy way to do that: use the <a href="http://www.ruby-doc.org/core/classes/Array.html#M000285" onclick="pageTracker._trackPageview('/outgoing/www.ruby-doc.org/core/classes/Array.html_M000285?referer=');">sample</a> method.</p>
<p><em>sample</em> is a class method from the <em>Array</em> class that retrieves one or more random items from an array instance. It conveniently returns <em>nil</em> or an array lesser than the items requested if the original array has not enough items.</p>
<p>Since all <em>ActiveRecord</em> <em>find</em>s return an array, you can easily add the sample call at the end of a <em>find</em> call to get the random items you need from complex queries.</p>
<p>For example, imagine you have a Book model which has a published_at datetime attribute and you want to show, in your library home page, a random selection of 5 books that have been published. You can easily get those using this snippet:</p>
<p>
<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">def</span> get_random_books_for_home_page
  find<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:all</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">sample</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006666;">5</span><span style="color:#006600; font-weight:bold;">&#41;</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>
</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fthinkingeek.com%2F2011%2F07%2F04%2Feasily-select-random-records-rails%2F&amp;title=Easily%20select%20random%20records%20in%20rails" id="wpa2a_14" onclick="pageTracker._trackPageview('/outgoing/www.addtoany.com/share_save_url=http_3A_2F_2Fthinkingeek.com_2F2011_2F07_2F04_2Feasily-select-random-records-rails_2F_amp_title=Easily_20select_20random_20records_20in_20rails?referer=');"><img src="http://thinkingeek.com/wp-content/plugins/add-to-any/share_save_120_16.gif" width="120" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://thinkingeek.com/2011/07/04/easily-select-random-records-rails/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>WordPress AddToAny plugin</title>
		<link>http://thinkingeek.com/2011/06/16/wordpress-addtoany-plugin/</link>
		<comments>http://thinkingeek.com/2011/06/16/wordpress-addtoany-plugin/#comments</comments>
		<pubDate>Thu, 16 Jun 2011 18:02:41 +0000</pubDate>
		<dc:creator>brafales</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[addtoany]]></category>
		<category><![CDATA[footer]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://thinkingeek.com/?p=182</guid>
		<description><![CDATA[If you encounter problems after upgrading WordPress and the AddToAny plugin version .9.9.9.1 (the one I tested), try to update your footer.php file of your current theme too add this line just before the closing body tag: &#60;?php wp_footer&#40;&#41;; ?&#62; It seems that newer versions of the plugin put some javascript code into the footer [...]]]></description>
			<content:encoded><![CDATA[<p>
If you encounter problems after upgrading <a href="http://www.wordpress.org" onclick="pageTracker._trackPageview('/outgoing/www.wordpress.org?referer=');">WordPress</a> and the <a href="http://wordpress.org/extend/plugins/add-to-any/" onclick="pageTracker._trackPageview('/outgoing/wordpress.org/extend/plugins/add-to-any/?referer=');">AddToAny</a> plugin version .9.9.9.1 (the one I tested), try to update your <em>footer.php</em> file of your current theme too add this line just before the closing <em>body</em> tag:
</p>
<p>
<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> wp_footer<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

</p>
<p>
It seems that newer versions of the plugin put some javascript code into the footer section, so without this call, there&#8217;s no javascript for <em>AddToAny</em>, and without javascript, you can&#8217;t see the popup div that allows you to select the service you want to use to share your posts.</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fthinkingeek.com%2F2011%2F06%2F16%2Fwordpress-addtoany-plugin%2F&amp;title=WordPress%20AddToAny%20plugin" id="wpa2a_16" onclick="pageTracker._trackPageview('/outgoing/www.addtoany.com/share_save_url=http_3A_2F_2Fthinkingeek.com_2F2011_2F06_2F16_2Fwordpress-addtoany-plugin_2F_amp_title=WordPress_20AddToAny_20plugin?referer=');"><img src="http://thinkingeek.com/wp-content/plugins/add-to-any/share_save_120_16.gif" width="120" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://thinkingeek.com/2011/06/16/wordpress-addtoany-plugin/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Fixtures and serialized attributes in Ruby on Rails</title>
		<link>http://thinkingeek.com/2011/06/16/fixtures-and-serialized-attributes-in-ruby-on-rails/</link>
		<comments>http://thinkingeek.com/2011/06/16/fixtures-and-serialized-attributes-in-ruby-on-rails/#comments</comments>
		<pubDate>Thu, 16 Jun 2011 17:46:59 +0000</pubDate>
		<dc:creator>brafales</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[fixtures]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[ruby on rails]]></category>
		<category><![CDATA[serialize]]></category>
		<category><![CDATA[yaml]]></category>

		<guid isPermaLink="false">http://thinkingeek.com/?p=175</guid>
		<description><![CDATA[If you&#8217;ve ever used the serialize method in an ActiveRecord model, you may have faced the problem of writing a fixture for that particular serialized field. The serialize method is quite handy if you need to store a complex object (like a Hash or an Array) in a database field, without having to create additional [...]]]></description>
			<content:encoded><![CDATA[<p>
If you&#8217;ve ever used the <a href="http://apidock.com/rails/ActiveRecord/Base/serialize/class" onclick="pageTracker._trackPageview('/outgoing/apidock.com/rails/ActiveRecord/Base/serialize/class?referer=');">serialize</a> method in an ActiveRecord model, you may have faced the problem of writing a fixture for that particular serialized field. The serialize method is quite handy if you need to store a complex object (like a Hash or an Array) in a database field, without having to create additional models and relationships between them. A good example could be store the preferences of a user in a hash:
</p>
<p>
<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">class</span> User <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#6666ff; font-weight:bold;">ActiveRecord::Base</span>
    serialize <span style="color:#ff3333; font-weight:bold;">:preferences</span>, <span style="color:#CC00FF; font-weight:bold;">Hash</span>
  <span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

</p>
<p>
This way you can set and get the <em>preferences</em> attribute of the user without having to worry much about it:
</p>
<p>
<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">User.<span style="color:#9900CC;">first</span>.<span style="color:#9900CC;">preferences</span> <span style="color:#008000; font-style:italic;"># =&gt; {:show_email =&gt; true, :allow_pm =&gt; :false, ...}</span>
user = User.<span style="color:#9900CC;">first</span>
user.<span style="color:#9900CC;">preferences</span> = <span style="color:#006600; font-weight:bold;">&#123;</span>:show_email <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">true</span>, <span style="color:#ff3333; font-weight:bold;">:allow_pm</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> :<span style="color:#0000FF; font-weight:bold;">false</span><span style="color:#006600; font-weight:bold;">&#125;</span>
user.<span style="color:#9900CC;">save</span></pre></div></div>

</p>
<p>
In order to do that, at the database table for the <em>User</em> class, among the other fields you&#8217;ll need to add a <em>text</em> column for the preferences. After that, you can easily work with your model without too much of a hassle.
</p>
<p>
If you care to look at the rows of the model&#8217;s table, you&#8217;ll see that the serialized attribute is stored in <a href="http://www.yaml.org/" onclick="pageTracker._trackPageview('/outgoing/www.yaml.org/?referer=');">YAML</a> format:
</p>
<p>
<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">sqlite&gt; select preferences from users where id = 1;
--- 
:show_email: false
:allow_pm: false</pre></div></div>

</p>
<p>
Now, that if you need to add a <a href="http://rails.rubyonrails.org/classes/Fixtures.html" onclick="pageTracker._trackPageview('/outgoing/rails.rubyonrails.org/classes/Fixtures.html?referer=');">fixture</a> for your model that needs the <em>preferences</em> attribute to be set to a particular value? If you have to manually parse the value you want to put in there to be tested, it&#8217;ll be a pain in the ass. Even if you have a script that converts certain values to YAML so you can copy and paste the script output to the fixture, it&#8217;s not very comfortable. Hopefully, you have to remember that you can use some <a href="http://ruby-doc.org/stdlib/libdoc/erb/rdoc/classes/ERB.html" onclick="pageTracker._trackPageview('/outgoing/ruby-doc.org/stdlib/libdoc/erb/rdoc/classes/ERB.html?referer=');">ERB</a> magic in your fixtures <img src='http://thinkingeek.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  So, here&#8217;s the deal if you need to add something to the serializable attribute:
</p>
<p>
<div class="wp_syntax"><div class="code"><pre class="yaml" style="font-family:monospace;">one:
  preferences: &lt;%= {:show_email =&gt; true, :allow_pm =&gt; :false}.to_yaml.inspect  %&gt;</pre></div></div>

</p>
<p>
The <em>to_yaml</em> method converts the Hash into a YAML representation, and with <em>inspect</em> we convert that to a string. Using this technique, we can add whatever we want to a serialized field in our fixtures.</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fthinkingeek.com%2F2011%2F06%2F16%2Ffixtures-and-serialized-attributes-in-ruby-on-rails%2F&amp;title=Fixtures%20and%20serialized%20attributes%20in%20Ruby%20on%20Rails" id="wpa2a_18" onclick="pageTracker._trackPageview('/outgoing/www.addtoany.com/share_save_url=http_3A_2F_2Fthinkingeek.com_2F2011_2F06_2F16_2Ffixtures-and-serialized-attributes-in-ruby-on-rails_2F_amp_title=Fixtures_20and_20serialized_20attributes_20in_20Ruby_20on_20Rails?referer=');"><img src="http://thinkingeek.com/wp-content/plugins/add-to-any/share_save_120_16.gif" width="120" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://thinkingeek.com/2011/06/16/fixtures-and-serialized-attributes-in-ruby-on-rails/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Installing xmonad in ArchLinux</title>
		<link>http://thinkingeek.com/2011/05/19/installing-xmonad-in-archlinux/</link>
		<comments>http://thinkingeek.com/2011/05/19/installing-xmonad-in-archlinux/#comments</comments>
		<pubDate>Thu, 19 May 2011 18:36:46 +0000</pubDate>
		<dc:creator>brafales</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[archlinux]]></category>
		<category><![CDATA[xmonad]]></category>

		<guid isPermaLink="false">http://thinkingeek.com/?p=170</guid>
		<description><![CDATA[For some reason, the ArchLinux wiki is kind of outdated explaining how to install xmonad in Arch. Also, the new packages seem to have a bug and the xmonad installation won&#8217;t work out of the box. Here you have detailed steps on how to install and run xmonad on ArchLinux. First of all, you need [...]]]></description>
			<content:encoded><![CDATA[<p>
For some reason, the ArchLinux wiki is kind of outdated explaining how to install xmonad in Arch. Also, the new packages seem to have a bug and the xmonad installation won&#8217;t work out of the box. Here you have detailed steps on how to install and run xmonad on ArchLinux.<br />
First of all, you need to install the Xorg server. Refer to <a href="https://wiki.archlinux.org/index.php/Xorg" onclick="pageTracker._trackPageview('/outgoing/wiki.archlinux.org/index.php/Xorg?referer=');">Xorg</a> for detailed instructions. After that, you&#8217;ll need to install the xmonad packages, named xmonad and xmonad-contrib.
</p>
<p>
<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">pacman <span style="color: #660033;">-Syu</span> xmonad xmonad-contrib</pre></div></div>

</p>
<p>
This will install xmonad and all the required dependencies. After that, if you want a fairly simple X setup, add the line <em>xmonad</em> to your <em>~/.xinitrc</em> file (hopefully you&#8217;ll be using a display manager that uses that file like <a href="https://wiki.archlinux.org/index.php/Slim" onclick="pageTracker._trackPageview('/outgoing/wiki.archlinux.org/index.php/Slim?referer=');">SLiM</a>). If you try this on a freshly installed ArchLinux system, though, it won&#8217;t work. There are some missing steps to do. First of all, you need to create the folder <em>~/.xmonad</em>.
</p>
<p>
<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">mkdir</span> ~<span style="color: #000000; font-weight: bold;">/</span>.xmonad</pre></div></div>

</p>
<p>
After that, you need to create a new xmonad config file, called <em>xmonad.hs</em into that folder, so fire up your favourite editor and fill the file with this basic (empty) configuration:
</p>
<p>
<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;"><span style="color: #06c; font-weight: bold;">import</span> XMonad
&nbsp;
main <span style="color: #339933; font-weight: bold;">=</span> <span style="color: #06c; font-weight: bold;">do</span>
    xmonad <span style="color: #339933; font-weight: bold;">$</span> defaultConfig</pre></div></div>

</p>
<p>
Once you have you configuration file in place, it&#8217;s time to rebuild xmonad:
</p>
<p>
<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">xmonad <span style="color: #660033;">--recompile</span></pre></div></div>

</p>
<p>
And that&#8217;s all, you should be able to start your fresh new xmonad setup in ArchLinux. By the way, if you wonder why pressing <em>Mod1 + Shift + Enter</em> does nothing, make sure you have the package <em>xterm</em> installed.
</p>
<p>
Cheers!</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fthinkingeek.com%2F2011%2F05%2F19%2Finstalling-xmonad-in-archlinux%2F&amp;title=Installing%20xmonad%20in%20ArchLinux" id="wpa2a_20" onclick="pageTracker._trackPageview('/outgoing/www.addtoany.com/share_save_url=http_3A_2F_2Fthinkingeek.com_2F2011_2F05_2F19_2Finstalling-xmonad-in-archlinux_2F_amp_title=Installing_20xmonad_20in_20ArchLinux?referer=');"><img src="http://thinkingeek.com/wp-content/plugins/add-to-any/share_save_120_16.gif" width="120" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://thinkingeek.com/2011/05/19/installing-xmonad-in-archlinux/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

