<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom"><title>Silviu Tantos (razius)</title><link href="https://razius.com/" rel="alternate"></link><link href="https://razius.com/feeds/all.atom.xml" rel="self"></link><id>https://razius.com/</id><updated>2014-01-19T10:58:00+01:00</updated><entry><title>Auto-refreshing Google Chrome on file changes.</title><link href="https://razius.com/articles/auto-refreshing-google-chrome-on-file-changes.html" rel="alternate"></link><published>2014-01-19T10:58:00+01:00</published><updated>2014-01-19T10:58:00+01:00</updated><author><name>Silviu Tantos</name></author><id>tag:razius.com,2014-01-19:/articles/auto-refreshing-google-chrome-on-file-changes.html</id><summary type="html">&lt;p&gt;I am known for being an lazy ass, one of the ways of coping with this horrible disease is automating any repetitive task that takes more that 5 minutes of work. So, in my free time, when I&amp;#8217;m not dreaming of eating cake on a magical dessert island, I …&lt;/p&gt;</summary><content type="html">&lt;p&gt;I am known for being an lazy ass, one of the ways of coping with this horrible disease is automating any repetitive task that takes more that 5 minutes of work. So, in my free time, when I&amp;#8217;m not dreaming of eating cake on a magical dessert island, I have the habit of bashing away at my keyboard to write shell scripts that ease my&amp;nbsp;life.&lt;/p&gt;
&lt;p&gt;During the process of writing a &lt;span class="caps"&gt;HTML&lt;/span&gt; presentation for my school and while trying to find ways to procrastinate and avoid it, I head this little voice in my head: &amp;#8220;Hey, psstt, you, wouldn&amp;#8217;t it be neat if you didn&amp;#8217;t have to spend those 5 seconds refreshing the browser window each time you save that&amp;nbsp;file?&amp;#8221;.&lt;/p&gt;
&lt;p&gt;After consulting my trusty &amp;#8220;Is it work the time chart?&amp;#8221; and seeing that I have lots of free time, with the weekend ahead of me, I&amp;#8217;ve decided to listen to my little procrastination demon and dive in to see how I can shave those 5 seconds&amp;nbsp;off.&lt;/p&gt;
&lt;div class="figure align-center"&gt;
&lt;a class="reference external image-reference" href="http://xkcd.com/1205/"&gt;&lt;img alt="" src="https://imgs.xkcd.com/comics/is_it_worth_the_time.png" /&gt;&lt;/a&gt;
&lt;/div&gt;
&lt;p&gt;It turns out it&amp;#8217;s pretty easy to do, there are two nice system utilities on Linux that you can easily glue together by writing a bash&amp;nbsp;script.&lt;/p&gt;
&lt;div class="section" id="inotifywait"&gt;
&lt;h2&gt;inotifywait&lt;/h2&gt;
&lt;p&gt;inotifywait is a command-line utility that uses the &lt;a class="reference external" href="http://linux.die.net/man/7/inotify"&gt;inotify&lt;/a&gt; Linux kernel &lt;span class="caps"&gt;API&lt;/span&gt; which provides a mechanism for monitoring filesystem events. The &lt;span class="caps"&gt;API&lt;/span&gt; can be used to monitor individual files, or to monitor&amp;nbsp;directories.&lt;/p&gt;
&lt;p&gt;When a directory is monitored, inotify  will  return  events  for  the  directory itself, and for files inside the directory. Events are fired, for example, for file and directory creation, deletion, access, modification, etc (for a full list, read the&amp;nbsp;manual).&lt;/p&gt;
&lt;p&gt;inotifywait, as the name suggests, will listen and wait for an event returning a code if the events for which we are listening to are&amp;nbsp;triggered.&lt;/p&gt;
&lt;/div&gt;
&lt;div class="section" id="xdotool"&gt;
&lt;h2&gt;xdotool&lt;/h2&gt;
&lt;p&gt;xdotool is a command-line utility that lets you automate keyboard input and mouse activity, move and resize windows, etc. It basically lets you control your &lt;span class="caps"&gt;GUI&lt;/span&gt;&amp;nbsp;application.&lt;/p&gt;
&lt;p&gt;TuxRadar has a really nice &lt;a class="reference external" href="http://tuxradar.com/content/xdotool-script-your-mouse"&gt;tutorial&lt;/a&gt; about it if you want to find out&amp;nbsp;more.&lt;/p&gt;
&lt;/div&gt;
&lt;div class="section" id="tying-it-all-together"&gt;
&lt;h2&gt;Tying it all&amp;nbsp;together&lt;/h2&gt;
&lt;p&gt;Ubuntu doesn&amp;#8217;t come with inotifywait and xdotool installed by default, but you can install them using&amp;nbsp;apt:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;table class="codehilitetable"&gt;&lt;tr&gt;&lt;td class="linenos"&gt;&lt;div class="linenodiv"&gt;&lt;pre&gt;&lt;span class="normal"&gt;1&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class="code"&gt;&lt;div&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="go"&gt;apt-get install -y inotify-tools xdotool&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;
&lt;p&gt;Now for the bash&amp;nbsp;script.&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;table class="codehilitetable"&gt;&lt;tr&gt;&lt;td class="linenos"&gt;&lt;div class="linenodiv"&gt;&lt;pre&gt;&lt;span class="normal"&gt; 1&lt;/span&gt;
&lt;span class="normal"&gt; 2&lt;/span&gt;
&lt;span class="normal"&gt; 3&lt;/span&gt;
&lt;span class="normal"&gt; 4&lt;/span&gt;
&lt;span class="normal"&gt; 5&lt;/span&gt;
&lt;span class="normal"&gt; 6&lt;/span&gt;
&lt;span class="normal"&gt; 7&lt;/span&gt;
&lt;span class="normal"&gt; 8&lt;/span&gt;
&lt;span class="normal"&gt; 9&lt;/span&gt;
&lt;span class="normal"&gt;10&lt;/span&gt;
&lt;span class="normal"&gt;11&lt;/span&gt;
&lt;span class="normal"&gt;12&lt;/span&gt;
&lt;span class="normal"&gt;13&lt;/span&gt;
&lt;span class="normal"&gt;14&lt;/span&gt;
&lt;span class="normal"&gt;15&lt;/span&gt;
&lt;span class="normal"&gt;16&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class="code"&gt;&lt;div&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="ch"&gt;#!/bin/bash&lt;/span&gt;
&lt;span class="c1"&gt;#&lt;/span&gt;
&lt;span class="c1"&gt;# Watches the folder or files passed as arguments to the script and when it&lt;/span&gt;
&lt;span class="c1"&gt;# detects a change it automatically refreshes the current selected Chrome tab or&lt;/span&gt;
&lt;span class="c1"&gt;# window.&lt;/span&gt;
&lt;span class="c1"&gt;#&lt;/span&gt;
&lt;span class="c1"&gt;# Usage:&lt;/span&gt;
&lt;span class="c1"&gt;# ./chrome-refresh.sh /folder/to/watch /some/folder/file_to_watch.html&lt;/span&gt;

&lt;span class="nv"&gt;TIME_FORMAT&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;%F %H:%M&amp;#39;&lt;/span&gt;
&lt;span class="nv"&gt;OUTPUT_FORMAT&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;%T Event(s): %e fired for file: %w. Refreshing.&amp;#39;&lt;/span&gt;

&lt;span class="k"&gt;while&lt;/span&gt; inotifywait -q -r --timefmt &lt;span class="s2"&gt;&amp;quot;&lt;/span&gt;&lt;span class="si"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;TIME_FORMAT&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;&lt;/span&gt; --format &lt;span class="s2"&gt;&amp;quot;&lt;/span&gt;&lt;span class="si"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;OUTPUT_FORMAT&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;&lt;/span&gt;&lt;span class="nv"&gt;$@&lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
    &lt;span class="nv"&gt;CHROME_WINDOW_ID&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="k"&gt;$(&lt;/span&gt;xdotool search --onlyvisible --class google-chrome &lt;span class="p"&gt;|&lt;/span&gt; head -1&lt;span class="k"&gt;)&lt;/span&gt;
    xdotool key --window &lt;span class="nv"&gt;$CHROME_WINDOW_ID&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;CTRL+r&amp;#39;&lt;/span&gt;
&lt;span class="k"&gt;done&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;
&lt;p&gt;It waits for an event, when detected it will search for the current Google Chrome window or tab and send the refresh key shortcut (&lt;span class="caps"&gt;CTRL&lt;/span&gt;+r) to it then loop again in the listening&amp;nbsp;state.&lt;/p&gt;
&lt;p&gt;I&amp;#8217;ve also made a &lt;a class="reference external" href="https://gist.github.com/razius/8503625"&gt;gist&lt;/a&gt; for easy reference. I&amp;#8217;ll probably update that more when I&amp;#8217;ll want to add new&amp;nbsp;features.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: Yes, I know about LiveReload but I find it way to complicated for my needs and it&amp;#8217;s also not available on Linux (my &lt;span class="caps"&gt;OS&lt;/span&gt; of choice). Plus, in the process I learned something new and I will definitely be using that knowledge in the&amp;nbsp;future.&lt;/p&gt;
&lt;/div&gt;
</content><category term="tech"></category><category term="automation"></category><category term="chrome"></category><category term="bash"></category></entry><entry><title>Ditching Wordpress and becoming one of the cool kids</title><link href="https://razius.com/articles/ditching-wordpress-and-becoming-one-of-the-cool-kids.html" rel="alternate"></link><published>2013-12-21T10:58:00+01:00</published><updated>2013-12-21T10:58:00+01:00</updated><author><name>Silviu Tantos</name></author><id>tag:razius.com,2013-12-21:/articles/ditching-wordpress-and-becoming-one-of-the-cool-kids.html</id><summary type="html">&lt;p&gt;I&amp;#8217;ve been a Wordpress user and developer for a long long time but lately this nagging idea kept crawling in the back of my head, why not switch my website to a statically generated one? Well, a 3 hour train journey and a lot of boredom finally pushed me …&lt;/p&gt;</summary><content type="html">&lt;p&gt;I&amp;#8217;ve been a Wordpress user and developer for a long long time but lately this nagging idea kept crawling in the back of my head, why not switch my website to a statically generated one? Well, a 3 hour train journey and a lot of boredom finally pushed me to just make the switch and to write a short post about&amp;nbsp;it.&lt;/p&gt;
&lt;div class="section" id="what-is-a-statically-generated-website"&gt;
&lt;h2&gt;What is a statically generated&amp;nbsp;website?&lt;/h2&gt;
&lt;p&gt;Compared to dynamic web pages, where the web page is rendered by server-side logic and usually require a database, with statically generated websites you feed files written in a markup language like Markdown, reStructuredText, Textile, etc. to a static site generator which spits them out as a static website that is ready for&amp;nbsp;deployment.&lt;/p&gt;
&lt;p&gt;They are useful when the content doesn&amp;#8217;t vary based on parameters provided by a user, like in the case of a personal web page where the content is delivered to the user exactly as it was&amp;nbsp;stored.&lt;/p&gt;
&lt;/div&gt;
&lt;div class="section" id="why-bother-switching"&gt;
&lt;h2&gt;Why bother&amp;nbsp;switching?&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;reStructuredText&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;I could write my articles as simple flat files using the &lt;a class="reference external" href="http://docutils.sourceforge.net/docs/user/rst/quickref.html"&gt;reStructuredText&lt;/a&gt; format, goodbye storing of articles in a database. Having the articles as simple text files would allow me to easily edit them using my editor of choice, sublime text, so no more editing of text in a form on a web page, copy/pasting code snippets in it and painfully adjusting the indentation. Just take a look at &lt;a class="reference external" href="https://raw.github.com/razius/razius.com/71c85959d5b0cd1bb9ef14109cfa25446aa829f2/content/articles/tech/ditching-wordpress-and-becoming-one-of-the-cool-kids.rst"&gt;the source&lt;/a&gt; of this article and see how easy it is to embed different code snippets, it feels just like editing a source file. I would also have syntax highlighting powered by the excellent &lt;a class="reference external" href="http://pygments.org/"&gt;pygments&lt;/a&gt; syntax&amp;nbsp;highlighter.&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;table class="codehilitetable"&gt;&lt;tr&gt;&lt;td class="linenos"&gt;&lt;div class="linenodiv"&gt;&lt;pre&gt;&lt;span class="normal"&gt;1&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class="code"&gt;&lt;div&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="nb"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;Hello, World!&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;
&lt;div class="codehilite"&gt;&lt;table class="codehilitetable"&gt;&lt;tr&gt;&lt;td class="linenos"&gt;&lt;div class="linenodiv"&gt;&lt;pre&gt;&lt;span class="normal"&gt;1&lt;/span&gt;
&lt;span class="normal"&gt;2&lt;/span&gt;
&lt;span class="normal"&gt;3&lt;/span&gt;
&lt;span class="normal"&gt;4&lt;/span&gt;
&lt;span class="normal"&gt;5&lt;/span&gt;
&lt;span class="normal"&gt;6&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class="code"&gt;&lt;div&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="cp"&gt;#include&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="cpf"&gt;&amp;lt;stdio.h&amp;gt;&lt;/span&gt;&lt;span class="cp"&gt;&lt;/span&gt;

&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;void&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;printf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;Hello, world!&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;&lt;span class="w"&gt;&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="w"&gt;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;
&lt;div class="codehilite"&gt;&lt;table class="codehilitetable"&gt;&lt;tr&gt;&lt;td class="linenos"&gt;&lt;div class="linenodiv"&gt;&lt;pre&gt;&lt;span class="normal"&gt;1&lt;/span&gt;
&lt;span class="normal"&gt;2&lt;/span&gt;
&lt;span class="normal"&gt;3&lt;/span&gt;
&lt;span class="normal"&gt;4&lt;/span&gt;
&lt;span class="normal"&gt;5&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class="code"&gt;&lt;div&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="kd"&gt;public&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;HelloWorld&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="kd"&gt;public&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kd"&gt;static&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kt"&gt;void&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;String&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;&lt;/span&gt;
&lt;span class="w"&gt;        &lt;/span&gt;&lt;span class="n"&gt;System&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="na"&gt;out&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="na"&gt;println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;Hello, world!&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;&lt;span class="w"&gt;&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;
&lt;div class="codehilite"&gt;&lt;table class="codehilitetable"&gt;&lt;tr&gt;&lt;td class="linenos"&gt;&lt;div class="linenodiv"&gt;&lt;pre&gt;&lt;span class="normal"&gt;1&lt;/span&gt;
&lt;span class="normal"&gt;2&lt;/span&gt;
&lt;span class="normal"&gt;3&lt;/span&gt;
&lt;span class="normal"&gt;4&lt;/span&gt;
&lt;span class="normal"&gt;5&lt;/span&gt;
&lt;span class="normal"&gt;6&lt;/span&gt;
&lt;span class="normal"&gt;7&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class="code"&gt;&lt;div&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="kn"&gt;package&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;main&lt;/span&gt;&lt;span class="w"&gt;&lt;/span&gt;

&lt;span class="kn"&gt;import&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;&amp;quot;fmt&amp;quot;&lt;/span&gt;&lt;span class="w"&gt;&lt;/span&gt;

