http://chodounsky.net/chodounsky.net - Jakub Chodounsky2013-05-24T00:00:00ZJakub Chodounskyhttp://www.chodounsky.nettag:chodounsky.net,2013-05-24:/2013/05/24/pro-tip-change-vim-color-theme/Pro Tip - Change Vim Color Theme2013-05-24T00:00:00Z2013-05-24T00:00:00Z<p>Pro Tip is a new section of this blog. It contains useful tips for programming professionals and computer power users. I think all of you, dear readers, are in this category. It should help you to be more productive and effective in daily tasks. Let’s start with the first one.</p>
<p>I like to use a notebook on different places and on various times. I like to code on a sunny day on my balcony. I like to lie on the couch near the window. I like to stand at the bar table near the kitchen. </p>
<p>Each location provides different light conditions. Each location makes your eyes fatigue in a different way. The first thing that can help you is the brightness and contrast adjustment of your monitor. With normal conditions I set up my contrast and brightness to only 30% of the maximum level. 100% is used only on the direct sun on the balcony.</p>
<p>Sometimes screen adjustments are simply not enough. In these cases it is a good idea to use high and low contrast themes. High contrast for a sunny place and the low one in the dark. </p>
<p><img src="/resources/img/posts/2013-05-24-pro-tip-change-vim-color-theme-1.png" alt="Codeschool color scheme is great for working in the dark" /></p>
<p>Using vim you can do that without restarting the program. Go to normal (command) mode by pressing <code>CTRL + C</code> and type:</p>
<pre><code>:colorscheme <name of the scheme>
</code></pre>
<p>Great color scheme for working in the dark and normal lightning is <code>codeschool</code> and <code>zellner</code> is handy for the light places.</p>
<p><img src="/resources/img/posts/2013-05-24-pro-tip-change-vim-color-theme-2.png" alt="Zellner theme is useful in the direct sunlight." /></p>
tag:chodounsky.net,2013-05-20:/2013/05/20/weekly-digest-14/Weekly Digest 142013-05-20T00:00:00Z2013-05-20T00:00:00Z<p>Previously on chodounsky.net</p>
<ul>
<li><a href="http://chodounsky.net/2013/05/15/dont-flood-your-twitter-schedule/">Don’t Flood Your Twitter - Schedule!</a></li>
</ul>
<p>The best links from community</p>
<ul>
<li><a href="http://blog.willbenton.com/2008/11/rent-a-coder-hilarity/">Rent-a-coder hilarity</a> - Will Benton</li>
<li><a href="http://www.troyhunt.com/2013/05/clickjack-attack-hidden-threat-right-in.html">Clickjack attack – the hidden threat right in front of you</a> - Troy Hunt</li>
<li><a href="http://haacked.com/archive/2013/05/13/applying-conways-law.aspx">Applying Conway’s Law</a> - Phil Haack</li>
<li><a href="http://www.yosefk.com/blog/parallelism-and-concurrency-need-different-tools.html">Parallelism and concurrency need different tools</a> - Yossi Kreinin</li>
<li><a href="http://blog.filipekberg.se/2013/05/14/using-bit-fields-in-csharp/">Using bit fields in C#</a> - Filip Ekberg</li>
<li><a href="http://www.troyhunt.com/2013/05/hack-yourself-first-how-to-go-on.html">Hack yourself first – how to go on the offence before online attackers do</a> - Troy Hunt</li>
<li><a href="http://www.akkadia.org/drepper/cpumemory.pdf">What Every Programmer Should Know About Memory - PDF</a> - Ulrich Drepper</li>
<li><a href="http://ericlippert.com/2013/05/16/spot-the-defect-rounding-part-two/">Spot the defect: rounding, part two</a> - Eric Lippert</li>
<li><a href="http://jobtipsforgeeks.com/2013/05/17/booklearnin/">The Dangers of Book Learnin’</a> - Dave Fecak</li>
<li><a href="https://twitter.com/Zigoo0/status/335889277122666496/photo/1">Programmers VS Hackers</a> - Zigoo0</li>
<li><a href="http://blogs.msdn.com/b/agileer/archive/2013/05/17/the-right-way-to-write-a-custom-exception-class.aspx">The CORRECT Way to Code a Custom Exception Class</a> - Doug Seelinger</li>
</ul>
<p>Interesting projects are</p>
<ul>
<li><a href="http://developer.android.com/sdk/installing/studio.html">Android Studio</a></li>
</ul>
<p>And finally more great link collections</p>
<ul>
<li><a href="http://www.alvinashcraft.com/">Dew Drop</a> - Alvin Ashcraft’s Morning Dew,</li>
<li><a href="http://blog.cwa.me.uk/">The Morning Brew</a> - Chris Alcock,</li>
<li><a href="http://www.dirkstrauss.com/the-daily-six-pack">The Daily Sixpack</a> - Dirk Strauss,</li>
<li><a href="http://jasonhaley.com/blog/">Interesting Finds</a> - Jason Haley.</li>
</ul>
tag:chodounsky.net,2013-05-15:/2013/05/15/dont-flood-your-twitter-schedule/Don't Flood Your Twitter - Schedule!2013-05-15T00:00:00Z2013-05-15T00:00:00Z<p>I read a lot of blog posts. As most of you probably know, I digest these posts for you, dear reader, in <a href="http://chodounsky.net/2013/05/06/weekly-digest-12/">weekly programming digests</a> - and if you didn’t know, go and check them out.</p>
<p>Each day I post articles I liked on <a href="https://twitter.com/search?q=%23codingdigest%20%40jakubgarfield&src=typd">Twitter</a>. That means multiple links per day. I used to send my links through email and submit them before the dinner to Twitter in a batch. </p>
<p>One of my friends was complaining that I flooded his wall. Every tweet he saw was from me when I decided to do the batch. This is definitely not a good thing. I am very glad he didn’t remain silent and he told me what bothers him. Criticism is always a good thing and you should learn from your mistakes.</p>
<p>This batch approach, apart from it can drive some people mad and make them unfollow you, has a few other disadvantages too. If someone misses your batch you are invisible. There is no evidence of your virtual presence and activity. And you will become invisible for users from different timezones.</p>
<p>So I started to think, how to solve this problem. There must be some way to schedule your tweets. My requirements were simple. I wanted to schedule my tweet to a given time, I wanted an extension for Chrome and I wanted to be able tweet from my android phone and tablet.</p>
<p>I found a great application (or more likely a platform) that satisfies all my requirements and gives me much more features called <a href="https://bufferapp.com">Buffer</a>.</p>
<h3 id="how-does-it-work">How Does It Work?</h3>
<p>You simple sign with your Twitter account. You can use Facebook, LinkedIn or a custom one. Buffer works with these social platforms too but they are not on my radar. </p>
<p>After signing you download a browser extension - Chrome, Firefox and Safari are supported. Or you can install application for your phone. Currently iPhone and Android are supported.</p>
<p><img src="/resources/img/posts/2013-05-15-dont-flood-your-twitter-schedule-1.png" alt="How to share a site like chodounsky.net with Buffer" /></p>
<p>When you find a site that is remarkable for sharing, like chodounsky.net of course, you click on the buffer extension button in the top right corner and click Buffer. Link shortening is handled for you by Buffer worry about the length of the URL. For shortening you can choose <a href="http://bit.ly">bit.ly</a> or use the one provided from Buffer.</p>
<p>You can set up your custom schedule when to post your tweets.</p>
<p><img src="/resources/img/posts/2013-05-15-dont-flood-your-twitter-schedule-2.png" alt="Schedule setup" /></p>
<p>And if you use service for link shortening there are simple statistics that can track the performance of your links. </p>
<p><img src="/resources/img/posts/2013-05-15-dont-flood-your-twitter-schedule-3.png" alt="Buffer Analytics" /></p>
<p>Mobile version uses the Share button on your phone. Therefore you can add content to buffer from every application that supports sharing. I use it with my mobile browser and the mobile version of <a href="http://feedly.com">feedly</a>. And it works just great.</p>
<h2 id="conclusion">Conclusion</h2>
<p><a href="http://bufferapp.com">Buffer</a> is a great application for managing your tweets and social activity in general. It is free for basic usage and the basic features are everything you should need. You should never flood your follower’s walls again.</p>
<p>You can use it with your browser or smartphone. Great tool!</p>
tag:chodounsky.net,2013-05-13:/2013/05/13/weekly-digest-13/Weekly Digest 132013-05-13T05:07:03Z2013-05-13T05:07:03Z<p>Previously on chodounsky.net</p>
<ul>
<li><a href="http://chodounsky.net/2013/05/09/merge-files-with-git-merge-tool/">Merge Files with Git Merge Tool</a></li>
</ul>
<p>The best links from community</p>
<ul>
<li><a href="http://blogs.atlassian.com/2013/05/git-branching-and-forking-in-the-enterprise-why-fork/">Git Branching and Forking in the Enterprise: Why Fork?</a> - Nicola Paolucci</li>
<li><a href="http://bigocheatsheet.com/">Big-O Cheat Sheet</a> </li>
<li><a href="http://ericlippert.com/2013/05/06/producing-permutations-part-seven/">Producing permutations, part seven</a> - Eric Lippert</li>
<li><a href="http://www.troyhunt.com/2013/05/why-i-am-worlds-greatest-lover-and.html">Why I am the world’s greatest lover (and other worthless security claims)</a> - Troy Hunt</li>
<li><a href="http://www.codeproject.com/Articles/493389/Four-ways-of-passing-data-between-layers">Four ways of passing data between layers</a> - Shivprasad koirala</li>
<li><a href="http://ericlippert.com/2013/05/10/i-have-a-mysterious-fifth-sense/">Rerun: I have a mysterious fifth sense</a> - Eric Lippert</li>
<li><a href="http://jeremykun.com/primers/">Math ∩ Programming - Primers</a> - Jeremy Kun</li>
</ul>
<p>And finally more great link collections</p>
<ul>
<li><a href="http://www.alvinashcraft.com/">Dew Drop</a> - Alvin Ashcraft’s Morning Dew,</li>
<li><a href="http://blog.cwa.me.uk/">The Morning Brew</a> - Chris Alcock,</li>
<li><a href="http://www.dirkstrauss.com/the-daily-six-pack">The Daily Sixpack</a> - Dirk Strauss,</li>
<li><a href="http://jasonhaley.com/blog/">Interesting Finds</a> - Jason Haley.</li>
</ul>
tag:chodounsky.net,2013-05-09:/2013/05/09/merge-files-with-git-merge-tool/Merge Files with Git Merge Tool2013-05-09T13:45:19Z2013-05-09T13:45:19Z<p>Last time I wrote about <a href="http://chodounsky.net/2013/05/01/compare-files-with-git-diff-tool/">git diff and difftool</a> and showed you how to use them to compare different files and versions. Today I am going to focus on the merging and conflict resolution with git merge and mergetool. Merging is an important part of the development process. If you use git you probably work with <a href="http://nvie.com/posts/a-successful-git-branching-model/">multiple branches</a>. But even if you develop in trunk with more people, merging and the conflict resolution comes in place when two are working on the same file.</p>
<h3 id="merge-tool">Merge Tool</h3>
<p>Mergetool is a command in git that lets you run your custom tool for resolving conflicts in your merged files. Let’s setup the tool and take a closer look at the basic usage. </p>
<h4 id="setup">Setup</h4>
<p>We will use <a href="http://www.perforce.com/product/components/perforce-visual-merge-and-diff-tools">p4merge</a> as we already use it for a <a href="http://chodounsky.net/2013/05/01/compare-files-with-git-diff-tool/">difftool</a>. It is a great tool with a lot of extra features and very good performance.</p>
<p>For setting up p4merge as your mergetool you have to run these commands.</p>
<pre class="prettyprint"><code>git config --global merge.tool p4merge
git config --global mergetool.prompt false
git config --global mergetool.p4merge.cmd '\"C:/Program Files/Perforce/p4merge.exe\" $BASE $LOCAL $REMOTE $MERGED'
git config --global mergetool.p4merge.keepTemporaries false
git config --global mergetool.p4merge.trustExitCode false
</code></pre>
<h4 id="usage">Usage</h4>
<p>So you’ve set up your tool. Let’s resolve our first conflict that I created. I have two branches. Master and iss1. I created file called test.txt in both of them. The content of the file in master branch is <em>master</em> and the content in the iss1 branch is <em>iss1</em>. I committed those changes and now I am trying to merge iss1 into master branch. I ran <code>git merge iss1</code> command. Take a look at the output.</p>
<pre><code>C:\Users\Jakub\Desktop\ruby-sample [master]> git merge iss1
Auto-merging test.txt
CONFLICT (add/add): Merge conflict in test.txt
Automatic merge failed; fix conflicts and then commit the result.
</code></pre>
<p>Merge couldn’t be performed automatically and manual resolution comes into place. Now we run the mergetool command.</p>
<pre class="prettyprint"><code>git mergetool
</code></pre>
<p>P4merge tool starts right away.</p>
<p><img src="/resources/img/posts/2013-05-09-merge-files-with-git-merge-tool-1.png" alt="P4merge and the conflict resolution of the file test.txt" /></p>
<p>You can see that p4merge supports <a href="http://en.wikipedia.org/wiki/Merge_%28revision_control%29#Three-way_merge">three-way merge</a>. Resolve the conflict and save the file.</p>
<p>Branches were successfully saved. You can notice git created *.orig file with the content from both branches - test.txt.orig. If you’d like to remove this file after merge automatically you have to disable mergetool backups.</p>
<pre class="prettyprint"><code>git config --global mergetool.keepBackup false
</code></pre>
<h2 id="conclusion">Conclusion</h2>
<p>This article gave you a quick introduction to merging with git. You set up p4merge as your primary mergetool and you are able to use it for any conflict resolution.</p>
tag:chodounsky.net,2013-05-06:/2013/05/06/weekly-digest-12/Weekly Digest 122013-05-06T00:00:00Z2013-05-06T00:00:00Z<p>Previously on chodounsky.net</p>
<ul>
<li><a href="http://chodounsky.net/2013/05/01/compare-files-with-git-diff-tool/">Compare Files with Git Diff Tool</a></li>
</ul>
<p>The best links from community</p>
<ul>
<li><a href="http://what-if.xkcd.com/43/">Train Loop</a> - xkcd</li>
<li><a href="http://agile.dzone.com/articles/pair-programming-and-grass">Pair Programming and a Grass-Roots Movement</a> - Scott Leberknight</li>
<li><a href="http://ericlippert.com/2013/04/29/producing-permutations-part-five">Producing permutations, part five</a> - Eric Lippert</li>
<li><a href="http://www.codinghorror.com/blog/2013/04/so-you-dont-want-to-be-a-programmer-after-all.html">So You Don’t Want to be a Programmer After All</a> - Jeff Atwood</li>
<li><a href="http://weblogs.asp.net/ricardoperes/archive/2013/04/29/entity-framework-code-first-inheritance.aspx">Entity Framework Code First Inheritance</a> - Ricardo Peres</li>
<li><a href="http://weblogs.asp.net/ricardoperes/archive/2013/04/29/entity-framework-code-first-relations.aspx">Entity Framework Code First Relations</a> - Ricardo Peres</li>
<li><a href="http://highscalability.com/blog/2013/5/1/myth-eric-brewer-on-why-banks-are-base-not-acid-availability.html">Myth: Eric Brewer On Why Banks Are BASE Not ACID - Availability Is Revenue </a> - Todd Hoff</li>
<li><a href="http://dotnet.dzone.com/articles/intro-git">Git Explained: For Beginners</a> - Juri Strumpflohner</li>
<li><a href="http://ericlippert.com/2013/05/02/producing-permutations-part-six/">Producing permutations, part six</a> - Eric Lippert</li>
<li><a href="http://msdn.microsoft.com/en-us/magazine/dn198238.aspx">Social Authentication in ASP.NET MVC 4</a> - Dino Esposito</li>
<li><a href="http://blog.jongallant.com/2013/05/work-life-balance-at-microsoft.html#.UYYP7KKNJws">My Thoughts on Work/Life Balance at Microsoft</a> - Jon Gallant</li>
<li><a href="https://medium.com/what-i-learned-building/9216e1c9da7d">McDonald’s Theory</a> - Jon Bell</li>
<li><a href="http://www.blackwasp.co.uk/InvokeMaxParallelism.aspx">Limiting Parallelism with Parallel.Invoke</a> - Richard Carr</li>
<li><a href="http://blogs.msdn.com/b/eric_brechner/archive/2013/05/01/evil-assumptions.aspx">Evil assumptions</a> - Eric Brechner</li>
<li><a href="http://blog.notdot.net/2007/4/Damn-Cool-Algorithms-Part-1-BK-Trees">Damn Cool Algorithms, Part 1: BK-Trees</a> - Nick Johnson</li>
<li><a href="http://slott-softwarearchitect.blogspot.cz/2013/04/legacy-code-preservation-paving-cowpaths.html">Legacy Code Preservation: Paving the Cowpaths</a> - Steven Lott</li>
</ul>
<p>Interesting projects are</p>
<ul>
<li><a href="http://joshnuss.github.io/mruby-web-irb/">mruby web irb</a> - web interactive ruby interface</li>
<li><a href="https://github.com/diowa/ruby2-rails4-bootstrap-heroku">ruby2-rails4-bootstrap-heroku</a> - A Starter Application based on Ruby2 Rails4 and Twitter Bootstrap, deployable on Heroku</li>
</ul>
<p>And finally more great link collections</p>
<ul>
<li><a href="http://www.alvinashcraft.com/">Dew Drop</a> - Alvin Ashcraft’s Morning Dew,</li>
<li><a href="http://blog.cwa.me.uk/">The Morning Brew</a> - Chris Alcock,</li>
<li><a href="http://www.dirkstrauss.com/the-daily-six-pack">The Daily Sixpack</a> - Dirk Strauss,</li>
<li><a href="http://jasonhaley.com/blog/">Interesting Finds</a> - Jason Haley.</li>
</ul>
tag:chodounsky.net,2013-05-01:/2013/05/01/compare-files-with-git-diff-tool/Compare Files with Git Diff Tool2013-05-01T13:44:50Z2013-05-01T13:44:50Z<p>Comparing files under your version control system is one of the most common tasks in programming. This article describes techniques that are available in git. It helps you setup git diff tool and shows you how to use it to perform some basic comparisons of your changes to a current base and also few more advanced comparisons between specific commits.</p>
<h3 id="diff">Diff</h3>
<p>Git already comes with the tool for file comparison. It is text based and easy to use with files with few line changes. </p>
<h4 id="changing-colors">Changing Colors</h4>
<p>If you use git on Windows especially with Powershell and <a href="https://github.com/dahlbyk/posh-git">posh-git</a> extensions you soon realize that some colors in the output are very hard to read. The dark red used with git status and displayed changes doesn’t work very well with the blue background.</p>
<p><img src="/resources/img/posts/2013-05-01-compare-files-with-git-diff-tool-1.png" alt="Example of the wrong contrast between colors in Powershell." /></p>
<p>For changing git global configuration of modified and untracked files you need to run these commands. Let’s change the color from dark red to cyan and also modify the colors for changes to more shiny ones.</p>
<pre class="prettyprint"><code>git config --global color.status.changed "cyan normal bold"
git config --global color.status.untracked "cyan normal bold"
git config --global color.diff.old "red normal bold"
git config --global color.diff.new "green normal bold"
</code></pre>
<p>Posh-git is a great tool but the information about modified, untracked and removed files aren’t readable. We’ll change it to much better colors. You have to edit your Powershell profile that is located in your documents folder and you can run <code>$profile</code> to see where exactly it is. Add the following lines to the end of the file and it changes the output from dark red to yellow.</p>
<pre class="prettyprint"><code>$global:GitPromptSettings.WorkingForegroundColor = [ConsoleColor]::Yellow
$global:GitPromptSettings.UntrackedForegroundColor = [ConsoleColor]::Yellow
</code></pre>
<p>Now the output in the Powershell window is much more readable. Take a look at the screenshot and compare it with the previous one.</p>
<p><img src="/resources/img/posts/2013-05-01-compare-files-with-git-diff-tool-2.png" alt="Tuned colors with posh-git and git diff tool in Windows Powershell." /></p>
<p>This looks much better than the previous one, don’t you think?</p>
<h4 id="usage">Usage</h4>
<p>The most simple usage is to run the command without any parameters.</p>
<pre class="prettyprint"><code>git diff
</code></pre>
<p>It displays all the differences in all your modified files from previously committed work. Old lines are prefixed with the <strong>-</strong> sign and the new lines with the <strong>+</strong> sign. There is many more information in the output and I recommend to take a look at <a href="http://stackoverflow.com/questions/2529441/how-to-work-with-diff-representation-in-git">stackoverflow</a> for their representation. Just be aware that some of them are not available in the msysgit implementation on Windows.</p>
<p>For displaying the difference in just one file you have to add the file relative location and the file name.</p>
<pre class="prettyprint"><code>git diff location\filename
</code></pre>
<h3 id="difftool">Difftool</h3>
<p>If you are not satisfied with the simple text diff you need to use a custom tool. For this purpose git provides a command <strong>difftool</strong>. It allows you to register comparison tool of your choice and to integrate it with git.</p>
<h4 id="setup">Setup</h4>
<p>The tool of my choice is <a href="http://www.perforce.com/product/components/perforce-visual-merge-and-diff-tools">p4merge</a>. It is a free, fast and it is capable of performing the most challenging merging and comparing tasks.</p>
<p><img src="/resources/img/posts/2013-05-01-compare-files-with-git-diff-tool-3.png" alt="p4merge in action." /></p>
<p>There is a lot of different tools you can use and each setup would be a little different. Next steps show you how to setup p4merge as git difftool.</p>
<pre class="prettyprint"><code>git config --global diff.tool p4merge
git config --global difftool.p4merge.cmd 'p4merge.exe $LOCAL $REMOTE'
git config --global difftool.prompt false
</code></pre>
<p>P4merge must be added to your system path. Otherwise you have to provide the full path to the exe file in the <code>difftool.p4merge.cmd</code> line. </p>
<p>That’s it. From now on p4merge is ready to compare your files. Let’s try it with comparing the working file against the revision in repository. The usage is similar to the git diff from above.</p>
<pre class="prettyprint"><code># Starts git difftool for all modified files
git difftool
# Compare only specific file
git difftool location\filename
</code></pre>
<p>The first command runs the difftool for all modified files and the second one compares only the specified file.</p>
<h4 id="advanced-usage">Advanced Usage</h4>
<p>The first thing we want to do is to compare file against specific revision. You can list file revisions with the git log command.</p>
<pre><code>git log filename
</code></pre>
<p>From the output you can copy the commit identifier and run the difftool with the path to the version you want to compare with. Just like this.</p>
<pre class="prettyprint"><code>git difftool 8d53363981a35c07f2bee7cae71f8e8bd95be625 -- filename
</code></pre>
<p>You can also compare between two different commits with the following syntax.</p>
<pre class="prettyprint"><code># git difftool [start commit]..[end commit] filename
git difftool 6cde26245763dd43f9505c7578a1f7be44b7fad1..8d53363981a35c07f2bee7cae71f8e8bd95be625 filename
</code></pre>
<p>You can specify the path of the revision to the branch, relatively to the number of history commits and in more other ways you can ever dream about. Also don’t forget that you can use graphical tools for displaying the history of the file like <strong>gitk</strong> and others.</p>
<h2 id="conclusion">Conclusion</h2>
<p>Your git should be set up to use diff tool p4merge. With the changed colors you receive much better experience from your command line output. </p>
<p>After reading this article comparison of two different files and looking for changes between different revisions and branches should be no mystery for you. If you have any suggestions to make this experience even more pleasant, please leave a comment.</p>
tag:chodounsky.net,2013-04-29:/2013/04/29/weekly-digest-11/Weekly Digest 112013-04-29T00:00:00Z2013-04-29T00:00:00Z<p>Previously on chodounsky.net</p>
<ul>
<li><a href="http://chodounsky.net/2013/04/23/nanoc-project-structure/">Nanoc Project Structure</a></li>
</ul>
<p>The best links from community</p>
<ul>
<li><a href="http://jaylee.org/post/2013/04/18/Memoization-and-Immutable-data-in-CSharp-Part-1.aspx">Immutable Data and Memoization in C#, Part 1</a> - Jérôme Laban</li>
<li><a href="http://ericlippert.com/2013/04/22/producing-permutations-part-three/">Producing permutations, part three</a> - Eric Lippert</li>
<li><a href="http://haacked.com/archive/2013/04/22/better-testers.aspx">Better Testers</a> - Phil Haack</li>
<li><a href="http://www.hanselman.com/blog/ExposedABlogCommentSpammersSourceTemplate.aspx">Exposed: A Blog Comment Spammer’s Source Template</a> - Scott Hanselman</li>
<li><a href="http://www.infoq.com/news/2013/04/Immutable-Collections">More on Immutable Collections in .NET</a> - Jonathan Allen</li>
<li><a href="http://geekswithblogs.net/simonc/archive/2013/04/19/inside-portable-class-libraries.aspx">Inside Portable Class Libraries</a> - Simon Cooper</li>
<li><a href="http://fsharpforfunandprofit.com/posts/ten-reasons-not-to-use-a-functional-programming-language">Ten reasons not to use a statically typed functional programming language</a> - scottw</li>
<li><a href="http://blogs.msdn.com/b/nikolait/archive/2013/04/23/introducing-code-digger-an-extension-for-vs2012.aspx">Introducing: Code Digger, an extension for VS2012</a> - Nikolai Tillmann</li>
<li><a href="http://slott-softwarearchitect.blogspot.co.uk/2013/04/legacy-code-preservation-are-there.html">Legacy Code Preservation: Are There Quirks?</a> - Steven Lott</li>
<li><a href="http://blogs.msdn.com/b/zainnab/archive/2013/02/12/understanding-intellitrace-part-i-what-the-is-intellitrace.aspx">Understanding IntelliTrace Part I</a> - zainmab</li>
<li><a href="http://www.marcusoft.net/2013/04/WhatDoYouOptimizeFor2.html">Are you coding for change or stability - the followup post</a> - Marcus Hammarberg</li>
<li><a href="http://jaylee.org/post/2013/04/22/Immutable-Data-and-Memoization-in-CSharp-Part-2.aspx">Immutable Data and Memoization in C#, Part 2</a> - Jérôme Laban</li>
<li><a href="http://mikehadlow.blogspot.co.uk/2013/04/stop-your-console-app-nice-way.html">Stop Your Console App The Nice Way</a> - Mike Hadlow</li>
<li><a href="https://medium.com/the-healthy-life/b65f8e19ed18">Sleep: Everything You Need To Know</a> - Maroun Najjar</li>
<li><a href="http://adit.io/posts/2013-04-17-functors,_applicatives,_and_monads_in_pictures.html">Functors, Applicatives, And Monads In Pictures</a> - Aditya Bhargava</li>
<li><a href="http://ericlippert.com/2013/04/25/producing-permutations-part-four/">Permutations, part four</a> - Eric Lippert</li>
</ul>
<p>Interesting projects are</p>
<ul>
<li><a href="http://artpolikarpov.github.io/garmoshka/">Garmoshka</a> - CSS3 responsive design project</li>
<li><a href="http://www.codeproject.com/Tips/581743/Dynamic-Lambda-Expression-Compiler">Dynamic Lambda Expression Compiler</a> - Fernando Callejon</li>
</ul>
<p>And finally more great link collections</p>
<ul>
<li><a href="http://www.alvinashcraft.com/">Dew Drop</a> - Alvin Ashcraft’s Morning Dew,</li>
<li><a href="http://blog.cwa.me.uk/">The Morning Brew</a> - Chris Alcock,</li>
<li><a href="http://www.dirkstrauss.com/the-daily-six-pack">The Daily Sixpack</a> - Dirk Strauss,</li>
<li><a href="http://jasonhaley.com/blog/">Interesting Finds</a> - Jason Haley.</li>
</ul>
tag:chodounsky.net,2013-04-23:/2013/04/23/nanoc-project-structure/Nanoc Project Structure2013-04-23T00:00:00Z2013-04-23T00:00:00Z<p>In the <a href="http://chodounsky.net/2013/03/28/introduction-to-static-site-generation-with-nanoc/">previous part</a> of the series we created a simple hello world application and fixed problems with the encoding. This part guides you through the nanoc project structure and gives you better understanding how the web site is linked together.</p>
<p>There are multiple files and folders in the project structure.</p>
<pre><code>|- content/
|- layouts/
|- lib/
|- output/
|- tmp/
|- nanoc.yaml (config.yaml)
|- crash.log
|- Rules
</code></pre>
<dl>
<dt>content/</dt>
<dd>contains uncompiled data for your web site</dd>
<dt>layouts/</dt>
<dd>all your templates are placed here</dd>
<dt>lib/</dt>
<dd>helper functions, extensions and all your custom ruby code</dd>
<dt>output/</dt>
<dd>compiled web site prepared for deploying to server</dd>
<dt>tmp/</dt>
<dd>temporary files used for speeding up the compilation</dd>
<dt>nanoc.yaml</dt>
<dd>site configuration, in the older versions this file is called config.yaml</dd>
<dt>crash.log</dt>
<dd>if your compilation fails the error is logged in this file</dd>
<dt>Rules</dt>
<dd>contains a set of rules how to treat your content files</dd>
</dl>
<p>Let’s take a closer look to the important items in the hierarchy.</p>
<h3 id="rules">Rules</h3>
<p>This file is the most essential file in the nanoc generator. Rules are used for two different important purposes - compilation and routing. To be technically precise there is a preprocessing before compilation. It can be used for advanced techniques like pagination but we are going to skip this process to keep it simple.</p>
<h4 id="compilation">Compilation</h4>
<p>Compilation determines how specified files should be treated when compiled by nanoc. You can set filters and assign layouts. </p>
<p>Filters are used for content transformation. You can chain multiple filters together. Typical example is to compile your pages written in markdown with the kramdown filter.</p>
<pre class="prettyprint"><code>compile 'posts/*' do
filter :kramdown
end
</code></pre>
<p>In this example all the files in the posts directory are compiled with the kramdown filter. </p>
<p>You can use advanced code in the compile body. For example you can compile your files based on extension.</p>
<pre class="prettyprint"><code>compile '*' do
if item.binary?
# don’t filter binary items
else
case item[:extension]
when 'md'
filter :kramdown
layout 'default'
when 'erb'
filter :erb
layout 'default'
end
end
end
</code></pre>
<p>No filter is set for binary items. Items with *.md extension are compiled with kramdown filter and items with *.erb extension are treated as erb files.</p>
<p>The layout property is used for choosing proper template. Templates are stored in the layout folder and this is how they are assigned to items from the content folder. You can use special template for all your blog posts and default template for normal pages. Next example shows you how to do it.</p>
<pre class="prettyprint"><code>compile 'posts/*'
layout: 'post'
end
compile '*'
if item.binary?
# don’t filter binary items
else
layout: 'default'
end
end
</code></pre>
<p>Keep in mind that you should start with the most specific rules. <strong>Rules ordering matters</strong>. If you put general rule for ‘*’ to the top of your file all other rules are skipped. </p>
<pre class="prettyprint"><code>compile '*' do
...
end
compile 'post/**' do
// this rule won't be applied because it is
// placed in this file after more general one
end
</code></pre>
<p>Filters can be also very useful for binary files and your resources. Imagine that you can create thumbnails from your images for your custom gallery. Or you want to write your CSS with LESS and then use minification. All these things are possible with nanoc.</p>
<h4 id="routing">Routing</h4>
<p>The second important part of the Rules file is routing. These rules are used to determine the physical representation of the output of compiled content. In other words it says where the file would be placed on your web server.</p>
<p>As with the compilation rules routing ordering also matters so you should keep the general ones at the bottom.</p>
<p>Routing can be used for ignoring output from specific folders. Let’s say we have a draft folder. If you don’t set the route body the output is ignored.</p>
<pre class="prettyprint"><code>route 'posts/drafts/*' do
end
</code></pre>
<p>Another usage of routing is the way to create cleaner URLs for non binary items.</p>
<pre class="prettyprint"><code>route '*' do
if item.binary?
# Write item with identifier /foo/ to /foo.ext
item.identifier.chop + '.' + item[:extension]
else
# Write item with identifier /foo/ to /foo/index.html
item.identifier + 'index.html'
end
end
</code></pre>
<h3 id="layout">Layout</h3>
<p>We already discussed how the layout files are assigned with Rules file. The file with the assigned name (without extension) must exist in the layout folder. Layout file is a HTML template with special tag <code><%= yield =></code>. After compilation the tag is replaced by current content.</p>
<pre class="prettyprint"><code><html>
<head>
<title>Hello World</title>
</head>
<body>
<%= yield =>
</body>
</html>
</code></pre>
<p>You can create partial views. They can be nested together. This feature is very useful especially when you have a global view and few special nested views like gallery, post or project view.</p>
<pre class="prettyprint"><code><% render "default" do %>
<h2>Other view</h2>
<div>
<%= yield =>
</div>
<% end %>
</code></pre>
<p>In the example above the view is placed in the file called default.erb instead of the yield and current compiled content is placed instead of the yield in this partial view.</p>
<h3 id="configuration">Configuration</h3>
<p>The global configuration of your web site is located in the nanoc.yaml or config.yaml in older version of nanoc. In our default hello world application it contains information about supported text extensions, automatic watcher and some other global settings.</p>
<p>You can change output directory of your site by modifying the <code>output_dir: output</code> to another value.</p>
<p>It is not necessary to change those settings for creating basic applications but you can add your own. </p>
<pre class="prettyprint"><code>title: 'chodounsky.net - Jakub Chodounsky'
author_name: 'Jakub Chodounsky'
author_uri: 'http://www.chodounsky.net'
base_url: 'http://chodounsky.net'
</code></pre>
<h3 id="helpers-and-custom-functions">Helpers and Custom Functions</h3>
<p>Helpers are pieces of ruby code that you can use in your layouts and items. Location for your custom helpers is in the <strong>lib</strong> folder.</p>
<p>By default there is a file called <strong>default.rb</strong>. Nanoc comes with a set of integrated helpers but they need to be activated before using. This can be done very easily.</p>
<pre class="prettyprint"><code>include Nanoc3::Helpers::Blogging
include Nanoc3::Helpers::Tagging
include Nanoc3::Helpers::Rendering
include Nanoc3::Helpers::LinkTo
</code></pre>
<p>If you want to write custom code you can do it in the default.rb or you can create new files and link modules together in the default.rb.</p>
<h2 id="conclusion">Conclusion</h2>
<p>After reading this article you don’t have to search anymore where to put your content and where to modify necessary files. Now you should have a good starting point for creating custom web site with nanoc. </p>
<p>In the next article we will focus on the blogging features and how nanoc can be an effective tool that won’t stand in your way.</p>
tag:chodounsky.net,2013-04-22:/2013/04/22/weekly-digest-10/Weekly Digest 102013-04-22T00:00:00Z2013-04-22T00:00:00Z<p>The best links from community</p>
<ul>
<li><a href="http://www.codeproject.com/Articles/566542/Date-and-Time-Data-Types-and-Functions-SQL-Server">Date and Time Data Types and Functions</a> - Shemeer NS</li>
<li><a href="http://www.hanselman.com/blog/InstallingHelveticaNeueFontsWithGoogleChromeOnWindowsConsideredHarmful.aspx">Installing Helvetica Neue Fonts with Google Chrome on Windows considered harmful</a> - Scott Hanselman</li>
<li><a href="http://www.marcusoft.net/2013/04/WhatDoYouOptimizeFor.html">Are you coding for change or for stability?</a> - Marcus Hammarberg</li>
<li><a href="http://ericlippert.com/2013/04/15/producing-permutations-part-one/">Producing permutations, part one</a> - Eric Lippert</li>
<li><a href="http://ericlippert.com/2013/04/18/producing-permutations-part-two/">Producing permutations, part two</a> - Eric Lippert </li>
<li><a href="http://www.jamesaltucher.com/2013/04/why-do-people-hate-their-jobs/">Why Do People Hate Their Jobs?</a> - James Altucher</li>
<li><a href="http://nathanmarz.com/blog/you-should-blog-even-if-you-have-no-readers.html?utm_source=hackernewsletter">You should blog even if you have no readers</a> - Nathan Marz</li>
</ul>
<p>And finally more great link collections</p>
<ul>
<li><a href="http://www.alvinashcraft.com/">Dew Drop</a> - Alvin Ashcraft’s Morning Dew,</li>
<li><a href="http://blog.cwa.me.uk/">The Morning Brew</a> - Chris Alcock,</li>
<li><a href="http://www.dirkstrauss.com/the-daily-six-pack">The Daily Sixpack</a> - Dirk Strauss,</li>
<li><a href="http://jasonhaley.com/blog/">Interesting Finds</a> - Jason Haley.</li>
</ul>