&lt;span class="kd"&gt;func&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="nx"&gt;fmt&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;Println&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;Hello, world!&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;
&lt;p&gt;Plus, having the articles as flat files would allow me to keep the entire website in a git repository really&amp;nbsp;easy.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Faster page&amp;nbsp;loads&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Because there is no need to build the web page each time upon serving it, page load would be faster. I made a test of a page load before and after the&amp;nbsp;switch.&lt;/p&gt;
&lt;div class="figure align-center"&gt;
&lt;img alt="Page load speed for Wordpress" src="https://razius.com/images/articles/wordpress-page-speed.png" /&gt;
&lt;p class="caption"&gt;Page load speed for&amp;nbsp;Wordpress&lt;/p&gt;
&lt;/div&gt;
&lt;div class="figure align-center"&gt;
&lt;img alt="Page load speed for static website" src="https://razius.com/images/articles/static-page-speed.png" /&gt;
&lt;p class="caption"&gt;Page load speed for static&amp;nbsp;website&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;Not bad, a whole second. Yes, it&amp;#8217;s not really a fair comparison, I also changed the theme to a much simpler one which is a big boost too, but&amp;nbsp;still.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Github&amp;nbsp;pages&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;I could host my page for free using &lt;a class="reference external" href="http://pages.github.com/"&gt;Github pages&lt;/a&gt;, which is a free hosting for static pages offered by Github, using git repositories for file storing. No, I&amp;#8217;m not killing the little curious sysadmin in me, it&amp;#8217;s just that for my humble page administration is starting to feel like a&amp;nbsp;hassle.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;The geek&amp;nbsp;factor&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;In the end, why not? I keep this website to toy around with it and this would allow me to play around more with Python, Jinja2 and reStructuredText plus I could test a new flow for writing&amp;nbsp;articles.&lt;/p&gt;
&lt;/div&gt;
&lt;div class="section" id="making-the-switch"&gt;
&lt;h2&gt;Making the&amp;nbsp;switch&lt;/h2&gt;
&lt;p&gt;I picked &lt;a class="reference external" href="http://blog.getpelican.com/"&gt;Pelican&lt;/a&gt; over the two most popular static web site generators, &lt;a class="reference external" href="http://jekyllrb.com/"&gt;Jekyll&lt;/a&gt; and &lt;a class="reference external" href="http://octopress.org/"&gt;Octopress&lt;/a&gt; because being a python developer, and Pelican being python based, it would feel a bit more natural than Jekyll or Octopress which are Ruby&amp;nbsp;based.&lt;/p&gt;
&lt;p&gt;If you think something else would suit you more, you can take a look at a complete list of static website generators at &lt;a class="reference external" href="http://staticsitegenerators.net/"&gt;staticsitegenerators.net&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Installing Pelican, it&amp;#8217;s as simple as&amp;nbsp;running:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;table class="codehilitetable"&gt;&lt;tr&gt;&lt;td class="linenos"&gt;&lt;div class="linenodiv"&gt;&lt;pre&gt;&lt;span class="normal"&gt;1&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class="code"&gt;&lt;div&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="gp"&gt;$ &lt;/span&gt;pip install pelican
&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;
&lt;p&gt;Next, kickstart a new project. Do do this run &lt;tt class="docutils literal"&gt;&lt;span class="pre"&gt;pelican-quickstart&lt;/span&gt;&lt;/tt&gt;, it will ask us a few questions about you site to generate a config file named &lt;tt class="docutils literal"&gt;pelicanconf.py&lt;/tt&gt; and create a project skeleton with some helper scripts&amp;nbsp;inside.&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;table class="codehilitetable"&gt;&lt;tr&gt;&lt;td class="linenos"&gt;&lt;div class="linenodiv"&gt;&lt;pre&gt;&lt;span class="normal"&gt;1&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class="code"&gt;&lt;div&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="gp"&gt;$ &lt;/span&gt;pelican-quickstart
&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;
&lt;p&gt;You can edit you &lt;tt class="docutils literal"&gt;pelicanconf.py&lt;/tt&gt; to further tune your configuration, take a look at the &lt;a class="reference external" href="http://docs.getpelican.com/en/3.3.0/settings.html"&gt;manual&lt;/a&gt; for the available options or you can check out &lt;a class="reference external" href="https://github.com/razius/razius.com/blob/master/pelicanconf.py"&gt;my pelicanconf.py&lt;/a&gt; for some&amp;nbsp;inspiration.&lt;/p&gt;
&lt;p&gt;All the content goes into the &lt;a class="reference external" href="https://github.com/razius/razius.com/blob/09dfd41f842d9b3b1a514816fa550423fc9b35e4/pelicanconf.py#L37"&gt;content&lt;/a&gt; folder and I like to keep all my &lt;a class="reference external" href="https://github.com/razius/razius.com/blob/09dfd41f842d9b3b1a514816fa550423fc9b35e4/pelicanconf.py#L39"&gt;articles&lt;/a&gt; and &lt;a class="reference external" href="https://github.com/razius/razius.com/blob/09dfd41f842d9b3b1a514816fa550423fc9b35e4/pelicanconf.py#L38"&gt;posts&lt;/a&gt; in separate folders by setting the following in &lt;tt class="docutils literal"&gt;pelicanconf.py&lt;/tt&gt;:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;table class="codehilitetable"&gt;&lt;tr&gt;&lt;td class="linenos"&gt;&lt;div class="linenodiv"&gt;&lt;pre&gt;&lt;span class="normal"&gt;1&lt;/span&gt;
&lt;span class="normal"&gt;2&lt;/span&gt;
&lt;span class="normal"&gt;3&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class="code"&gt;&lt;div&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="n"&gt;PATH&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;content&amp;#39;&lt;/span&gt;
&lt;span class="n"&gt;PAGE_DIR&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;pages&amp;#39;&lt;/span&gt;
&lt;span class="n"&gt;ARTICLE_DIR&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;articles&amp;#39;&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;
&lt;p&gt;You can export your articles from Wordpress into an &lt;span class="caps"&gt;XML&lt;/span&gt; file by going to Tool -&amp;gt; Export and then run &lt;tt class="docutils literal"&gt;&lt;span class="pre"&gt;pelican-import&lt;/span&gt;&lt;/tt&gt; to generate the appropriate text files into the &lt;tt class="docutils literal"&gt;content&lt;/tt&gt; folder.&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;table class="codehilitetable"&gt;&lt;tr&gt;&lt;td class="linenos"&gt;&lt;div class="linenodiv"&gt;&lt;pre&gt;&lt;span class="normal"&gt;1&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class="code"&gt;&lt;div&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="gp"&gt;$ &lt;/span&gt;pelican-import --wpfile -o content/ wordpress-export.xml
&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;
&lt;p&gt;You can preview your files by running &lt;tt class="docutils literal"&gt;make devserver&lt;/tt&gt;, this will start a webserver that serves your build html files under &lt;tt class="docutils literal"&gt;&lt;span class="pre"&gt;http://localhost:8000/&lt;/span&gt;&lt;/tt&gt; and a process that watches the &lt;tt class="docutils literal"&gt;content&lt;/tt&gt; folder for file changes and rebuilds the served html&amp;nbsp;files.&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;table class="codehilitetable"&gt;&lt;tr&gt;&lt;td class="linenos"&gt;&lt;div class="linenodiv"&gt;&lt;pre&gt;&lt;span class="normal"&gt;1&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class="code"&gt;&lt;div&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="go"&gt;make devserver&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div class="section" id="hosting-on-github"&gt;
&lt;h2&gt;Hosting on&amp;nbsp;Github&lt;/h2&gt;
&lt;p&gt;Instead of using Github pages, where you are required to have your html pages under the project root and because pelican puts them under the output folder, I chose to use project pages. With project pages you keep the html files in a separate git branch called &lt;tt class="docutils literal"&gt;&lt;span class="pre"&gt;gh-pages&lt;/span&gt;&lt;/tt&gt; and Github will publish those pages for you under &lt;tt class="docutils literal"&gt;GITHUB_USERNAME.github.com/GITHUB_PROJECTNAME.&lt;/tt&gt; from that branch. Ex. my web address would be &lt;tt class="docutils literal"&gt;&lt;span class="pre"&gt;http://razius.github.com/razius.com&lt;/span&gt;&lt;/tt&gt;, don&amp;#8217;t worry, you can use your custom domain&amp;nbsp;too.&lt;/p&gt;
&lt;p&gt;Notice the difference between the &lt;a class="reference external" href="https://github.com/razius/razius.com/tree/master"&gt;master&lt;/a&gt; branch and the &lt;a class="reference external" href="https://github.com/razius/razius.com/tree/gh-pages"&gt;gh-pages&lt;/a&gt;&amp;nbsp;branch.&lt;/p&gt;
&lt;p&gt;Luckily, you don&amp;#8217;t have to maintain this branch manually, there&amp;#8217;s a script called &lt;tt class="docutils literal"&gt;&lt;span class="pre"&gt;ghp-import&lt;/span&gt;&lt;/tt&gt; which will manage it for you. It copies a directory to the &lt;tt class="docutils literal"&gt;&lt;span class="pre"&gt;gh-pages&lt;/span&gt;&lt;/tt&gt; branch, that is the site&amp;#8217;s document&amp;nbsp;root.&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;table class="codehilitetable"&gt;&lt;tr&gt;&lt;td class="linenos"&gt;&lt;div class="linenodiv"&gt;&lt;pre&gt;&lt;span class="normal"&gt;1&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class="code"&gt;&lt;div&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="go"&gt;pip install ghp-import&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;
&lt;p&gt;Now with &lt;tt class="docutils literal"&gt;&lt;span class="pre"&gt;ghp-import&lt;/span&gt;&lt;/tt&gt; installed you can publish your project pages by simply running &lt;tt class="docutils literal"&gt;make github&lt;/tt&gt; command which will build the html pages for publishing under the &lt;tt class="docutils literal"&gt;output/&lt;/tt&gt; folder, call &lt;tt class="docutils literal"&gt;&lt;span class="pre"&gt;ghp-import&lt;/span&gt;&lt;/tt&gt; to copy the files under that folder to the &lt;tt class="docutils literal"&gt;&lt;span class="pre"&gt;gh-pages&lt;/span&gt;&lt;/tt&gt; branch and do a &lt;tt class="docutils literal"&gt;git push&lt;/tt&gt; to push the new changes to&amp;nbsp;Github.&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;table class="codehilitetable"&gt;&lt;tr&gt;&lt;td class="linenos"&gt;&lt;div class="linenodiv"&gt;&lt;pre&gt;&lt;span class="normal"&gt;1&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class="code"&gt;&lt;div&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="go"&gt;make github&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;
&lt;p&gt;You can also use your own &lt;a class="reference external" href="https://help.github.com/articles/setting-up-a-custom-domain-with-pages"&gt;custom domain&lt;/a&gt;, I keep my &lt;tt class="docutils literal"&gt;&lt;span class="caps"&gt;CNAME&lt;/span&gt;&lt;/tt&gt; file in a static folder called &lt;tt class="docutils literal"&gt;files&lt;/tt&gt; and I&amp;#8217;ve added the file&amp;#8217;s path to &lt;a class="reference external" href="https://github.com/razius/razius.com/blob/master/pelicanconf.py#L43"&gt;EXTRA_PATH_METADATA&lt;/a&gt; in &lt;tt class="docutils literal"&gt;pelicanconf.py&lt;/tt&gt; so that pelican copies it each time on&amp;nbsp;build.&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;table class="codehilitetable"&gt;&lt;tr&gt;&lt;td class="linenos"&gt;&lt;div class="linenodiv"&gt;&lt;pre&gt;&lt;span class="normal"&gt;1&lt;/span&gt;
&lt;span class="normal"&gt;2&lt;/span&gt;
&lt;span class="normal"&gt;3&lt;/span&gt;
&lt;span class="normal"&gt;4&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class="code"&gt;&lt;div&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="n"&gt;STATIC_PATHS&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;files&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="n"&gt;EXTRA_PATH_METADATA&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="s1"&gt;&amp;#39;files/CNAME&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;path&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;CNAME&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;
&lt;p&gt;&lt;em&gt;&lt;span class="caps"&gt;PS&lt;/span&gt;: Yes, the title is a bit&amp;nbsp;ironic.&lt;/em&gt;&lt;/p&gt;
&lt;/div&gt;
</content><category term="tech"></category><category term="wordpress"></category><category term="static"></category><category term="pygments"></category><category term="python"></category><category term="restructured text"></category></entry><entry><title>Building a messaging framework for Django</title><link href="https://razius.com/articles/building-a-messaging-framework-for-django.html" rel="alternate"></link><published>2013-11-17T20:58:00+01:00</published><updated>2013-11-17T20:58:00+01:00</updated><author><name>Silviu Tantos</name></author><id>tag:razius.com,2013-11-17:/articles/building-a-messaging-framework-for-django.html</id><summary type="html">&lt;p&gt;As you might have noticed, one of the key usability features that we were missing on Iconfinder was the ability to display so called &amp;#8220;flash messages.&amp;#8221; Flash messages are one-time notification messages shown to the user after processing a form or handling other types of user input, so the user …&lt;/p&gt;</summary><content type="html">&lt;p&gt;As you might have noticed, one of the key usability features that we were missing on Iconfinder was the ability to display so called &amp;#8220;flash messages.&amp;#8221; Flash messages are one-time notification messages shown to the user after processing a form or handling other types of user input, so the user knows if things went as expected. Changing your password without being told &lt;em&gt;Your password was updated.&lt;/em&gt; can be a little confusing, so it was long overdue that we did something about something that&amp;nbsp;obvious.&lt;/p&gt;
&lt;div class="figure align-center"&gt;
&lt;img alt="messages" src="https://razius.com/images/articles/flash-messages.png" /&gt;
&lt;p class="caption"&gt;Example of flash&amp;nbsp;messages.&lt;/p&gt;
&lt;/div&gt;
&lt;p class="italic"&gt;Note: This is a cross-post of &lt;a class="reference external" href="http://blog.iconfinder.com/building-a-messaging-framework-for-django/"&gt;an article&lt;/a&gt; that I originally wrote on my company&amp;#8217;s blog a while&amp;nbsp;back.&lt;/p&gt;
&lt;div class="section" id="context-is-king"&gt;
&lt;h2&gt;Context is&amp;nbsp;king&lt;/h2&gt;
&lt;p&gt;Most popular web frameworks already feature an easy drop-in way of showing these flash messages. Iconfinder is a heavy Django shop, and of course Django comes with its own &lt;a class="reference external" href="https://docs.djangoproject.com/en/dev/ref/contrib/messages/"&gt;messaging framework&lt;/a&gt; built in for just this purpose. But, like most other drop-in solutions, it rarely fits the bill of a larger&amp;nbsp;site.&lt;/p&gt;
&lt;p&gt;The built in messaging framework has a problem in that it&amp;#8217;s not contextually bound - in other words, it&amp;#8217;s not associated with any one form or page. This means, that messages from a specific form could under odd circumstances be shown in the completely wrong place, which is arguably more confusing than not being shown any message at&amp;nbsp;all.&lt;/p&gt;
&lt;p&gt;Furthermore, this also means that we can&amp;#8217;t create &amp;#8220;out of band&amp;#8221; messages to be shown from asynchronous jobs, such as when we&amp;#8217;re processing icon data, as that would just show up somewhere where the user might not expect it. What was left for us to do then, was to roll our own solution that would make it possible for us to do all the things we&amp;nbsp;wanted.&lt;/p&gt;
&lt;p&gt;Now, &lt;em&gt;contextual&lt;/em&gt; is a pretty ambiguous term (which is why academics love using it) so we of course had to pick something more &amp;#8220;tangible.&amp;#8221; Django sites basically contain a bunch of views, which have the responsibility of displaying a specific kind of page, so as a starting place, we decided to bind messages to a specific view. As each user is also identified by a session, it made sense to start out with these two things defining the&amp;nbsp;context.&lt;/p&gt;
&lt;/div&gt;
&lt;div class="section" id="transient-messages-in-redis"&gt;
&lt;h2&gt;Transient messages in&amp;nbsp;Redis&lt;/h2&gt;
&lt;p&gt;Given the contextual nature of the messages, it is very likely that a user might have more than just one message waiting for him - especially if he or she is doing a lot of stuff at once. Therefore, the standard solution of using cookies to store the messages made no sense, as it would mean that a lot of pointless data was sent over the wire all the time. So, we have to store the data somewhere. Our primary PostgreSQL database is the first option, that comes to mind, but given that messages are shown once, that would mean that we&amp;#8217;d be inserting and deleting a lot of data - something a relational database is usually not made for. Luckily, there are options out there that are basically made for this kind of workload, like for example our favorite key-value store, &lt;a class="reference external" href="http://redis.io/"&gt;Redis&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Redis is essentially in-memory, but we do snapshots every minute and run a master/slave pair to make sure we don&amp;#8217;t loose too much data in case of failure, but the loss of a couple of messages won&amp;#8217;t be the end of the world, which makes it the perfect tool for the&amp;nbsp;job.&lt;/p&gt;
&lt;p&gt;The beauty of Redis is, that we can get away with a simple key structure: the base key is the application name, followed by the session key and finally by a view identifier. This makes insertion and retrieval of values very easy. The keys are also set to expire after a default period of inactivity, just to make sure we don&amp;#8217;t have any orphaned messages lying around a week after you&amp;#8217;ve changed your&amp;nbsp;password.&lt;/p&gt;
&lt;p&gt;&lt;tt class="docutils literal"&gt;&lt;span class="pre"&gt;messages:user-session-key:view-identifier&lt;/span&gt;&lt;/tt&gt;&lt;/p&gt;
&lt;p&gt;When a new message needs to be shown, we simply serialize it along with a bit of meta data and store it in a &lt;a class="reference external" href="http://redis.io/topics/data-types"&gt;sorted set&lt;/a&gt; with the message&amp;#8217;s timestamp as a score. This way the messages can be easily sorted by time or be purged using a garbage collection scheme if we run out of&amp;nbsp;space.&lt;/p&gt;
&lt;/div&gt;
&lt;div class="section" id="the-exposed-api"&gt;
&lt;h2&gt;The exposed &lt;span class="caps"&gt;API&lt;/span&gt;&lt;/h2&gt;
&lt;p&gt;One of the keys to keeping a large code base maintainable is to expose functionality through a stable, consistent &lt;span class="caps"&gt;API&lt;/span&gt;. The contextual messaging system adheres to this principle by exposing to simle methods: one to
add a message and the other one to retrieve all the messages for a session in a view. If you&amp;#8217;re a Pythonista, the following should look familiar to&amp;nbsp;you:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;table class="codehilitetable"&gt;&lt;tr&gt;&lt;td class="linenos"&gt;&lt;div class="linenodiv"&gt;&lt;pre&gt;&lt;span class="normal"&gt; 1&lt;/span&gt;
&lt;span class="normal"&gt; 2&lt;/span&gt;
&lt;span class="normal"&gt; 3&lt;/span&gt;
&lt;span class="normal"&gt; 4&lt;/span&gt;
&lt;span class="normal"&gt; 5&lt;/span&gt;
&lt;span class="normal"&gt; 6&lt;/span&gt;
&lt;span class="normal"&gt; 7&lt;/span&gt;
&lt;span class="normal"&gt; 8&lt;/span&gt;
&lt;span class="normal"&gt; 9&lt;/span&gt;
&lt;span class="normal"&gt;10&lt;/span&gt;
&lt;span class="normal"&gt;11&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class="code"&gt;&lt;div&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="nn"&gt;messaging.models&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Message&lt;/span&gt;

&lt;span class="n"&gt;Message&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;session_key&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;current-users-session-key&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="n"&gt;text&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;This *is* the message you are looking for.&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="n"&gt;title&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;Hello&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="n"&gt;status&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;Message&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;INFO&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="n"&gt;autoclose&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;True&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="n"&gt;view&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;my_view&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;messages&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;Message&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;session_key&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;current-users-session-key&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                       &lt;span class="n"&gt;view&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;my_view&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div class="section" id="a-perfect-case-for-a-mixin"&gt;
&lt;h2&gt;A perfect case for a&amp;nbsp;mixin&lt;/h2&gt;
&lt;p&gt;Django provides &lt;a class="reference external" href="https://docs.djangoproject.com/en/dev/topics/class-based-views/"&gt;class based views&lt;/a&gt; which makes it easy to structure views and expose common functionality by harnessing inheritance and mixins. Because in most of the cases we would need to add and retrieve messages for the current view, to make it even easier we created a mixin that would provide some abstracted functionality to our view classes. The retrieval of messages for the current view is handled by the mixin so messages are ready to be consumed in the templates without having to call &lt;tt class="docutils literal"&gt;Message.get()&lt;/tt&gt; in each&amp;nbsp;view.&lt;/p&gt;
&lt;p&gt;Adding a message is also a lot easier as we can figure out the view name and session from the&amp;nbsp;view:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;table class="codehilitetable"&gt;&lt;tr&gt;&lt;td class="linenos"&gt;&lt;div class="linenodiv"&gt;&lt;pre&gt;&lt;span class="normal"&gt;1&lt;/span&gt;
&lt;span class="normal"&gt;2&lt;/span&gt;
&lt;span class="normal"&gt;3&lt;/span&gt;
&lt;span class="normal"&gt;4&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class="code"&gt;&lt;div&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;DashboardView&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;MessageViewMixin&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;TemplateView&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;form_valid&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="bp"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;form&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="bp"&gt;self&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;add_message&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;text&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;Your settings have been changed successfully.&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                         &lt;span class="n"&gt;status&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;Message&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;SUCCESS&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;
&lt;p&gt;Doesn&amp;#8217;t get much easier than that,&amp;nbsp;huh?&lt;/p&gt;
&lt;/div&gt;
&lt;div class="section" id="don-t-be-afraid-to-write-code"&gt;
&lt;h2&gt;Don&amp;#8217;t be afraid to write&amp;nbsp;code&lt;/h2&gt;
&lt;p&gt;If there is a functionality built into the framework that you need but it doesn&amp;#8217;t fit you use case, don&amp;#8217;t be afraid to write your own solution. In most cases you only need a minimum viable product that fits your needs really well rather than a full fledged library that can send a rocket to the&amp;nbsp;moon.&lt;/p&gt;
&lt;/div&gt;
</content><category term="tech"></category><category term="django"></category><category term="iconfinder"></category><category term="messaging"></category><category term="redis"></category></entry><entry><title>Launching services after Vagrant mount</title><link href="https://razius.com/articles/launching-services-after-vagrant-mount.html" rel="alternate"></link><published>2013-11-10T14:40:00+01:00</published><updated>2013-11-10T14:40:00+01:00</updated><author><name>Silviu Tantos</name></author><id>tag:razius.com,2013-11-10:/articles/launching-services-after-vagrant-mount.html</id><summary type="html">&lt;p&gt;I recently had to set up a Vagrant project where all the configuration files for services like nginx, supervisor, mysql where symlinks pointing to files residing on the &lt;a class="reference external" href="http://docs.vagrantup.com/v2/synced-folders/index.html"&gt;Vagrant synced folder&lt;/a&gt;. This turned out to be
a bit of a problem, when the Vagrant box boots, one of the last …&lt;/p&gt;</summary><content type="html">&lt;p&gt;I recently had to set up a Vagrant project where all the configuration files for services like nginx, supervisor, mysql where symlinks pointing to files residing on the &lt;a class="reference external" href="http://docs.vagrantup.com/v2/synced-folders/index.html"&gt;Vagrant synced folder&lt;/a&gt;. This turned out to be
a bit of a problem, when the Vagrant box boots, one of the last things it does is mount the synced folder, so those services would fail to start because of missing configuration&amp;nbsp;files.&lt;/p&gt;
&lt;p&gt;To fix the problem you need to ensure that all services are started after Vagrant had the chance to mount the synced /vagrant/ folder and to do this there are a couple of ways depending on the type of init script that the service&amp;nbsp;has.&lt;/p&gt;
&lt;div class="section" id="upstart"&gt;
&lt;h2&gt;Upstart&lt;/h2&gt;
&lt;p&gt;There is an &lt;a class="reference external" href="http://upstart.ubuntu.com/cookbook/#event"&gt;upstart event&lt;/a&gt; that Vagrant emits each time it mounts a synced folder that is called &lt;em&gt;vagrant-mounted&lt;/em&gt; so we can modify the upstart configuration file for services that depend on the Vagrant synced folder to listen and start after the &lt;em&gt;vagrant-mounted&lt;/em&gt; &lt;a class="reference external" href="https://github.com/mitchellh/vagrant/blob/7897de3fbdc4c61a281954ec2df1c23bfe22f4d4/plugins/guests/ubuntu/cap/mount_nfs.rb#L13"&gt;event is emitted&lt;/a&gt;.&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;table class="codehilitetable"&gt;&lt;tr&gt;&lt;td class="linenos"&gt;&lt;div class="linenodiv"&gt;&lt;pre&gt;&lt;span class="normal"&gt; 1&lt;/span&gt;
&lt;span class="normal"&gt; 2&lt;/span&gt;
&lt;span class="normal"&gt; 3&lt;/span&gt;
&lt;span class="normal"&gt; 4&lt;/span&gt;
&lt;span class="normal"&gt; 5&lt;/span&gt;
&lt;span class="normal"&gt; 6&lt;/span&gt;
&lt;span class="normal"&gt; 7&lt;/span&gt;
&lt;span class="normal"&gt; 8&lt;/span&gt;
&lt;span class="normal"&gt; 9&lt;/span&gt;
&lt;span class="normal"&gt;10&lt;/span&gt;
&lt;span class="normal"&gt;11&lt;/span&gt;
&lt;span class="normal"&gt;12&lt;/span&gt;
&lt;span class="normal"&gt;13&lt;/span&gt;
&lt;span class="normal"&gt;14&lt;/span&gt;
&lt;span class="normal"&gt;15&lt;/span&gt;
&lt;span class="normal"&gt;16&lt;/span&gt;
&lt;span class="normal"&gt;17&lt;/span&gt;
&lt;span class="normal"&gt;18&lt;/span&gt;
&lt;span class="normal"&gt;19&lt;/span&gt;
&lt;span class="normal"&gt;20&lt;/span&gt;
&lt;span class="normal"&gt;21&lt;/span&gt;
&lt;span class="normal"&gt;22&lt;/span&gt;
&lt;span class="normal"&gt;23&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class="code"&gt;&lt;div&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="c1"&gt;# nginx&lt;/span&gt;
description &lt;span class="s2"&gt;&amp;quot;nginx http daemon&amp;quot;&lt;/span&gt;
author &lt;span class="s2"&gt;&amp;quot;Silviu Tantos &amp;quot;&lt;/span&gt;

&lt;span class="c1"&gt;# Listen and start after the vagrant-mounted event&lt;/span&gt;
start on vagrant-mounted
stop on runlevel &lt;span class="o"&gt;[&lt;/span&gt;!2345&lt;span class="o"&gt;]&lt;/span&gt;

env &lt;span class="nv"&gt;DAEMON&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;/usr/sbin/nginx
env &lt;span class="nv"&gt;PID&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;/var/run/nginx.pid

expect fork
respawn
respawn limit &lt;span class="m"&gt;10&lt;/span&gt; &lt;span class="m"&gt;5&lt;/span&gt;

pre-start script
        &lt;span class="nv"&gt;$DAEMON&lt;/span&gt; -t
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt; &lt;span class="nv"&gt;$?&lt;/span&gt; -ne &lt;span class="m"&gt;0&lt;/span&gt; &lt;span class="o"&gt;]&lt;/span&gt;
                &lt;span class="k"&gt;then&lt;/span&gt; &lt;span class="nb"&gt;exit&lt;/span&gt; &lt;span class="nv"&gt;$?&lt;/span&gt;
        &lt;span class="k"&gt;fi&lt;/span&gt;
end script

&lt;span class="nb"&gt;exec&lt;/span&gt; &lt;span class="nv"&gt;$DAEMON&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div class="section" id="system-v"&gt;
&lt;h2&gt;System-V&lt;/h2&gt;
&lt;p&gt;If you are not running Ubuntu as the guest &lt;span class="caps"&gt;OS&lt;/span&gt; or you don&amp;#8217;t want to convert your init script to upstart, there&amp;#8217;s still hope, albeit a bit more complicated. Underneath Vagrant uses VirtualBox&amp;#8217;s shared folder for it&amp;#8217;s synced folder so we can hook-up to udev events and trigger a script execution after the VirtualBox mount event has fired, this of course will also works for VirtualBox&amp;#8217;s shared folder not just for Vagrant&amp;#8217;s synced&amp;nbsp;folders.&lt;/p&gt;
&lt;div class="section" id="finding-out-the-udev-event"&gt;
&lt;h3&gt;Finding out the udev&amp;nbsp;event&lt;/h3&gt;
&lt;p&gt;This step is not needed as I already wrote the udev rule, it&amp;#8217;s just to show how I came up with it. If you&amp;#8217;re not interested in it just skip to writing the udev&amp;nbsp;rule.&lt;/p&gt;
&lt;p&gt;Fire up a terminal and listen to udev&amp;nbsp;events:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;table class="codehilitetable"&gt;&lt;tr&gt;&lt;td class="linenos"&gt;&lt;div class="linenodiv"&gt;&lt;pre&gt;&lt;span class="normal"&gt;1&lt;/span&gt;
&lt;span class="normal"&gt;2&lt;/span&gt;
&lt;span class="normal"&gt;3&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class="code"&gt;&lt;div&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;root@vagrant:~# udevadm monitor --property --kernel
monitor will print the received events &lt;span class="k"&gt;for&lt;/span&gt;:
KERNEL - the kernel uevent
&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;
&lt;p&gt;Fire up another terminal and trigger a&amp;nbsp;mount:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;table class="codehilitetable"&gt;&lt;tr&gt;&lt;td class="linenos"&gt;&lt;div class="linenodiv"&gt;&lt;pre&gt;&lt;span class="normal"&gt;1&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class="code"&gt;&lt;div&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;root@vagrant:~# mount -t vboxsf -o &lt;span class="nv"&gt;uid&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sb"&gt;`&lt;/span&gt;id -u vagrant&lt;span class="sb"&gt;`&lt;/span&gt;,gid&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sb"&gt;`&lt;/span&gt;id -g vagrant&lt;span class="sb"&gt;`&lt;/span&gt; /vagrant /vagrant
&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;
&lt;p&gt;Now we should see the event in the first terminal&amp;nbsp;window:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;table class="codehilitetable"&gt;&lt;tr&gt;&lt;td class="linenos"&gt;&lt;div class="linenodiv"&gt;&lt;pre&gt;&lt;span class="normal"&gt; 1&lt;/span&gt;
&lt;span class="normal"&gt; 2&lt;/span&gt;
&lt;span class="normal"&gt; 3&lt;/span&gt;
&lt;span class="normal"&gt; 4&lt;/span&gt;
&lt;span class="normal"&gt; 5&lt;/span&gt;
&lt;span class="normal"&gt; 6&lt;/span&gt;
&lt;span class="normal"&gt; 7&lt;/span&gt;
&lt;span class="normal"&gt; 8&lt;/span&gt;
&lt;span class="normal"&gt; 9&lt;/span&gt;
&lt;span class="normal"&gt;10&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class="code"&gt;&lt;div&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;root@vagrant:~# udevadm monitor --property --kernel
monitor will print the received events &lt;span class="k"&gt;for&lt;/span&gt;:
KERNEL - the kernel uevent

KERNEL&lt;span class="o"&gt;[&lt;/span&gt;&lt;span class="m"&gt;4234&lt;/span&gt;.545610&lt;span class="o"&gt;]&lt;/span&gt; add      /devices/virtual/bdi/vboxsf-13 &lt;span class="o"&gt;(&lt;/span&gt;bdi&lt;span class="o"&gt;)&lt;/span&gt;
&lt;span class="nv"&gt;ACTION&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;add
&lt;span class="nv"&gt;DEVPATH&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;/devices/virtual/bdi/vboxsf-13
&lt;span class="nv"&gt;SEQNUM&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="m"&gt;1407&lt;/span&gt;
&lt;span class="nv"&gt;SUBSYSTEM&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;bdi
&lt;span class="nv"&gt;UDEV_LOG&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="m"&gt;3&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div class="section" id="writing-the-udev-rule"&gt;
&lt;h3&gt;Writing the udev&amp;nbsp;rule&lt;/h3&gt;
&lt;p&gt;We can see that the subsystem is &lt;em&gt;bdi&lt;/em&gt; and the action is &lt;em&gt;add&lt;/em&gt; so we can write a &lt;a class="reference external" href="http://hackaday.com/2009/09/18/how-to-write-udev-rules/"&gt;udev rule&lt;/a&gt; for the event. I use &lt;tt class="docutils literal"&gt;&lt;span class="pre"&gt;/etc/udev/rules.d/50-vagrant-mount.rules&lt;/span&gt;&lt;/tt&gt; as the file name and&amp;nbsp;path.&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;table class="codehilitetable"&gt;&lt;tr&gt;&lt;td class="linenos"&gt;&lt;div class="linenodiv"&gt;&lt;pre&gt;&lt;span class="normal"&gt;1&lt;/span&gt;
&lt;span class="normal"&gt;2&lt;/span&gt;
&lt;span class="normal"&gt;3&lt;/span&gt;
&lt;span class="normal"&gt;4&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class="code"&gt;&lt;div&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="c1"&gt;# Start on mount&lt;/span&gt;
&lt;span class="nv"&gt;SUBSYSTEM&lt;/span&gt;&lt;span class="o"&gt;==&lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;bdi&amp;quot;&lt;/span&gt;,ACTION&lt;span class="o"&gt;==&lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;add&amp;quot;&lt;/span&gt;,RUN+&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;/usr/bin/screen -m -d bash -c &amp;#39;sleep 5; /etc/init.d/nginx start&amp;#39;&amp;quot;&lt;/span&gt;
&lt;span class="c1"&gt;# Stop on unmount&lt;/span&gt;
&lt;span class="nv"&gt;SUBSYSTEM&lt;/span&gt;&lt;span class="o"&gt;==&lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;bdi&amp;quot;&lt;/span&gt;,ACTION&lt;span class="o"&gt;==&lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;remove&amp;quot;&lt;/span&gt;,RUN+&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;/usr/bin/screen -m -d bash -c &amp;#39;sleep 5; /etc/init.d/nginx stop&amp;#39;&amp;quot;&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;
&lt;p&gt;This will run each time a VirtualBox shared folder is mounted. It spawns a screen session (of course you need to have the &lt;a class="reference external" href="https://wiki.archlinux.org/index.php/GNU_Screen"&gt;screen&lt;/a&gt; package installed) to prevent the command from being killed by systemd when parent udev exits, sleeps for 5 seconds to make sure Vagrant had the chance to mount the synced folder and exits successfully and finally start the&amp;nbsp;service.&lt;/p&gt;
&lt;p&gt;Don&amp;#8217;t forget to type in the full paths otherwise udev won&amp;#8217;t be able to find the command. For more information consult the &lt;a class="reference external" href="http://www.freedesktop.org/software/systemd/man/udev.html#RUN%7Btype%7D"&gt;udev manual&lt;/a&gt;.&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
</content><category term="tech"></category><category term="init"></category><category term="upstart"></category><category term="vagrant"></category><category term="virtualbox"></category></entry><entry><title>Move fast and break things</title><link href="https://razius.com/articles/move-fast-and-break-things.html" rel="alternate"></link><published>2013-10-14T19:14:00+02:00</published><updated>2013-10-14T19:14:00+02:00</updated><author><name>Silviu Tantos</name></author><id>tag:razius.com,2013-10-14:/articles/move-fast-and-break-things.html</id><summary type="html">&lt;p&gt;&lt;em&gt;Move fast and break things&lt;/em&gt; is one of the &lt;a class="reference external" href="http://www.youtube.com/watch?v=LPSbtqGiol4"&gt;founding mantras&lt;/a&gt; of Facebook and I think it defines a company culture that can apply to almost any technology startup. It is a culture who&amp;#8217;s principles embody, promote and encourage communication, constant and fast iterations, tight feedback loop between the …&lt;/p&gt;</summary><content type="html">&lt;p&gt;&lt;em&gt;Move fast and break things&lt;/em&gt; is one of the &lt;a class="reference external" href="http://www.youtube.com/watch?v=LPSbtqGiol4"&gt;founding mantras&lt;/a&gt; of Facebook and I think it defines a company culture that can apply to almost any technology startup. It is a culture who&amp;#8217;s principles embody, promote and encourage communication, constant and fast iterations, tight feedback loop between the implementation and the design, short code-to-deployment cycles, experimentation and&amp;nbsp;efficiency.&lt;/p&gt;
&lt;p&gt;These are also just a few of the reasons why I chose to be a part of the &lt;a class="reference external" href="https://www.iconfinder.com/"&gt;Iconfinder&lt;/a&gt; team and to do my internship at a startup company instead
of a traditional one. I have the perfect environment for rapid professional growth, I can acquire new skills and sharpen my old ones at a much faster pace, I feel challenged everyday and I have the pleasure of working with the newest&amp;nbsp;technologies.&lt;/p&gt;
&lt;p&gt;In this &lt;em&gt;move fast and break things&lt;/em&gt; culture the &lt;em&gt;break things&lt;/em&gt;, as I&amp;#8217;ve come to find out, is not optional. To continue to improve you have to make mistakes from which you have to learn and my recent blunder is one of those mistakes. During the development of the new comment section a &lt;a class="reference external" href="http://blog.iconfinder.com/cookie-hijacking/"&gt;serious bug&lt;/a&gt; slipped through making it possible for attackers to hijack cookies from users. The bug was discovered and fixed under 2 hours and didn&amp;#8217;t have any major repercussions apart from the inconvenience of clearing the session storage and having all users log in&amp;nbsp;again.&lt;/p&gt;
&lt;p&gt;I&amp;#8217;ve learned a lot this month, some lessons where learned the hard way, from mistakes, but it&amp;#8217;s been a fun ride so far and I can&amp;#8217;t wait to see what the future will&amp;nbsp;bring.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Some geeky&amp;nbsp;statistics:&lt;/strong&gt;&lt;/p&gt;
&lt;ul class="simple"&gt;
&lt;li&gt;Git commits:&amp;nbsp;101&lt;/li&gt;
&lt;li&gt;Git code line additions: 4.674&amp;nbsp;++&lt;/li&gt;
&lt;li&gt;Git code line deletions: 1.430&amp;nbsp;&amp;#8212;&lt;/li&gt;
&lt;li&gt;Coffee cups consumed:&amp;nbsp;82&lt;/li&gt;
&lt;li&gt;Number of times I caused chaos:&amp;nbsp;1&lt;/li&gt;
&lt;li&gt;Minutes wishing I was somewhere else:&amp;nbsp;0.5&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Some of tasks accomplished so&amp;nbsp;far:&lt;/strong&gt;&lt;/p&gt;
&lt;ul class="simple"&gt;
&lt;li&gt;Created &lt;a class="reference external" href="http://razius.com/2013/09/vagrant-and-ssh-agent-forwarding/"&gt;Vagrant machine&lt;/a&gt; to use for local&amp;nbsp;development.&lt;/li&gt;
&lt;li&gt;Implemented a PayPal cash out&amp;nbsp;option.&lt;/li&gt;
&lt;li&gt;Designed and implemented a new &lt;a class="reference external" href="https://www.iconfinder.com/iconsets/20-flat-icons"&gt;comment section&lt;/a&gt;, replacing&amp;nbsp;Disqus.&lt;/li&gt;
&lt;li&gt;Created a Python script to generate a &lt;a class="reference external" href="https://support.google.com/webmasters/answer/178636?hl=en"&gt;image sitemap&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Integrated internal notifications into &lt;a class="reference external" href="https://www.hipchat.com/"&gt;Hipchat&lt;/a&gt;, our internal
communication&amp;nbsp;application.&lt;/li&gt;
&lt;li&gt;Did various &lt;span class="caps"&gt;CSS&lt;/span&gt; and Javascript&amp;nbsp;fixes.&lt;/li&gt;
&lt;/ul&gt;
</content><category term="toughts"></category><category term="iconfinder"></category><category term="internship"></category><category term="personal"></category></entry><entry><title>Getting the IP address of a specific interface in puppet using facter</title><link href="https://razius.com/articles/getting-the-ip-address-of-a-specific-interface-in-puppet-using-facter.html" rel="alternate"></link><published>2013-10-06T22:13:00+02:00</published><updated>2013-10-06T22:13:00+02:00</updated><author><name>Silviu Tantos</name></author><id>tag:razius.com,2013-10-06:/articles/getting-the-ip-address-of-a-specific-interface-in-puppet-using-facter.html</id><summary type="html">&lt;p&gt;One of the problems that I find annoying in puppet is that you can&amp;#8217;t easily obtain the &lt;span class="caps"&gt;IP&lt;/span&gt; address of a specific network&amp;nbsp;interface.&lt;/p&gt;
&lt;p&gt;Let&amp;#8217;s say that you want to define a class or type to which you wish to pass a interface name and use it&amp;#8217;s …&lt;/p&gt;</summary><content type="html">&lt;p&gt;One of the problems that I find annoying in puppet is that you can&amp;#8217;t easily obtain the &lt;span class="caps"&gt;IP&lt;/span&gt; address of a specific network&amp;nbsp;interface.&lt;/p&gt;
&lt;p&gt;Let&amp;#8217;s say that you want to define a class or type to which you wish to pass a interface name and use it&amp;#8217;s &lt;span class="caps"&gt;IP&lt;/span&gt; address as a&amp;nbsp;variable.&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;table class="codehilitetable"&gt;&lt;tr&gt;&lt;td class="linenos"&gt;&lt;div class="linenodiv"&gt;&lt;pre&gt;&lt;span class="normal"&gt;1&lt;/span&gt;
&lt;span class="normal"&gt;2&lt;/span&gt;
&lt;span class="normal"&gt;3&lt;/span&gt;
&lt;span class="normal"&gt;4&lt;/span&gt;
&lt;span class="normal"&gt;5&lt;/span&gt;
&lt;span class="normal"&gt;6&lt;/span&gt;
&lt;span class="normal"&gt;7&lt;/span&gt;
&lt;span class="normal"&gt;8&lt;/span&gt;
&lt;span class="normal"&gt;9&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class="code"&gt;&lt;div&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="n"&gt;dns&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="vg"&gt;$interface&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="vg"&gt;$address&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt; &lt;span class="n"&gt;insert&lt;/span&gt; &lt;span class="n"&gt;magic&lt;/span&gt; &lt;span class="n"&gt;here&lt;/span&gt; &lt;span class="o"&gt;]&lt;/span&gt;

    &lt;span class="vg"&gt;$message&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;So you want to know the IP address for ${interface} huh?&amp;quot;&lt;/span&gt;
    &lt;span class="vg"&gt;$message&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;Well, it&amp;#39;s ${address}&amp;quot;&lt;/span&gt;
    &lt;span class="n"&gt;notify&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;  &lt;span class="s2"&gt;&amp;quot;${message}&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;dns&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;interface&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;eth0&amp;#39;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;
&lt;p&gt;We could use facters &lt;tt class="docutils literal"&gt;&lt;span class="pre"&gt;$::ipaddress&lt;/span&gt;&lt;/tt&gt;, but what happens if the network interface is not our main network interface? What if we want to use more than one network interface? There&amp;#8217;s &lt;tt class="docutils literal"&gt;&lt;span class="pre"&gt;$::ipaddress_eth0&lt;/span&gt;&lt;/tt&gt;, but how do we construct or reference a variable in a dynamic way (construct a variable based on another variable)&amp;nbsp;?&lt;/p&gt;
&lt;p&gt;Luckily there&amp;#8217;s a nifty trick involving inline templates and&amp;nbsp;lookupvar:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;table class="codehilitetable"&gt;&lt;tr&gt;&lt;td class="linenos"&gt;&lt;div class="linenodiv"&gt;&lt;pre&gt;&lt;span class="normal"&gt;1&lt;/span&gt;
&lt;span class="normal"&gt;2&lt;/span&gt;
&lt;span class="normal"&gt;3&lt;/span&gt;
&lt;span class="normal"&gt;4&lt;/span&gt;
&lt;span class="normal"&gt;5&lt;/span&gt;
&lt;span class="normal"&gt;6&lt;/span&gt;
&lt;span class="normal"&gt;7&lt;/span&gt;
&lt;span class="normal"&gt;8&lt;/span&gt;
&lt;span class="normal"&gt;9&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class="code"&gt;&lt;div&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="n"&gt;dns&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="vg"&gt;$interface&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="vg"&gt;$address&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;inline_template&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;&amp;lt;%= scope.lookupvar(&amp;#39;::ipaddress_${interface}&amp;#39;) -%&amp;gt;&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="vg"&gt;$message&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;So you want to know the IP address for ${interface} huh?&amp;quot;&lt;/span&gt;
    &lt;span class="vg"&gt;$message&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;Well, it&amp;#39;s ${address}&amp;quot;&lt;/span&gt;
    &lt;span class="n"&gt;notify&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;  &lt;span class="s2"&gt;&amp;quot;${message}&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;dns&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;interface&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;eth0&amp;#39;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;
</content><category term="tech"></category><category term="facter"></category><category term="puppet"></category></entry><entry><title>Vagrant and SSH agent forwarding</title><link href="https://razius.com/articles/vagrant-and-ssh-agent-forwarding.html" rel="alternate"></link><published>2013-09-13T08:29:00+02:00</published><updated>2013-09-13T08:29:00+02:00</updated><author><name>Silviu Tantos</name></author><id>tag:razius.com,2013-09-13:/articles/vagrant-and-ssh-agent-forwarding.html</id><summary type="html">&lt;p&gt;I haven&amp;#8217;t even started yet and I can already hear you muttering over there, &amp;#8220;What the hell is this Vagrant thing and why should I care?&amp;#8221;. Well, &lt;a class="reference external" href="http://www.vagrantup.com/"&gt;Vagrant&lt;/a&gt; is a wrapper around &lt;a class="reference external" href="https://www.virtualbox.org/"&gt;VirtualBox&lt;/a&gt;, the virtualization
software, that can create homogeneous development environments automatically without any effort from the developer …&lt;/p&gt;</summary><content type="html">&lt;p&gt;I haven&amp;#8217;t even started yet and I can already hear you muttering over there, &amp;#8220;What the hell is this Vagrant thing and why should I care?&amp;#8221;. Well, &lt;a class="reference external" href="http://www.vagrantup.com/"&gt;Vagrant&lt;/a&gt; is a wrapper around &lt;a class="reference external" href="https://www.virtualbox.org/"&gt;VirtualBox&lt;/a&gt;, the virtualization
software, that can create homogeneous development environments automatically without any effort from the developer. This means that we have a consistent development environment across out team with the same &lt;span class="caps"&gt;OS&lt;/span&gt; version, same package versions, same database, same settings. No more &lt;em&gt;But it worked on &lt;span class="caps"&gt;MY&lt;/span&gt; machine&lt;/em&gt;&amp;nbsp;excuses.&lt;/p&gt;
&lt;p&gt;Lets say that inside this virtual machine you need to use your &lt;span class="caps"&gt;SSH&lt;/span&gt; key, maybe the key for your &lt;a class="reference external" href="https://github.com/"&gt;Github&lt;/a&gt; account to access your private or public git repositories or maybe the key to connect to a remote server.
That can be a problem, you don&amp;#8217;t want to distribute your &lt;span class="caps"&gt;SSH&lt;/span&gt; keys with the Vagrant box. Each &lt;span class="caps"&gt;SSH&lt;/span&gt; key should be tied to an individual developer
account so to prevent &lt;span class="caps"&gt;SSH&lt;/span&gt; key sharing you would need to either distribute each &lt;span class="caps"&gt;SSH&lt;/span&gt; key with a new Vagrant box or copy it during provisioning. That&amp;#8217;s not really homogeneous, you will end up with a Vagrant box for each developer or an inconvenient way of providing the &lt;span class="caps"&gt;SSH&lt;/span&gt; key depending on the developer&amp;#8217;s &lt;span class="caps"&gt;OS&lt;/span&gt;.&lt;/p&gt;
&lt;p&gt;Enter &lt;a class="reference external" href="https://help.github.com/articles/using-ssh-agent-forwarding"&gt;&lt;span class="caps"&gt;SSH&lt;/span&gt; agent forwarding&lt;/a&gt;. With &lt;span class="caps"&gt;SSH&lt;/span&gt; agent forwarding we can use the &lt;span class="caps"&gt;SSH&lt;/span&gt; key from our local machine inside the Vagrant&amp;nbsp;box.&lt;/p&gt;
&lt;p&gt;To enable agent forwarding for all ssh connections inside your Vagrant box you need to set the following in your Vagrant file inside the config section (Vagrant.configure(VAGRANTFILE_API_VERSION) do&amp;nbsp;|config|):&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;table class="codehilitetable"&gt;&lt;tr&gt;&lt;td class="linenos"&gt;&lt;div class="linenodiv"&gt;&lt;pre&gt;&lt;span class="normal"&gt;1&lt;/span&gt;
&lt;span class="normal"&gt;2&lt;/span&gt;
&lt;span class="normal"&gt;3&lt;/span&gt;
&lt;span class="normal"&gt;4&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class="code"&gt;&lt;div&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;...&lt;span class="o"&gt;]&lt;/span&gt;
    config.ssh.private_key_path &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;~/.ssh/id_rsa&amp;quot;&lt;/span&gt;
    config.ssh.forward_agent &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;true&lt;/span&gt;
&lt;span class="o"&gt;[&lt;/span&gt;...&lt;span class="o"&gt;]&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;
&lt;p&gt;Due to a Vagrant bug &lt;span class="caps"&gt;SSH&lt;/span&gt; Agent Forwarding not available during provisioning (&lt;a class="reference external" href="https://github.com/mitchellh/vagrant/issues/1303"&gt;see issue&lt;/a&gt;), to work around that we need to create a file in &lt;tt class="docutils literal"&gt;/etc/sudoers.d/&lt;/tt&gt; with the following&amp;nbsp;contents:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;table class="codehilitetable"&gt;&lt;tr&gt;&lt;td class="linenos"&gt;&lt;div class="linenodiv"&gt;&lt;pre&gt;&lt;span class="normal"&gt;1&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class="code"&gt;&lt;div&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;Defaults &lt;span class="nv"&gt;env_keep&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;SSH_AUTH_SOCK&amp;quot;&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;
&lt;p&gt;To create it automatically during provisioning we can add the following to our Vagrant&amp;nbsp;file:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;table class="codehilitetable"&gt;&lt;tr&gt;&lt;td class="linenos"&gt;&lt;div class="linenodiv"&gt;&lt;pre&gt;&lt;span class="normal"&gt;1&lt;/span&gt;
&lt;span class="normal"&gt;2&lt;/span&gt;
&lt;span class="normal"&gt;3&lt;/span&gt;
&lt;span class="normal"&gt;4&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class="code"&gt;&lt;div&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;vm&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;provision&lt;/span&gt; &lt;span class="ss"&gt;:shell&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="n"&gt;shell&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;
    &lt;span class="n"&gt;shell&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;inline&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;touch $1 &amp;amp;&amp;amp; chmod 0440 $1 &amp;amp;&amp;amp; echo $2 &amp;gt; $1&amp;quot;&lt;/span&gt;
    &lt;span class="n"&gt;shell&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;args&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sx"&gt;%q{/etc/sudoers.d/root_ssh_agent &amp;quot;Defaults env_keep += \&amp;quot;SSH_AUTH_SOCK\&amp;quot;&amp;quot;}&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;
&lt;p&gt;or in the shell script that you&amp;#8217;re using for&amp;nbsp;provisioning:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;table class="codehilitetable"&gt;&lt;tr&gt;&lt;td class="linenos"&gt;&lt;div class="linenodiv"&gt;&lt;pre&gt;&lt;span class="normal"&gt;1&lt;/span&gt;
&lt;span class="normal"&gt;2&lt;/span&gt;
&lt;span class="normal"&gt;3&lt;/span&gt;
&lt;span class="normal"&gt;4&lt;/span&gt;
&lt;span class="normal"&gt;5&lt;/span&gt;
&lt;span class="normal"&gt;6&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class="code"&gt;&lt;div&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="nv"&gt;SSH_FIX_FILE&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;/etc/sudoers.d/root_ssh_agent&amp;quot;&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt; ! -f  &lt;span class="nv"&gt;$SSH_FIX_FILE&lt;/span&gt; &lt;span class="o"&gt;]&lt;/span&gt;
    &lt;span class="k"&gt;then&lt;/span&gt;
    &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;Defaults env_keep += \&amp;quot;SSH_AUTH_SOCK\&amp;quot;&amp;quot;&lt;/span&gt; &amp;gt; &lt;span class="nv"&gt;$SSH_FIX_FILE&lt;/span&gt;
    chmod &lt;span class="m"&gt;0440&lt;/span&gt; &lt;span class="nv"&gt;$SSH_FIX_FILE&lt;/span&gt;
&lt;span class="k"&gt;fi&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;
</content><category term="tech"></category><category term="provisioning"></category><category term="ssh"></category><category term="vagrant"></category></entry><entry><title>Copenhagen and my r’bad_luck’</title><link href="https://razius.com/articles/copenhagen-and-my-rbad_luck.html" rel="alternate"></link><published>2013-09-08T11:46:00+02:00</published><updated>2013-09-08T11:46:00+02:00</updated><author><name>Silviu Tantos</name></author><id>tag:razius.com,2013-09-08:/articles/copenhagen-and-my-rbad_luck.html</id><summary type="html">&lt;p&gt;To tell you the story of my string of bad luck and my first week of
internship in Copenhagen, I&amp;#8217;ll first have to start with my last week. It
was Saturday, the day before I had to leave for Copenhagen, I was there
minding my own business, when my …&lt;/p&gt;</summary><content type="html">&lt;p&gt;To tell you the story of my string of bad luck and my first week of
internship in Copenhagen, I&amp;#8217;ll first have to start with my last week. It
was Saturday, the day before I had to leave for Copenhagen, I was there
minding my own business, when my laptop suddenly decided that he is
thirsty. Now, my laptop being a laptop and having no hands, couldn&amp;#8217;t
achieve this feat by&amp;nbsp;itself.&lt;/p&gt;
&lt;p&gt;Enter me and my clumsy hands. In my infinite star gazing mode, I knock
down a glass of water down on my laptop, helping him quenching his
thirst and in the same time helping him commit&amp;nbsp;suicide.&lt;/p&gt;
&lt;p&gt;Enter me in panic mode. There I was on a Saturday evening without a
laptop and I would have to start work on Monday. Luckily I managed to
borrow an older laptop from somebody I know but only on Sunday evening,
leaving me with little time to swap it&amp;#8217;s hard-drive with the hard-drive
from my old laptop and to try to boot my old Linux installation from it.
If I managed to get it to boot it I would at least have all my files and
could work properly. But the laptop that I borrowed, being as stubborn
as a wild stallion being caught and trained, decided to all of a sudden
defy me and refuse to boot my Linux installation&amp;nbsp;properly.&lt;/p&gt;
&lt;p&gt;After a couple of hours of intense training I tamed him and manage to
boot my Linux installation successfully. I was finally presented with a
beautiful login screen with my name on&amp;nbsp;it.&lt;/p&gt;
&lt;p&gt;Fast forward Friday evening. The end of my first internship week. After
an office party I head down to Copenhagen Central Station at around 2 &lt;span class="caps"&gt;AM&lt;/span&gt;
to take the train back to Horsens to sleep at a friend for the weekend
and to take my things back to Copenhagen. Having still a couple of hours
till the train arrives I sit on a bench and put my backpack in between
my legs. After a couple of minutes I start to doze off. Upon waking up I
realize that my backpack with all my things is gone, somebody stole it
in the meantime. I had my laptop with all my data, phone, id, credit
card and my ticket back to Horsens in&amp;nbsp;it.&lt;/p&gt;
&lt;p&gt;Now, at this point, I have to mention that I also didn&amp;#8217;t have a place to
stay in Copenhagen. When leaving for Copenhagen I didn&amp;#8217;t find anything
to rent so I just lived in a hostel for the past 5 days with the plan of
returning to Horsens for the weekend. I packed just enough clothes for
the week and my intention was to go back to Horsens for the weekend and
return on Sunday when the apartment that I finally manage to rent would
be&amp;nbsp;available.&lt;/p&gt;
&lt;p&gt;So exit scene for now, it&amp;#8217;s Friday night (&lt;span class="caps"&gt;3AM&lt;/span&gt;), I&amp;#8217;m standing in the
middle of Copenhagen Central Station, with my hands on top of my head,
philosophizing on universe&amp;#8217;s strange idea of humor. I am without a place
to stay, without a way to contact somebody, without knowing anybody or
anyplace and without a way to at least get back to Horsens. Everything I
have on me are a couple of beer&amp;nbsp;caps.&lt;/p&gt;
</content><category term="toughts"></category><category term="copenhagen"></category><category term="personal"></category></entry><entry><title>About stuff</title><link href="https://razius.com/articles/about-stuff.html" rel="alternate"></link><published>2013-07-31T19:53:00+02:00</published><updated>2013-07-31T19:53:00+02:00</updated><author><name>Silviu Tantos</name></author><id>tag:razius.com,2013-07-31:/articles/about-stuff.html</id><summary type="html">&lt;p&gt;I moved to Denmark, from my home country Romania, exactly two years ago to the day with just a small suitcase and a backpack. In them I had a hand-full of clothes, a few personal belongings and my&amp;nbsp;laptop.&lt;/p&gt;
&lt;p&gt;During the past couple of years things started to accumulate, I …&lt;/p&gt;</summary><content type="html">&lt;p&gt;I moved to Denmark, from my home country Romania, exactly two years ago to the day with just a small suitcase and a backpack. In them I had a hand-full of clothes, a few personal belongings and my&amp;nbsp;laptop.&lt;/p&gt;
&lt;p&gt;During the past couple of years things started to accumulate, I started buying new things, some out of necessity others because I wanted&amp;nbsp;them.&lt;/p&gt;
&lt;div class="figure"&gt;
&lt;img alt="My luggage when moving to Denmark" src="https://razius.com/images/articles/moving-to-denmark.jpg" /&gt;
&lt;p class="caption"&gt;My luggage when moving to Horsens,&amp;nbsp;Denmark&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;But fortunately because as a student I had limited space and resources I was forced in a certain mindset, making me think twice before buying something. For example when I needed something, I tried to buy the cheapest thing that would serve it&amp;#8217;s purpose, I bought a computer chair and a table for 5$, a bed for 50$ and a lamp for 2$. Being cheap, when moving out instead of taking them with me I could just leave them behind,less thing to move, less hassle and effort spent on moving them&amp;nbsp;out.&lt;/p&gt;
&lt;p&gt;Being accepted for an internship in Copenhagen and facing the possibility of living in a hostel for an undetermined period of time made me decide to see how much I could slim down my list of possessions again. My objective was simple, everything that I own should fit in my backpack and my travel bag (or less if&amp;nbsp;possible).&lt;/p&gt;
&lt;p&gt;What did I end up&amp;nbsp;with?&lt;/p&gt;
&lt;div class="figure"&gt;
&lt;img alt="My luggage when moving to Denmark" src="https://razius.com/images/articles/moving-to-copenhagen.jpg" /&gt;
&lt;p class="caption"&gt;Everything I currently&amp;nbsp;own&lt;/p&gt;
&lt;/div&gt;
&lt;ul class="simple"&gt;
&lt;li&gt;&lt;strong&gt;Clothes&lt;/strong&gt;, nothing spectacular&amp;nbsp;here.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Two pairs of shoes&lt;/strong&gt;, I&amp;#8217;ve always owned no more than 2-3 pair, never felt like I needed&amp;nbsp;more.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Thinkpad T500&lt;/strong&gt; laptop +&amp;nbsp;mouse.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Kindle&lt;/strong&gt; which I find incredibly useful, it allows me to carry tons of books around with little physical space requirements. I would love to own physical books, but it feels like they would be too much of a hassle right&amp;nbsp;now.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;External hard-drive&lt;/strong&gt; to back-up the data from my&amp;nbsp;laptop.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;span class="caps"&gt;HTC&lt;/span&gt; One S phone&lt;/strong&gt;, it also acts as my camera, alarm clock and whatever other uses I can think&amp;nbsp;of.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;iPod Touch&lt;/strong&gt;, I bought it to develop and test a iOS application. I&amp;#8217;m considering selling it and buying a proper &lt;span class="caps"&gt;MP3&lt;/span&gt;&amp;nbsp;player.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Longboard&lt;/strong&gt;, I&amp;#8217;ve bought this one last year and I consider it incredibly&amp;nbsp;fun.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Ogio backpack&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Not shown in the&amp;nbsp;picture:&lt;/p&gt;
&lt;ul class="simple"&gt;
&lt;li&gt;Charger and a docking station for the&amp;nbsp;laptop&lt;/li&gt;
&lt;li&gt;A pair of headphones,a usb cable for my phone/iPod/Kindle and one for my external&amp;nbsp;hard-drive&lt;/li&gt;
&lt;li&gt;A computer that I keep back home in Romania which is acting as an off-site back-up server for my files, every night the content of my laptop is saved on to it. In this way if anything happens to my laptop or the data on it, I would still have what&amp;#8217;s most important, my files and&amp;nbsp;data&lt;/li&gt;
&lt;li&gt;A shoe box filled with personal&amp;nbsp;memories.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Now I&amp;#8217;m gonna leave you with a great comedy sketch by George Carlin and an &lt;a class="reference external" href="http://storyofstuff.org/"&gt;awesome website&lt;/a&gt; on the&amp;nbsp;subject.&lt;/p&gt;
&lt;div class="youtube youtube-16x9"&gt;&lt;iframe src="https://www.youtube.com/embed/MvgN5gCuLac" allowfullscreen seamless frameBorder="0"&gt;&lt;/iframe&gt;&lt;/div&gt;</content><category term="toughts"></category><category term="personal"></category><category term="stuff"></category></entry><entry><title>Generating password hashes with puppet</title><link href="https://razius.com/articles/generating-password-hashes-for-puppet.html" rel="alternate"></link><published>2013-07-08T10:25:00+02:00</published><updated>2013-07-08T10:25:00+02:00</updated><author><name>Silviu Tantos</name></author><id>tag:razius.com,2013-07-08:/articles/generating-password-hashes-for-puppet.html</id><summary type="html">&lt;p&gt;Puppet expects the user’s password to be encrypted in the format the local system expects, for most modern Unix-like systems (Linux, *&lt;span class="caps"&gt;BSD&lt;/span&gt;, Solaris, etc.) this format is a salted &lt;span class="caps"&gt;SHA1&lt;/span&gt; password&amp;nbsp;hash.&lt;/p&gt;
&lt;p&gt;To generate a password hash to use with puppet manifest files you can use the mkpasswd utility …&lt;/p&gt;</summary><content type="html">&lt;p&gt;Puppet expects the user’s password to be encrypted in the format the local system expects, for most modern Unix-like systems (Linux, *&lt;span class="caps"&gt;BSD&lt;/span&gt;, Solaris, etc.) this format is a salted &lt;span class="caps"&gt;SHA1&lt;/span&gt; password&amp;nbsp;hash.&lt;/p&gt;
&lt;p&gt;To generate a password hash to use with puppet manifest files you can use the mkpasswd utility (it&amp;#8217;s available in the whois&amp;nbsp;package):&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;table class="codehilitetable"&gt;&lt;tr&gt;&lt;td class="linenos"&gt;&lt;div class="linenodiv"&gt;&lt;pre&gt;&lt;span class="normal"&gt;1&lt;/span&gt;
&lt;span class="normal"&gt;2&lt;/span&gt;
&lt;span class="normal"&gt;3&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class="code"&gt;&lt;div&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="gp"&gt;$ &lt;/span&gt;mkpasswd -m sha-512
&lt;span class="go"&gt;Password:&lt;/span&gt;
&lt;span class="gp"&gt;$&lt;/span&gt;&lt;span class="m"&gt;6&lt;/span&gt;&lt;span class="nv"&gt;$qfPDlAej83p$cj2nc1NjbKjhL42Mo&lt;/span&gt;/3Uia4NqD4dIB3ouVeI/tSG92UqH5cMKOA/ihjmxAuRtKHzGED0EHmdM0iNxa/662NW//
&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;
&lt;p&gt;You can then use the password hash in a puppet manifest&amp;nbsp;file:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;table class="codehilitetable"&gt;&lt;tr&gt;&lt;td class="linenos"&gt;&lt;div class="linenodiv"&gt;&lt;pre&gt;&lt;span class="normal"&gt;1&lt;/span&gt;
&lt;span class="normal"&gt;2&lt;/span&gt;
&lt;span class="normal"&gt;3&lt;/span&gt;
&lt;span class="normal"&gt;4&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class="code"&gt;&lt;div&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="n"&gt;user&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;root&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;ensure&lt;/span&gt;   &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;present&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;password&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;$6$qfPDlAej83p$cj2nc1NjbKjhL42Mo/3Uia4NqD4dIB3ouVeI/tSG92UqH5cMKOA/ihjmxAuRtKHzGED0EHmdM0iNxa/662NW//&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;
&lt;p&gt;Don&amp;#8217;t forget to put the password in quotes so that puppet does not interpret it as a variable if it contains the dollar sign&amp;nbsp;($).&lt;/p&gt;
&lt;p&gt;If you want the passwords to be stored in plain text in the puppet manifest you can use puppet&amp;#8217;s &lt;a class="reference external" href="http://docs.puppetlabs.com/references/latest/function.html#generate"&gt;generate&lt;/a&gt; function to call mkpassword and return the generated the hash version of the&amp;nbsp;password:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;table class="codehilitetable"&gt;&lt;tr&gt;&lt;td class="linenos"&gt;&lt;div class="linenodiv"&gt;&lt;pre&gt;&lt;span class="normal"&gt;1&lt;/span&gt;
&lt;span class="normal"&gt;2&lt;/span&gt;
&lt;span class="normal"&gt;3&lt;/span&gt;
&lt;span class="normal"&gt;4&lt;/span&gt;
&lt;span class="normal"&gt;5&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class="code"&gt;&lt;div&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="vg"&gt;$password&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;your_plain_text_password&amp;#39;&lt;/span&gt;
&lt;span class="n"&gt;user&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;root&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
    &lt;span class="k"&gt;ensure&lt;/span&gt;   &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;present&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;password&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;generate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;/bin/sh&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;-c&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;&amp;quot;mkpasswd -m sha-512 ${password} | tr -d &amp;#39;&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s2"&gt;&amp;#39;&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;
&lt;dl class="docutils"&gt;
&lt;dt&gt;References:&lt;/dt&gt;
&lt;dd&gt;&lt;ul class="first last simple"&gt;
&lt;li&gt;&lt;a class="reference external" href="http://docs.puppetlabs.com/references/latest/type.html#user"&gt;Puppet type&amp;nbsp;user&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a class="reference external" href="http://docs.puppetlabs.com/references/latest/function.html#sha1"&gt;Puppet sha1&amp;nbsp;function&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/dd&gt;
&lt;/dl&gt;
</content><category term="tech"></category><category term="password"></category><category term="puppet"></category><category term="shadow"></category></entry><entry><title>Testing print stylesheets using Google Chrome</title><link href="https://razius.com/articles/testing-print-stylesheets-using-google-chome.html" rel="alternate"></link><published>2013-05-14T21:46:00+02:00</published><updated>2013-05-14T21:46:00+02:00</updated><author><name>Silviu Tantos</name></author><id>tag:razius.com,2013-05-14:/articles/testing-print-stylesheets-using-google-chome.html</id><summary type="html">&lt;p&gt;Testing &lt;span class="caps"&gt;CSS&lt;/span&gt; print media queries is really difficult but &lt;a class="reference external" href="https://plus.google.com/+AddyOsmani/posts/MgpioU84JPe"&gt;a new featured&lt;/a&gt; was introduced in Google Chrome in December that allows you to apply different &lt;span class="caps"&gt;CSS&lt;/span&gt; media types like handheld, print, screen and so&amp;nbsp;on.&lt;/p&gt;
&lt;ol class="arabic simple"&gt;
&lt;li&gt;&lt;a class="reference external" href="https://developers.google.com/chrome-developer-tools/docs/shortcuts#opening-devtools"&gt;Open Developer Tools&lt;/a&gt; in Google Chrome by clicking the menu icon at the top-right of …&lt;/li&gt;&lt;/ol&gt;</summary><content type="html">&lt;p&gt;Testing &lt;span class="caps"&gt;CSS&lt;/span&gt; print media queries is really difficult but &lt;a class="reference external" href="https://plus.google.com/+AddyOsmani/posts/MgpioU84JPe"&gt;a new featured&lt;/a&gt; was introduced in Google Chrome in December that allows you to apply different &lt;span class="caps"&gt;CSS&lt;/span&gt; media types like handheld, print, screen and so&amp;nbsp;on.&lt;/p&gt;
&lt;ol class="arabic simple"&gt;
&lt;li&gt;&lt;a class="reference external" href="https://developers.google.com/chrome-developer-tools/docs/shortcuts#opening-devtools"&gt;Open Developer Tools&lt;/a&gt; in Google Chrome by clicking the menu icon at the top-right of your browser window, then select Tools → Developer&amp;nbsp;tools.&lt;/li&gt;
&lt;li&gt;Open up the Overrides menu in the Developer Tools by clicking the gear in the bottom right&amp;nbsp;corner:&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="figure align-center"&gt;
&lt;img alt="" src="https://razius.com/images/articles/dev-tools-settings.png" /&gt;
&lt;/div&gt;
&lt;ol class="arabic simple" start="3"&gt;
&lt;li&gt;Enable &amp;#8220;Emulate &lt;span class="caps"&gt;CSS&lt;/span&gt; media&amp;#8221; and select the &amp;#8220;print&amp;#8221; media type option from the drop-down&amp;nbsp;box:&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="figure align-center"&gt;
&lt;img alt="" src="https://razius.com/images/articles/emulate-css-print.png" /&gt;
&lt;/div&gt;
&lt;p&gt;You can find more information and nifty tricks in the &lt;a class="reference external" href="https://developers.google.com/chrome-developer-tools/docs/mobile-emulation"&gt;official documentation&lt;/a&gt;.&lt;/p&gt;
</content><category term="tech"></category></entry><entry><title>Programing the STK600 AVR board on Linux using C</title><link href="https://razius.com/articles/programing-the-stk600-avr-board-on-linux-using-c.html" rel="alternate"></link><published>2012-09-27T10:51:00+02:00</published><updated>2012-09-27T10:51:00+02:00</updated><author><name>Silviu Tantos</name></author><id>tag:razius.com,2012-09-27:/articles/programing-the-stk600-avr-board-on-linux-using-c.html</id><summary type="html">&lt;div class="section" id="setting-up-the-developing-enviroment"&gt;
&lt;h2&gt;Setting up the developing&amp;nbsp;enviroment&lt;/h2&gt;
&lt;p&gt;Note: I&amp;#8217;m assuming you have a .deb based distribution and a &lt;span class="caps"&gt;AVR&lt;/span&gt; &lt;span class="caps"&gt;STK600&lt;/span&gt; board with a ATmega2560 microcontroller that you are programming using an &lt;span class="caps"&gt;USB&lt;/span&gt;&amp;nbsp;cable.&lt;/p&gt;
&lt;div class="section" id="installing-the-software"&gt;
&lt;h3&gt;Installing the&amp;nbsp;software&lt;/h3&gt;
&lt;p&gt;We need to install the following programs and their&amp;nbsp;dependencies:&lt;/p&gt;
&lt;ul class="simple"&gt;
&lt;li&gt;gcc-avr: The &lt;span class="caps"&gt;GNU&lt;/span&gt; C compiler …&lt;/li&gt;&lt;/ul&gt;&lt;/div&gt;&lt;/div&gt;</summary><content type="html">&lt;div class="section" id="setting-up-the-developing-enviroment"&gt;
&lt;h2&gt;Setting up the developing&amp;nbsp;enviroment&lt;/h2&gt;
&lt;p&gt;Note: I&amp;#8217;m assuming you have a .deb based distribution and a &lt;span class="caps"&gt;AVR&lt;/span&gt; &lt;span class="caps"&gt;STK600&lt;/span&gt; board with a ATmega2560 microcontroller that you are programming using an &lt;span class="caps"&gt;USB&lt;/span&gt;&amp;nbsp;cable.&lt;/p&gt;
&lt;div class="section" id="installing-the-software"&gt;
&lt;h3&gt;Installing the&amp;nbsp;software&lt;/h3&gt;
&lt;p&gt;We need to install the following programs and their&amp;nbsp;dependencies:&lt;/p&gt;
&lt;ul class="simple"&gt;
&lt;li&gt;gcc-avr: The &lt;span class="caps"&gt;GNU&lt;/span&gt; C compiler (cross compiler for&amp;nbsp;avr)&lt;/li&gt;
&lt;li&gt;gdb-avr: The &lt;span class="caps"&gt;GNU&lt;/span&gt; Debugger for&amp;nbsp;avr&lt;/li&gt;
&lt;li&gt;avr-libc: Standard C library for Atmel &lt;span class="caps"&gt;AVR&lt;/span&gt;&amp;nbsp;development&lt;/li&gt;
&lt;li&gt;avrdude: Tool to download the compiled code and data to the Atmel &lt;span class="caps"&gt;AVR&lt;/span&gt;&amp;nbsp;microcontroller&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Install them by running the following&amp;nbsp;command:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;table class="codehilitetable"&gt;&lt;tr&gt;&lt;td class="linenos"&gt;&lt;div class="linenodiv"&gt;&lt;pre&gt;&lt;span class="normal"&gt;1&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class="code"&gt;&lt;div&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="gp"&gt;$ &lt;/span&gt;sudo apt-get install avrdude avrdude-doc gcc-avr binutils-avr avr-libc simulavr gdb-avr
&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div class="section" id="setting-up-the-permissions"&gt;
&lt;h3&gt;Setting up the&amp;nbsp;permissions&lt;/h3&gt;
&lt;p&gt;In order to download the firmware on the device as a regular user we need to setup some udev rules for device permissions otherwise we get the following&amp;nbsp;errors:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;table class="codehilitetable"&gt;&lt;tr&gt;&lt;td class="linenos"&gt;&lt;div class="linenodiv"&gt;&lt;pre&gt;&lt;span class="normal"&gt;1&lt;/span&gt;
&lt;span class="normal"&gt;2&lt;/span&gt;
&lt;span class="normal"&gt;3&lt;/span&gt;
&lt;span class="normal"&gt;4&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class="code"&gt;&lt;div&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;avrdude: usb_open(): cannot read serial number...
avrdude: usb_open(): cannot read product name...
avrdude: usbdev_open(): error setting configuration 1...
avrdude: usbdev_open(): did not find any USB device...
&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;
&lt;p&gt;Create a new file under &lt;tt class="docutils literal"&gt;/etc/udev/rules.d/&lt;/tt&gt; named &lt;tt class="docutils literal"&gt;&lt;span class="pre"&gt;41-atmega.rules&lt;/span&gt;&lt;/tt&gt; with the following&amp;nbsp;content:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;table class="codehilitetable"&gt;&lt;tr&gt;&lt;td class="linenos"&gt;&lt;div class="linenodiv"&gt;&lt;pre&gt;&lt;span class="normal"&gt;1&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class="code"&gt;&lt;div&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="nv"&gt;SUBSYSTEM&lt;/span&gt;&lt;span class="o"&gt;==&lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;usb&amp;quot;&lt;/span&gt;, ATTR&lt;span class="o"&gt;{&lt;/span&gt;idVendor&lt;span class="o"&gt;}==&lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;03eb&amp;quot;&lt;/span&gt;, ATTR&lt;span class="o"&gt;{&lt;/span&gt;idProduct&lt;span class="o"&gt;}==&lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;product_id&amp;quot;&lt;/span&gt;, &lt;span class="nv"&gt;OWNER&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;my_username&amp;quot;&lt;/span&gt;, &lt;span class="nv"&gt;GROUP&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;my_group&amp;quot;&lt;/span&gt;, &lt;span class="nv"&gt;MODE&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;0666&amp;quot;&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;
&lt;p&gt;Where you need to replace &lt;tt class="docutils literal"&gt;product_id&lt;/tt&gt;, &lt;tt class="docutils literal"&gt;my_username&lt;/tt&gt; and &lt;tt class="docutils literal"&gt;my_group&lt;/tt&gt; with your own&amp;nbsp;values.&lt;/p&gt;
&lt;p&gt;&lt;tt class="docutils literal"&gt;my_username&lt;/tt&gt; is the username that you login to the system, you can find it by running the following&amp;nbsp;command:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;table class="codehilitetable"&gt;&lt;tr&gt;&lt;td class="linenos"&gt;&lt;div class="linenodiv"&gt;&lt;pre&gt;&lt;span class="normal"&gt;1&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class="code"&gt;&lt;div&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="gp"&gt;$ &lt;/span&gt;id -gn
&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;
&lt;p&gt;&lt;tt class="docutils literal"&gt;my_group&lt;/tt&gt; is the primary group of your username, you can find it by running the following&amp;nbsp;command:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;table class="codehilitetable"&gt;&lt;tr&gt;&lt;td class="linenos"&gt;&lt;div class="linenodiv"&gt;&lt;pre&gt;&lt;span class="normal"&gt;1&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class="code"&gt;&lt;div&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="gp"&gt;$ &lt;/span&gt;id -un
&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;
&lt;p&gt;&lt;tt class="docutils literal"&gt;product_id&lt;/tt&gt; is the &lt;span class="caps"&gt;USB&lt;/span&gt; Product &lt;span class="caps"&gt;ID&lt;/span&gt; assigned by the manufacturer, you can find it by running the following&amp;nbsp;command:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;table class="codehilitetable"&gt;&lt;tr&gt;&lt;td class="linenos"&gt;&lt;div class="linenodiv"&gt;&lt;pre&gt;&lt;span class="normal"&gt;1&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class="code"&gt;&lt;div&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="gp"&gt;$ &lt;/span&gt;lsusb &lt;span class="p"&gt;|&lt;/span&gt;grep Atmel &lt;span class="p"&gt;|&lt;/span&gt; awk &lt;span class="s1"&gt;&amp;#39;{ print $6 }&amp;#39;&lt;/span&gt; &lt;span class="p"&gt;|&lt;/span&gt; awk &lt;span class="s1"&gt;&amp;#39;BEGIN { FS = &amp;quot;:&amp;quot; } ; { print $2 }&amp;#39;&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;
&lt;p&gt;Reload udev to apply our&amp;nbsp;rules:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;table class="codehilitetable"&gt;&lt;tr&gt;&lt;td class="linenos"&gt;&lt;div class="linenodiv"&gt;&lt;pre&gt;&lt;span class="normal"&gt;1&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class="code"&gt;&lt;div&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="gp"&gt;$ &lt;/span&gt;sudo /etc/init.d/udev reload
&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;
&lt;p&gt;Finally, be sure to disconnect and reconnect the &lt;span class="caps"&gt;AVR&lt;/span&gt; board for the new rule to be&amp;nbsp;applied.&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class="section" id="creating-a-new-project"&gt;
&lt;h2&gt;Creating a new&amp;nbsp;project&lt;/h2&gt;
&lt;p&gt;Create a new file named &lt;tt class="docutils literal"&gt;test.c&lt;/tt&gt; with the following&amp;nbsp;content:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;table class="codehilitetable"&gt;&lt;tr&gt;&lt;td class="linenos"&gt;&lt;div class="linenodiv"&gt;&lt;pre&gt;&lt;span class="normal"&gt;1&lt;/span&gt;
&lt;span class="normal"&gt;2&lt;/span&gt;
&lt;span class="normal"&gt;3&lt;/span&gt;
&lt;span class="normal"&gt;4&lt;/span&gt;
&lt;span class="normal"&gt;5&lt;/span&gt;
&lt;span class="normal"&gt;6&lt;/span&gt;
&lt;span class="normal"&gt;7&lt;/span&gt;
&lt;span class="normal"&gt;8&lt;/span&gt;
&lt;span class="normal"&gt;9&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class="code"&gt;&lt;div&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="cm"&gt;/* Sample C program to turn on all leds on the AVR */&lt;/span&gt;&lt;span class="w"&gt;&lt;/span&gt;

&lt;span class="cp"&gt;#include&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="cpf"&gt;&amp;lt;avr/io.h&amp;gt;&lt;/span&gt;&lt;span class="cp"&gt;&lt;/span&gt;

&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;void&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;DDRA&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mh"&gt;0xFF&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="w"&gt;&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="n"&gt;PORTA&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;~&lt;/span&gt;&lt;span class="mh"&gt;0xFF&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="w"&gt;&lt;/span&gt;
&lt;span class="w"&gt;    &lt;/span&gt;&lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="w"&gt;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;
&lt;p&gt;Create a new file named &lt;a class="reference external" href="http://en.wikipedia.org/wiki/Make_(software)#Makefiles"&gt;Makefile&lt;/a&gt; with the following&amp;nbsp;content:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;table class="codehilitetable"&gt;&lt;tr&gt;&lt;td class="linenos"&gt;&lt;div class="linenodiv"&gt;&lt;pre&gt;&lt;span class="normal"&gt; 1&lt;/span&gt;
&lt;span class="normal"&gt; 2&lt;/span&gt;
&lt;span class="normal"&gt; 3&lt;/span&gt;
&lt;span class="normal"&gt; 4&lt;/span&gt;
&lt;span class="normal"&gt; 5&lt;/span&gt;
&lt;span class="normal"&gt; 6&lt;/span&gt;
&lt;span class="normal"&gt; 7&lt;/span&gt;
&lt;span class="normal"&gt; 8&lt;/span&gt;
&lt;span class="normal"&gt; 9&lt;/span&gt;
&lt;span class="normal"&gt;10&lt;/span&gt;
&lt;span class="normal"&gt;11&lt;/span&gt;
&lt;span class="normal"&gt;12&lt;/span&gt;
&lt;span class="normal"&gt;13&lt;/span&gt;
&lt;span class="normal"&gt;14&lt;/span&gt;
&lt;span class="normal"&gt;15&lt;/span&gt;
&lt;span class="normal"&gt;16&lt;/span&gt;
&lt;span class="normal"&gt;17&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class="code"&gt;&lt;div&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="nv"&gt;CC&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sb"&gt;`&lt;/span&gt;which avr-gcc&lt;span class="sb"&gt;`&lt;/span&gt;
&lt;span class="nv"&gt;CFLAGS&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;-g -Os -Wall -mcall-prologues -std&lt;span class="o"&gt;=&lt;/span&gt;c99 -mmcu&lt;span class="o"&gt;=&lt;/span&gt;atmega2560
&lt;span class="nv"&gt;OBJ2HEX&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sb"&gt;`&lt;/span&gt;which avr-objcopy&lt;span class="sb"&gt;`&lt;/span&gt;
&lt;span class="nv"&gt;AVRD&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sb"&gt;`&lt;/span&gt;which avrdude&lt;span class="sb"&gt;`&lt;/span&gt;
&lt;span class="c"&gt;# Modify TARGET to match your C static without the .c extension (it&amp;#39;s test.c in this case)&lt;/span&gt;
&lt;span class="nv"&gt;TARGET&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nb"&gt;test&lt;/span&gt;

&lt;span class="nf"&gt;program &lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="k"&gt;$(&lt;/span&gt;&lt;span class="nv"&gt;TARGET&lt;/span&gt;&lt;span class="k"&gt;)&lt;/span&gt;.&lt;span class="n"&gt;hex&lt;/span&gt;
    &lt;span class="k"&gt;$(&lt;/span&gt;AVRD&lt;span class="k"&gt;)&lt;/span&gt; -p atmega2560 -c stk600 -P usb -v -v -U flash:w:&lt;span class="k"&gt;$(&lt;/span&gt;TARGET&lt;span class="k"&gt;)&lt;/span&gt;.hex
&lt;span class="nf"&gt;%.obj &lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; %.&lt;span class="n"&gt;o&lt;/span&gt;
    &lt;span class="k"&gt;$(&lt;/span&gt;CC&lt;span class="k"&gt;)&lt;/span&gt; &lt;span class="k"&gt;$(&lt;/span&gt;CFLAGS&lt;span class="k"&gt;)&lt;/span&gt; $&amp;lt; -o &lt;span class="nv"&gt;$@&lt;/span&gt;

&lt;span class="nf"&gt;%.hex &lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; %.&lt;span class="n"&gt;obj&lt;/span&gt;
    &lt;span class="k"&gt;$(&lt;/span&gt;OBJ2HEX&lt;span class="k"&gt;)&lt;/span&gt; -R .eeprom -O ihex $&amp;lt; &lt;span class="nv"&gt;$@&lt;/span&gt;

&lt;span class="nf"&gt;clean &lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;
    rm -f *.hex *.obj *.o
&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;
&lt;p&gt;Now all you have to do is run &lt;tt class="docutils literal"&gt;make&lt;/tt&gt; in the project folder to build the binary and upload it to the &lt;span class="caps"&gt;AVR&lt;/span&gt;&amp;nbsp;Board:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;table class="codehilitetable"&gt;&lt;tr&gt;&lt;td class="linenos"&gt;&lt;div class="linenodiv"&gt;&lt;pre&gt;&lt;span class="normal"&gt;1&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class="code"&gt;&lt;div&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="gp"&gt;$ &lt;/span&gt;make
&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;
&lt;/div&gt;
</content><category term="tech"></category><category term="avr"></category><category term="debian"></category><category term="linux"></category><category term="ubuntu"></category></entry><entry><title>Usefull linux commands/tricks</title><link href="https://razius.com/articles/usefull-linux-commandstricks.html" rel="alternate"></link><published>2012-05-14T23:00:00+02:00</published><updated>2012-05-14T23:00:00+02:00</updated><author><name>Silviu Tantos</name></author><id>tag:razius.com,2012-05-14:/articles/usefull-linux-commandstricks.html</id><summary type="html">&lt;p&gt;These are some sort of notes to myself, this list will be constantly&amp;nbsp;updated.&lt;/p&gt;
&lt;p&gt;Sort directories by size (human readable&amp;nbsp;size):&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;table class="codehilitetable"&gt;&lt;tr&gt;&lt;td class="linenos"&gt;&lt;div class="linenodiv"&gt;&lt;pre&gt;&lt;span class="normal"&gt;1&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class="code"&gt;&lt;div&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="gp"&gt;# &lt;/span&gt;du --max-depth&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="m"&gt;1&lt;/span&gt; -h &lt;span class="p"&gt;|&lt;/span&gt;sort -hr
&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;
&lt;p&gt;Set tabsize to 4 in&amp;nbsp;vim:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;table class="codehilitetable"&gt;&lt;tr&gt;&lt;td class="linenos"&gt;&lt;div class="linenodiv"&gt;&lt;pre&gt;&lt;span class="normal"&gt;1&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class="code"&gt;&lt;div&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="k"&gt;set&lt;/span&gt; &lt;span class="nb"&gt;tabstop&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="m"&gt;4&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;
&lt;p&gt;Show failed login attempts on your&amp;nbsp;machine:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;table class="codehilitetable"&gt;&lt;tr&gt;&lt;td class="linenos"&gt;&lt;div class="linenodiv"&gt;&lt;pre&gt;&lt;span class="normal"&gt;1&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class="code"&gt;&lt;div&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="gp"&gt;# &lt;/span&gt;lastb -F
&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;
&lt;p&gt;Print the …&lt;/p&gt;</summary><content type="html">&lt;p&gt;These are some sort of notes to myself, this list will be constantly&amp;nbsp;updated.&lt;/p&gt;
&lt;p&gt;Sort directories by size (human readable&amp;nbsp;size):&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;table class="codehilitetable"&gt;&lt;tr&gt;&lt;td class="linenos"&gt;&lt;div class="linenodiv"&gt;&lt;pre&gt;&lt;span class="normal"&gt;1&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class="code"&gt;&lt;div&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="gp"&gt;# &lt;/span&gt;du --max-depth&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="m"&gt;1&lt;/span&gt; -h &lt;span class="p"&gt;|&lt;/span&gt;sort -hr
&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;
&lt;p&gt;Set tabsize to 4 in&amp;nbsp;vim:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;table class="codehilitetable"&gt;&lt;tr&gt;&lt;td class="linenos"&gt;&lt;div class="linenodiv"&gt;&lt;pre&gt;&lt;span class="normal"&gt;1&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class="code"&gt;&lt;div&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="k"&gt;set&lt;/span&gt; &lt;span class="nb"&gt;tabstop&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="m"&gt;4&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;
&lt;p&gt;Show failed login attempts on your&amp;nbsp;machine:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;table class="codehilitetable"&gt;&lt;tr&gt;&lt;td class="linenos"&gt;&lt;div class="linenodiv"&gt;&lt;pre&gt;&lt;span class="normal"&gt;1&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class="code"&gt;&lt;div&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="gp"&gt;# &lt;/span&gt;lastb -F
&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;
&lt;p&gt;Print the most recent login of all users and of a given&amp;nbsp;user:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;table class="codehilitetable"&gt;&lt;tr&gt;&lt;td class="linenos"&gt;&lt;div class="linenodiv"&gt;&lt;pre&gt;&lt;span class="normal"&gt;1&lt;/span&gt;
&lt;span class="normal"&gt;2&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class="code"&gt;&lt;div&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="gp"&gt;# &lt;/span&gt;lastlog
&lt;span class="go"&gt;lastlog -u USERNAME&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;
&lt;div class="codehilite"&gt;&lt;table class="codehilitetable"&gt;&lt;tr&gt;&lt;td class="linenos"&gt;&lt;div class="linenodiv"&gt;&lt;pre&gt;&lt;span class="normal"&gt;1&lt;/span&gt;
&lt;span class="normal"&gt;2&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class="code"&gt;&lt;div&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="gp"&gt;$ &lt;/span&gt;curl -d &lt;span class="s2"&gt;&amp;quot;param1=value1&amp;amp;param2=value2&amp;quot;&lt;/span&gt; http://example.com/
&lt;span class="gp"&gt;$ &lt;/span&gt;curl -X POST -d @static http://example.com/
&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;
&lt;p&gt;Return current &lt;span class="caps"&gt;SSID&lt;/span&gt;&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;table class="codehilitetable"&gt;&lt;tr&gt;&lt;td class="linenos"&gt;&lt;div class="linenodiv"&gt;&lt;pre&gt;&lt;span class="normal"&gt;1&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class="code"&gt;&lt;div&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="go"&gt;iwconfig wlan0 | awk -F&amp;#39;:&amp;#39; &amp;#39;/ ESSID/ {print $2}&amp;#39; | tr -d &amp;#39;&amp;quot;&amp;#39;&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;
&lt;p&gt;Force a&amp;nbsp;reboot:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;table class="codehilitetable"&gt;&lt;tr&gt;&lt;td class="linenos"&gt;&lt;div class="linenodiv"&gt;&lt;pre&gt;&lt;span class="normal"&gt;1&lt;/span&gt;
&lt;span class="normal"&gt;2&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class="code"&gt;&lt;div&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="gp"&gt;# &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt; &amp;gt; /proc/sys/kernel/sysrq
&lt;span class="gp"&gt;# &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; b &amp;gt; /proc/sysrq-trigger
&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;
&lt;p&gt;Force a&amp;nbsp;shutdown:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;table class="codehilitetable"&gt;&lt;tr&gt;&lt;td class="linenos"&gt;&lt;div class="linenodiv"&gt;&lt;pre&gt;&lt;span class="normal"&gt;1&lt;/span&gt;
&lt;span class="normal"&gt;2&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class="code"&gt;&lt;div&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="gp"&gt;# &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt; &amp;gt; /proc/sys/kernel/sysrq
&lt;span class="gp"&gt;# &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; o &amp;gt; /proc/sysrq-trigger
&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;
&lt;div class="codehilite"&gt;&lt;table class="codehilitetable"&gt;&lt;tr&gt;&lt;td class="linenos"&gt;&lt;div class="linenodiv"&gt;&lt;pre&gt;&lt;span class="normal"&gt;1&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class="code"&gt;&lt;div&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="go"&gt;find . -maxdepth 1 -type d -exec basename {} \;|xargs -L 1 -I &amp;#39;{}&amp;#39; chown {}:{} {}&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;
&lt;p&gt;Print text at LINE_NUMBER in a huge&amp;nbsp;file&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;table class="codehilitetable"&gt;&lt;tr&gt;&lt;td class="linenos"&gt;&lt;div class="linenodiv"&gt;&lt;pre&gt;&lt;span class="normal"&gt;1&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class="code"&gt;&lt;div&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="go"&gt;awk &amp;#39;NR &amp;gt;= LINE_NUMBER &amp;amp;&amp;amp; NR &amp;lt;= LINE_NUMBER&amp;#39; data.txt&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;
</content><category term="tech"></category></entry><entry><title>How to fix GC overhead limit exceeded in Eclipse</title><link href="https://razius.com/articles/how-to-fix-gc-overhead-limit-exceeded-in-eclipse.html" rel="alternate"></link><published>2012-03-27T10:13:00+02:00</published><updated>2012-03-27T10:13:00+02:00</updated><author><name>Silviu Tantos</name></author><id>tag:razius.com,2012-03-27:/articles/how-to-fix-gc-overhead-limit-exceeded-in-eclipse.html</id><summary type="html">&lt;p&gt;If you&amp;#8217;re performing memory intensive operations such as building workspace on big projects, Eclipse will throw this error when it runs out of&amp;nbsp;memory:&lt;/p&gt;
&lt;p&gt;&lt;em&gt;An internal error occurred during: “Building workspace”. &lt;span class="caps"&gt;GC&lt;/span&gt; overhead limit&amp;nbsp;exceeded&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;In order to fix it, you need to increase the memory allocation for Eclipse …&lt;/p&gt;</summary><content type="html">&lt;p&gt;If you&amp;#8217;re performing memory intensive operations such as building workspace on big projects, Eclipse will throw this error when it runs out of&amp;nbsp;memory:&lt;/p&gt;
&lt;p&gt;&lt;em&gt;An internal error occurred during: “Building workspace”. &lt;span class="caps"&gt;GC&lt;/span&gt; overhead limit&amp;nbsp;exceeded&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;In order to fix it, you need to increase the memory allocation for Eclipse. To do this, open &lt;tt class="docutils literal"&gt;eclipse.ini&lt;/tt&gt; and increase the &lt;tt class="docutils literal"&gt;Xms&lt;/tt&gt; (heap&amp;#8217;s start memory) and &lt;tt class="docutils literal"&gt;Xmx&lt;/tt&gt; (heap&amp;#8217;s maximum memory) values to a value that you think is reasonable with your system and projects, for&amp;nbsp;example:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;table class="codehilitetable"&gt;&lt;tr&gt;&lt;td class="linenos"&gt;&lt;div class="linenodiv"&gt;&lt;pre&gt;&lt;span class="normal"&gt;1&lt;/span&gt;
&lt;span class="normal"&gt;2&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class="code"&gt;&lt;div&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="go"&gt;-Xms512m&lt;/span&gt;
&lt;span class="go"&gt;-Xmx1024m&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;
</content><category term="tech"></category><category term="eclipse"></category><category term="java"></category><category term="linux"></category></entry><entry><title>Backup and restore installed packages on Debian/Ubuntu</title><link href="https://razius.com/articles/backup-and-restore-installed-packages-on-debian-ubuntu.html" rel="alternate"></link><published>2012-03-05T10:24:00+01:00</published><updated>2012-03-05T10:24:00+01:00</updated><author><name>Silviu Tantos</name></author><id>tag:razius.com,2012-03-05:/articles/backup-and-restore-installed-packages-on-debian-ubuntu.html</id><summary type="html">&lt;p&gt;If you want to reinstall a server or a desktop and want to install the same packages after reinstalling the operating system you can easily do that with&amp;nbsp;dpkg.&lt;/p&gt;
&lt;p&gt;First we need to backup the list of packages to a file and after reinstalling the operating system, in this example …&lt;/p&gt;</summary><content type="html">&lt;p&gt;If you want to reinstall a server or a desktop and want to install the same packages after reinstalling the operating system you can easily do that with&amp;nbsp;dpkg.&lt;/p&gt;
&lt;p&gt;First we need to backup the list of packages to a file and after reinstalling the operating system, in this example will also backup the &lt;tt class="docutils literal"&gt;/etc/apt/sources.list&lt;/tt&gt; file and the &lt;tt class="docutils literal"&gt;/etc/apt/sources.list.d&lt;/tt&gt; directory as they contain the list of repositories from which you installed&amp;nbsp;packages.&lt;/p&gt;
&lt;div class="section" id="backuping-up-the-list-of-installed-package-and-the-repository-list-into-a-tar-archive"&gt;
&lt;h2&gt;Backuping up the list of installed package and the repository list into a tar&amp;nbsp;archive&lt;/h2&gt;
&lt;div class="codehilite"&gt;&lt;table class="codehilitetable"&gt;&lt;tr&gt;&lt;td class="linenos"&gt;&lt;div class="linenodiv"&gt;&lt;pre&gt;&lt;span class="normal"&gt;1&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class="code"&gt;&lt;div&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="gp"&gt;# &lt;/span&gt;mkdir ~/packages&lt;span class="p"&gt;;&lt;/span&gt; cp -R /etc/apt/sources.list /etc/apt/sources.list.d/ ~/packages/&lt;span class="p"&gt;;&lt;/span&gt; dpkg --get-selections &amp;gt; ~/packages/package.list&lt;span class="p"&gt;;&lt;/span&gt; tar cPvzf ~/packages-&lt;span class="sb"&gt;`&lt;/span&gt;date +%Y-%m-%d&lt;span class="sb"&gt;`&lt;/span&gt;.tar.gz ~/packages/&lt;span class="p"&gt;;&lt;/span&gt; rm -rf ~/packages/
&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;
&lt;p&gt;Now you should have a &lt;tt class="docutils literal"&gt;&lt;span class="pre"&gt;packages-&lt;span class="caps"&gt;DATE&lt;/span&gt;.tar.gz&lt;/span&gt;&lt;/tt&gt; archive under your root user&amp;#8217;s home folder (/root/) containing the list of packages and&amp;nbsp;repositories.&lt;/p&gt;
&lt;/div&gt;
&lt;div class="section" id="restore-the-list-of-installed-package-and-the-repository-list-from-the-tar-archive"&gt;
&lt;h2&gt;Restore the list of installed package and the repository list from the tar&amp;nbsp;archive:&lt;/h2&gt;
&lt;p&gt;After reinstalling upload the packages-&lt;span class="caps"&gt;DATE&lt;/span&gt;.tar.gz archive to the root&amp;#8217;s user&amp;#8217;s home directory (&lt;tt class="docutils literal"&gt;/root/&lt;/tt&gt;) and run the following&amp;nbsp;command:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;table class="codehilitetable"&gt;&lt;tr&gt;&lt;td class="linenos"&gt;&lt;div class="linenodiv"&gt;&lt;pre&gt;&lt;span class="normal"&gt;1&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class="code"&gt;&lt;div&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="gp"&gt;# &lt;/span&gt;mkdir ~/packages&lt;span class="p"&gt;;&lt;/span&gt; tar xPvzf ~/packages-*.tar.gz&lt;span class="p"&gt;;&lt;/span&gt; cp ~/packages/sources.list /etc/apt/sources.list&lt;span class="p"&gt;;&lt;/span&gt; cp ~/packages/sources.list.d/* /etc/apt/sources.list.d/&lt;span class="p"&gt;;&lt;/span&gt;apt-get update&lt;span class="p"&gt;;&lt;/span&gt; dpkg --set-selections &amp;lt; ~/packages/package.list&lt;span class="p"&gt;;&lt;/span&gt; apt-get install --yes dselect&lt;span class="p"&gt;;&lt;/span&gt; dselect update&lt;span class="p"&gt;;&lt;/span&gt; apt-get dselect-upgrade
&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;
&lt;p&gt;This will install all of the packages which you had at the time of the&amp;nbsp;backup.&lt;/p&gt;
&lt;/div&gt;
</content><category term="tech"></category><category term="debian"></category><category term="dpkg"></category><category term="linux"></category></entry><entry><title>Lock screen when closing laptop lid in Ubuntu 11.10</title><link href="https://razius.com/articles/lock-screen-when-closing-laptop-lid-in-ubuntu-11-10.html" rel="alternate"></link><published>2012-02-13T13:03:00+01:00</published><updated>2012-02-13T13:03:00+01:00</updated><author><name>Silviu Tantos</name></author><id>tag:razius.com,2012-02-13:/articles/lock-screen-when-closing-laptop-lid-in-ubuntu-11-10.html</id><summary type="html">&lt;p&gt;An useful thing to do is to have lock the screen when you close the laptop lid so you don&amp;#8217;t have to wait for the timeout but in Ubuntu 11.10 this feature was&amp;nbsp;disabled.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Note: This bug has been fixed in Ubuntu 12.04 Precise&amp;nbsp;Pangolin.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;To have …&lt;/p&gt;</summary><content type="html">&lt;p&gt;An useful thing to do is to have lock the screen when you close the laptop lid so you don&amp;#8217;t have to wait for the timeout but in Ubuntu 11.10 this feature was&amp;nbsp;disabled.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Note: This bug has been fixed in Ubuntu 12.04 Precise&amp;nbsp;Pangolin.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;To have your screen locked when you close your lid under Ubuntu 11.10 you need to edit &lt;tt class="docutils literal"&gt;/etc/acpi/lid.sh&lt;/tt&gt; and just after the&amp;nbsp;line&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;table class="codehilitetable"&gt;&lt;tr&gt;&lt;td class="linenos"&gt;&lt;div class="linenodiv"&gt;&lt;pre&gt;&lt;span class="normal"&gt;1&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class="code"&gt;&lt;div&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;. /usr/share/acpi-support/screenblank
&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;
&lt;p&gt;add the following&amp;nbsp;line:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;table class="codehilitetable"&gt;&lt;tr&gt;&lt;td class="linenos"&gt;&lt;div class="linenodiv"&gt;&lt;pre&gt;&lt;span class="normal"&gt;1&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class="code"&gt;&lt;div&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="go"&gt;su $user -c &amp;#39;/usr/bin/gnome-screensaver-command -l&amp;#39;&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;
&lt;p&gt;So the result should look something&amp;nbsp;like:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;table class="codehilitetable"&gt;&lt;tr&gt;&lt;td class="linenos"&gt;&lt;div class="linenodiv"&gt;&lt;pre&gt;&lt;span class="normal"&gt; 1&lt;/span&gt;
&lt;span class="normal"&gt; 2&lt;/span&gt;
&lt;span class="normal"&gt; 3&lt;/span&gt;
&lt;span class="normal"&gt; 4&lt;/span&gt;
&lt;span class="normal"&gt; 5&lt;/span&gt;
&lt;span class="normal"&gt; 6&lt;/span&gt;
&lt;span class="normal"&gt; 7&lt;/span&gt;
&lt;span class="normal"&gt; 8&lt;/span&gt;
&lt;span class="normal"&gt; 9&lt;/span&gt;
&lt;span class="normal"&gt;10&lt;/span&gt;
&lt;span class="normal"&gt;11&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class="code"&gt;&lt;div&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="o"&gt;[&lt;/span&gt;...&lt;span class="o"&gt;]&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; x &lt;span class="k"&gt;in&lt;/span&gt; /tmp/.X11-unix/*&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
        &lt;span class="nv"&gt;displaynum&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sb"&gt;`&lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="nv"&gt;$x&lt;/span&gt; &lt;span class="p"&gt;|&lt;/span&gt; sed s#/tmp/.X11-unix/X##&lt;span class="sb"&gt;`&lt;/span&gt;
        getXuser&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt; x&lt;span class="s2"&gt;&amp;quot;&lt;/span&gt;&lt;span class="nv"&gt;$XAUTHORITY&lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;&lt;/span&gt; !&lt;span class="o"&gt;=&lt;/span&gt; x&lt;span class="s2"&gt;&amp;quot;&amp;quot;&lt;/span&gt; &lt;span class="o"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then&lt;/span&gt;
            &lt;span class="nb"&gt;export&lt;/span&gt; &lt;span class="nv"&gt;DISPLAY&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;:&lt;/span&gt;&lt;span class="nv"&gt;$displaynum&lt;/span&gt;&lt;span class="s2"&gt;&amp;quot;&lt;/span&gt;
            . /usr/share/acpi-support/screenblank
            su &lt;span class="nv"&gt;$user&lt;/span&gt; -c &lt;span class="s1"&gt;&amp;#39;/usr/bin/gnome-screensaver-command -l&amp;#39;&lt;/span&gt;
        &lt;span class="k"&gt;fi&lt;/span&gt;
    &lt;span class="k"&gt;done&lt;/span&gt;
&lt;span class="o"&gt;[&lt;/span&gt;...&lt;span class="o"&gt;]&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;
</content><category term="tech"></category><category term="ubuntu"></category></entry><entry><title>Password protecting folders with nginx</title><link href="https://razius.com/articles/password-protecting-folders-with-nginx.html" rel="alternate"></link><published>2012-02-13T12:20:00+01:00</published><updated>2012-02-13T12:20:00+01:00</updated><author><name>Silviu Tantos</name></author><id>tag:razius.com,2012-02-13:/articles/password-protecting-folders-with-nginx.html</id><summary type="html">&lt;p&gt;If you need to password protect a folder using nginx here&amp;#8217;s how. In this example we&amp;#8217;re gonna password protect the /admin folder, trying to access the admin directory will prompt the user with a basic authentication dialog, and will be challenged against the created password&amp;nbsp;file.&lt;/p&gt;
&lt;p&gt;Edit your …&lt;/p&gt;</summary><content type="html">&lt;p&gt;If you need to password protect a folder using nginx here&amp;#8217;s how. In this example we&amp;#8217;re gonna password protect the /admin folder, trying to access the admin directory will prompt the user with a basic authentication dialog, and will be challenged against the created password&amp;nbsp;file.&lt;/p&gt;
&lt;p&gt;Edit your site&amp;#8217;s configuration file and add the following lines inside the server-block&amp;nbsp;configuration:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;table class="codehilitetable"&gt;&lt;tr&gt;&lt;td class="linenos"&gt;&lt;div class="linenodiv"&gt;&lt;pre&gt;&lt;span class="normal"&gt;1&lt;/span&gt;
&lt;span class="normal"&gt;2&lt;/span&gt;
&lt;span class="normal"&gt;3&lt;/span&gt;
&lt;span class="normal"&gt;4&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class="code"&gt;&lt;div&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="k"&gt;location&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s"&gt;/admin&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;&lt;/span&gt;
&lt;span class="w"&gt;   &lt;/span&gt;&lt;span class="kn"&gt;auth_basic&lt;/span&gt;&lt;span class="w"&gt;            &lt;/span&gt;&lt;span class="s"&gt;&amp;quot;Restricted&amp;quot;&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="w"&gt;&lt;/span&gt;
&lt;span class="w"&gt;   &lt;/span&gt;&lt;span class="kn"&gt;auth_basic_user_file&lt;/span&gt;&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="s"&gt;/etc/nginx/htpasswd&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="w"&gt;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;
&lt;p&gt;Next we need to create a password file, the safest place to store a password file is outside of the web-accessible location so we&amp;#8217;re gonna place it in&amp;nbsp;/etc/nginx.&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;table class="codehilitetable"&gt;&lt;tr&gt;&lt;td class="linenos"&gt;&lt;div class="linenodiv"&gt;&lt;pre&gt;&lt;span class="normal"&gt;1&lt;/span&gt;
&lt;span class="normal"&gt;2&lt;/span&gt;
&lt;span class="normal"&gt;3&lt;/span&gt;
&lt;span class="normal"&gt;4&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class="code"&gt;&lt;div&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="gp"&gt;# &lt;/span&gt;&lt;span class="nb"&gt;cd&lt;/span&gt; /etc/nginx/
&lt;span class="gp"&gt;# &lt;/span&gt;wget http://trac.edgewall.org/export/10975/trunk/contrib/htpasswd.py
&lt;span class="gp"&gt;# &lt;/span&gt;chmod &lt;span class="m"&gt;755&lt;/span&gt; htpasswd.py
&lt;span class="gp"&gt;# &lt;/span&gt;./htpasswd.py -c -b htpasswd USERNAME PASSWORD
&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;
&lt;p&gt;Don&amp;#8217;t forget to reload nginx so that the configuration changes take&amp;nbsp;effect:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;table class="codehilitetable"&gt;&lt;tr&gt;&lt;td class="linenos"&gt;&lt;div class="linenodiv"&gt;&lt;pre&gt;&lt;span class="normal"&gt;1&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class="code"&gt;&lt;div&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="c1"&gt;# /etc/init.d/nginx reload&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;
</content><category term="tech"></category><category term="nginx"></category></entry><entry><title>Installing and adding an external Tomcat server in Netbeans</title><link href="https://razius.com/articles/installing-and-adding-an-external-tomcat-server-in-netbeans.html" rel="alternate"></link><published>2012-01-28T05:18:00+01:00</published><updated>2012-01-28T05:18:00+01:00</updated><author><name>Silviu Tantos</name></author><id>tag:razius.com,2012-01-28:/articles/installing-and-adding-an-external-tomcat-server-in-netbeans.html</id><summary type="html">&lt;p&gt;Netbeans no longer comes with Tomcat bundled so if you want to deploy your application to an Tomcat server you need to manually register an external&amp;nbsp;server.&lt;/p&gt;
&lt;p class="italic"&gt;Note: This article is old no longer and this is not true anymore, Tomcat is now bundled with Netbeans so the steps in …&lt;/p&gt;</summary><content type="html">&lt;p&gt;Netbeans no longer comes with Tomcat bundled so if you want to deploy your application to an Tomcat server you need to manually register an external&amp;nbsp;server.&lt;/p&gt;
&lt;p class="italic"&gt;Note: This article is old no longer and this is not true anymore, Tomcat is now bundled with Netbeans so the steps in this tutorial are not needed anymore. You can download and install the bundle from &lt;a class="reference external" href="https://netbeans.org/downloads/"&gt;the official page&lt;/a&gt;.&lt;/p&gt;
&lt;div class="section" id="pre-requisites"&gt;
&lt;h2&gt;Pre-requisites:&lt;/h2&gt;
&lt;p&gt;I&amp;#8217;m assuming you are using at least Ubuntu Linux 11.10 and you already have installed the the latest Netbeans 7.1 with the Java Web Applications plugin&amp;nbsp;installed.&lt;/p&gt;
&lt;p&gt;I also assume that you want to install and configure Tomcat from the repository, if you don&amp;#8217;t care an easier method would be to just download &lt;a class="reference external" href="http://ftp.download-by.net/apache/tomcat/tomcat-7/v7.0.47/bin/apache-tomcat-7.0.47.tar.gz"&gt;apache-tomcat.zip&lt;/a&gt; from the Tomcat website, extract the archive to a folder under your home directory and just skip to step 4 of this tutorial where Under Server Location you would browse to where you extracted the archive and under Username and Password you would put the username and password you would have put in &lt;tt class="docutils literal"&gt;&lt;span class="pre"&gt;tomcat-users.xml&lt;/span&gt;&lt;/tt&gt;.&lt;/p&gt;
&lt;/div&gt;
&lt;div class="section" id="install-tomcat"&gt;
&lt;h2&gt;1. Install&amp;nbsp;Tomcat&lt;/h2&gt;
&lt;div class="codehilite"&gt;&lt;table class="codehilitetable"&gt;&lt;tr&gt;&lt;td class="linenos"&gt;&lt;div class="linenodiv"&gt;&lt;pre&gt;&lt;span class="normal"&gt;1&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class="code"&gt;&lt;div&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="gp"&gt;$ &lt;/span&gt;sudo apt-get install tomcat7 tomcat7-common tomcat7-admin tomcat7-user
&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div class="section" id="add-an-administrative-user-to-tomcat"&gt;
&lt;h2&gt;2. Add an administrative user to&amp;nbsp;Tomcat&lt;/h2&gt;
&lt;p&gt;Tomcat does have any users defined that could be used for administrative purposes so we need to open tomcat-users.xml in a text editor and add a user with the proper roles assigned to&amp;nbsp;it.&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;table class="codehilitetable"&gt;&lt;tr&gt;&lt;td class="linenos"&gt;&lt;div class="linenodiv"&gt;&lt;pre&gt;&lt;span class="normal"&gt;1&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class="code"&gt;&lt;div&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="gp"&gt;$ &lt;/span&gt;sudo gedit /etc/tomcat7/tomcat-users.xml
&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;
&lt;p&gt;Replace its content with the following and make sure that you replace &lt;tt class="docutils literal"&gt;&lt;span class="caps"&gt;USERNAME&lt;/span&gt;&lt;/tt&gt; and &lt;tt class="docutils literal"&gt;&lt;span class="caps"&gt;PASSWORD&lt;/span&gt;&lt;/tt&gt; with the values you&amp;nbsp;want:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;table class="codehilitetable"&gt;&lt;tr&gt;&lt;td class="linenos"&gt;&lt;div class="linenodiv"&gt;&lt;pre&gt;&lt;span class="normal"&gt;1&lt;/span&gt;
&lt;span class="normal"&gt;2&lt;/span&gt;
&lt;span class="normal"&gt;3&lt;/span&gt;
&lt;span class="normal"&gt;4&lt;/span&gt;
&lt;span class="normal"&gt;5&lt;/span&gt;
&lt;span class="normal"&gt;6&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class="code"&gt;&lt;div&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="cp"&gt;&amp;lt;?xml version=&amp;#39;1.0&amp;#39; encoding=&amp;#39;utf-8&amp;#39;?&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;tomcat-users&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;role&lt;/span&gt; &lt;span class="na"&gt;rolename=&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;manager-script&amp;quot;&lt;/span&gt;&lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;role&lt;/span&gt; &lt;span class="na"&gt;rolename=&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;admin&amp;quot;&lt;/span&gt;&lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;user&lt;/span&gt; &lt;span class="na"&gt;username=&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;USERNAME&amp;quot;&lt;/span&gt; &lt;span class="na"&gt;password=&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;PASSWORD&amp;quot;&lt;/span&gt; &lt;span class="na"&gt;roles=&lt;/span&gt;&lt;span class="s"&gt;&amp;quot;manager-script,admin&amp;quot;&lt;/span&gt;&lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/tomcat-users&amp;gt;&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div class="section" id="some-fixes"&gt;
&lt;h2&gt;3. Some&amp;nbsp;&amp;#8220;fixes&amp;#8221;&lt;/h2&gt;
&lt;p&gt;Unfortunately it seams that Netbeans doesn&amp;#8217;t correctly detect the the Tomcat installation directory so we need to make some temporary changes till we add the server otherwise will get an error saying &lt;em&gt;&amp;#8220;The specified Server Location (Catalina Home) folder is not&amp;nbsp;valid.&amp;#8221;&lt;/em&gt;&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;table class="codehilitetable"&gt;&lt;tr&gt;&lt;td class="linenos"&gt;&lt;div class="linenodiv"&gt;&lt;pre&gt;&lt;span class="normal"&gt;1&lt;/span&gt;
&lt;span class="normal"&gt;2&lt;/span&gt;
&lt;span class="normal"&gt;3&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class="code"&gt;&lt;div&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="gp"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;cd&lt;/span&gt; /usr/share/tomcat7/lib
&lt;span class="gp"&gt;$ &lt;/span&gt;mv catalina.jar catalina.jar.bk
&lt;span class="gp"&gt;$ &lt;/span&gt;wget http://www.razius.com/files/catalina.jar
&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;
&lt;p&gt;We need to make sure that the configuration files can be read from the installation directory otherwise will get an error saying &lt;em&gt;&amp;#8220;The&amp;nbsp;&amp;lt;CATALINA_HOME&amp;gt;/conf/server.xml&amp;nbsp;can&amp;#8217;t&amp;nbsp;be&amp;nbsp;read.&amp;#8221;&lt;/em&gt;&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;table class="codehilitetable"&gt;&lt;tr&gt;&lt;td class="linenos"&gt;&lt;div class="linenodiv"&gt;&lt;pre&gt;&lt;span class="normal"&gt;1&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class="code"&gt;&lt;div&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="gp"&gt;$ &lt;/span&gt;sudo ln -s /etc/tomcat7/ /usr/share/tomcat7/conf
&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;
&lt;p&gt;We need to chown the Tomcat installation and configuration directory so we don&amp;#8217;t have any permission problems. Replace &lt;span class="caps"&gt;USERNAME&lt;/span&gt; with your Ubuntu&amp;nbsp;username:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;table class="codehilitetable"&gt;&lt;tr&gt;&lt;td class="linenos"&gt;&lt;div class="linenodiv"&gt;&lt;pre&gt;&lt;span class="normal"&gt;1&lt;/span&gt;
&lt;span class="normal"&gt;2&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class="code"&gt;&lt;div&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="gp"&gt;$ &lt;/span&gt;sudo chown -R USERNAME:USERNAME /etc/tomcat7/
&lt;span class="gp"&gt;$ &lt;/span&gt;sudo chown -R USERNAME:USERNAME /usr/share/tomcat7/
&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;
&lt;p&gt;Disable the upstart Tomcat service (Netbeans start&amp;#8217;s it up for us&amp;nbsp;automatically):&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;table class="codehilitetable"&gt;&lt;tr&gt;&lt;td class="linenos"&gt;&lt;div class="linenodiv"&gt;&lt;pre&gt;&lt;span class="normal"&gt;1&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class="code"&gt;&lt;div&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="gp"&gt;$ &lt;/span&gt;sudo update-rc.d tomcat7 disable &lt;span class="m"&gt;0123456&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div class="section" id="adding-the-server-in-netbeans"&gt;
&lt;h2&gt;4. Adding the server in&amp;nbsp;Netbeans&lt;/h2&gt;
&lt;p&gt;Now that you have Tomcat installed and configured we can open up Netbeans and under the Services tab right click on the Servers node and click on Add&amp;nbsp;server.&lt;/p&gt;
&lt;div class="figure align-center"&gt;
&lt;img alt="" src="https://razius.com/images/articles/netbeans-add-server.png" /&gt;
&lt;/div&gt;
&lt;p&gt;In the current list select Apache Tomcat and click Next. Under Server Location enter your Tomcat installation directory , by default this should be &lt;tt class="docutils literal"&gt;/usr/share/tomcat7&lt;/tt&gt; and under Username and Password put in the username and password that we added in the &lt;tt class="docutils literal"&gt;&lt;span class="pre"&gt;tomcat-users.xml&lt;/span&gt;&lt;/tt&gt; file.&lt;/p&gt;
&lt;div class="figure align-center"&gt;
&lt;img alt="" src="https://razius.com/images/articles/netbeans-add-server-instance.png" /&gt;
&lt;/div&gt;
&lt;p&gt;Click &lt;em&gt;Finish&lt;/em&gt;. You should now be able to see Tomcat as an added server under the Servers&amp;nbsp;Node.&lt;/p&gt;
&lt;/div&gt;
&lt;div class="section" id="revert-changes"&gt;
&lt;h2&gt;5. Revert&amp;nbsp;changes&lt;/h2&gt;
&lt;p&gt;If we are installing from the repository we need to revert the changes done in step&amp;nbsp;3:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;table class="codehilitetable"&gt;&lt;tr&gt;&lt;td class="linenos"&gt;&lt;div class="linenodiv"&gt;&lt;pre&gt;&lt;span class="normal"&gt;1&lt;/span&gt;
&lt;span class="normal"&gt;2&lt;/span&gt;
&lt;span class="normal"&gt;3&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class="code"&gt;&lt;div&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="gp"&gt;$ &lt;/span&gt;&lt;span class="nb"&gt;cd&lt;/span&gt; /usr/share/tomcat7/lib
&lt;span class="gp"&gt;$ &lt;/span&gt;rm catalina.jar
&lt;span class="gp"&gt;$ &lt;/span&gt;mv catalina.jar.bk catalina.jar
&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;
&lt;/div&gt;
</content><category term="tech"></category><category term="linux"></category><category term="netbeans"></category><category term="tomcat"></category></entry><entry><title>Wordpress reset password without email</title><link href="https://razius.com/articles/wordpress-reset-password-without-email.html" rel="alternate"></link><published>2011-09-13T14:45:00+02:00</published><updated>2011-09-13T14:45:00+02:00</updated><author><name>Silviu Tantos</name></author><id>tag:razius.com,2011-09-13:/articles/wordpress-reset-password-without-email.html</id><summary type="html">&lt;p&gt;If you&amp;#8217;re like me and you forgot your wordpress password and don&amp;#8217;t have email setup on your system there are alternative ways to set a new password rather then sending and&amp;nbsp;email.&lt;/p&gt;
&lt;p&gt;Pick a particular method depending on what type of access you have to your&amp;nbsp;website/hosting …&lt;/p&gt;</summary><content type="html">&lt;p&gt;If you&amp;#8217;re like me and you forgot your wordpress password and don&amp;#8217;t have email setup on your system there are alternative ways to set a new password rather then sending and&amp;nbsp;email.&lt;/p&gt;
&lt;p&gt;Pick a particular method depending on what type of access you have to your&amp;nbsp;website/hosting.&lt;/p&gt;
&lt;div class="section" id="through-mysql"&gt;
&lt;h2&gt;Through&amp;nbsp;MySQL:&lt;/h2&gt;
&lt;p&gt;The easiest ways is through the MySQL command line but you need ssh access to your&amp;nbsp;server.&lt;/p&gt;
&lt;ol class="arabic simple"&gt;
&lt;li&gt;Connect to&amp;nbsp;MySQL:&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="codehilite"&gt;&lt;table class="codehilitetable"&gt;&lt;tr&gt;&lt;td class="linenos"&gt;&lt;div class="linenodiv"&gt;&lt;pre&gt;&lt;span class="normal"&gt;1&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class="code"&gt;&lt;div&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="gp"&gt;# &lt;/span&gt;mysql -u root -p
&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;
&lt;ol class="arabic simple" start="2"&gt;
&lt;li&gt;Select the wordpress database (replace &lt;span class="caps"&gt;DATABASE&lt;/span&gt; with the wordpress database, if you don&amp;#8217;t know it you can find it in &lt;tt class="docutils literal"&gt;&lt;span class="pre"&gt;wp-config.php&lt;/span&gt;&lt;/tt&gt; under &lt;tt class="docutils literal"&gt;DB_NAME&lt;/tt&gt;):&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="codehilite"&gt;&lt;table class="codehilitetable"&gt;&lt;tr&gt;&lt;td class="linenos"&gt;&lt;div class="linenodiv"&gt;&lt;pre&gt;&lt;span class="normal"&gt;1&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class="code"&gt;&lt;div&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="n"&gt;mysql&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;use&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;DATABASE&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="w"&gt;&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;
&lt;ol class="arabic simple" start="3"&gt;
&lt;li&gt;Update the password running the folowing query (replace &lt;span class="caps"&gt;NEWPASSWORD&lt;/span&gt; with your new password and &lt;span class="caps"&gt;USERNAME&lt;/span&gt; with the username you wish to change the password&amp;nbsp;for):&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="codehilite"&gt;&lt;table class="codehilitetable"&gt;&lt;tr&gt;&lt;td class="linenos"&gt;&lt;div class="linenodiv"&gt;&lt;pre&gt;&lt;span class="normal"&gt;1&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class="code"&gt;&lt;div&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="n"&gt;mysql&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;UPDATE&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;wp_users&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;SET&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;user_pass&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nf"&gt;MD5&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;NEWPASSWORD&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="k"&gt;WHERE&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;user_login&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s1"&gt;&amp;#39;USERNAME&amp;#39;&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="w"&gt;&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div class="section" id="through-ftp-file-edit"&gt;
&lt;h2&gt;Through ftp/file&amp;nbsp;edit&lt;/h2&gt;
&lt;p&gt;If you don&amp;#8217;t have MySQL access you can also reset it by editing your theme&amp;#8217;s functions.php file. Edit the file and insert after the first &amp;lt;?php the folowing(replace &lt;span class="caps"&gt;NEWPASSWORD&lt;/span&gt; with your new&amp;nbsp;password):&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;table class="codehilitetable"&gt;&lt;tr&gt;&lt;td class="linenos"&gt;&lt;div class="linenodiv"&gt;&lt;pre&gt;&lt;span class="normal"&gt;1&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class="code"&gt;&lt;div&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="x"&gt;wp_set_password(&amp;#39;NEWPASSWORD&amp;#39;,1);&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;
&lt;p&gt;After you changed your password make sure you delete the line from functions.php otherwise it will reset your password on every page&amp;nbsp;load.&lt;/p&gt;
&lt;/div&gt;
</content><category term="tech"></category></entry><entry><title>Hello world!</title><link href="https://razius.com/articles/hello-world.html" rel="alternate"></link><published>2011-08-15T09:52:00+02:00</published><updated>2011-08-15T09:52:00+02:00</updated><author><name>Silviu Tantos</name></author><id>tag:razius.com,2011-08-15:/articles/hello-world.html</id><content type="html">&lt;p&gt;After much slacking around and ignoring this blog I decided to give it another spin and bring it back to&amp;nbsp;life.&lt;/p&gt;
&lt;p&gt;It will be mostly technical articles about Linux, system administration and network&amp;nbsp;administration.&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;table class="codehilitetable"&gt;&lt;tr&gt;&lt;td class="linenos"&gt;&lt;div class="linenodiv"&gt;&lt;pre&gt;&lt;span class="normal"&gt;1&lt;/span&gt;
&lt;span class="normal"&gt;2&lt;/span&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class="code"&gt;&lt;div&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;root@crappy:/# &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s1"&gt;&amp;#39;Hello, World!&amp;#39;&lt;/span&gt;
Hello, World!
&lt;/pre&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;
</content><category term="toughts"></category><category term="random"></category></entry></feed>