@ndrewhttps://berezovskyi.me/2023-08-11T00:00:00+02:00Rebasing all relevant pull requests on a Github repo2023-08-11T00:00:00+02:002023-08-11T00:00:00+02:00Andrew Berezovskyitag:berezovskyi.me,2023-08-11:/2023/08/rebasing-all-relevant-pull-requests-on-a-github-repo/<p>If you chose rebasing as your primary git workflow strategy, it becomes important to keep your feature branches updated. Out of the box, Github offers automatic rebasing on many Dependabot pull requests. Dependabot PRs can be further rebased semi-automatically using the <code>@dependabot rebase</code> command issued in the comments.</p>
<p>For all other PRs, you need to set up a bot or a Github Action to do this automatically. One such action that could be used is <code>peter-evans/rebase</code>:</p>
<div class="highlight"><pre><span></span><code><span class="nt">name</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">Rebase</span>
<span class="nt">on</span><span class="p">:</span>
<span class="w"> </span><span class="nt">schedule</span><span class="p">:</span>
<span class="w"> </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="nt">cron</span><span class="p">:</span><span class="w"> </span><span class="s">'40</span><span class="nv"> </span><span class="s">7</span><span class="nv"> </span><span class="s">*</span><span class="nv"> </span><span class="s">*</span><span class="nv"> </span><span class="s">*'</span>
<span class="w"> </span><span class="nt">workflow_dispatch</span><span class="p">:</span>
<span class="nt">jobs</span><span class="p">:</span>
<span class="w"> </span><span class="nt">rebase</span><span class="p">:</span>
<span class="w"> </span><span class="nt">runs-on</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">ubuntu-latest</span>
<span class="w"> </span><span class="nt">steps</span><span class="p">:</span>
<span class="w"> </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="nt">uses</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">peter-evans/rebase@v2</span>
<span class="w"> </span><span class="nt">with</span><span class="p">:</span>
<span class="w"> </span><span class="c1"># token: ${{ secrets.GH_PAT }} </span>
<span class="w"> </span><span class="c1"># exclude-drafts: true …</span></code></pre></div><p>If you chose rebasing as your primary git workflow strategy, it becomes important to keep your feature branches updated. Out of the box, Github offers automatic rebasing on many Dependabot pull requests. Dependabot PRs can be further rebased semi-automatically using the <code>@dependabot rebase</code> command issued in the comments.</p>
<p>For all other PRs, you need to set up a bot or a Github Action to do this automatically. One such action that could be used is <code>peter-evans/rebase</code>:</p>
<div class="highlight"><pre><span></span><code><span class="nt">name</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">Rebase</span>
<span class="nt">on</span><span class="p">:</span>
<span class="w"> </span><span class="nt">schedule</span><span class="p">:</span>
<span class="w"> </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="nt">cron</span><span class="p">:</span><span class="w"> </span><span class="s">'40</span><span class="nv"> </span><span class="s">7</span><span class="nv"> </span><span class="s">*</span><span class="nv"> </span><span class="s">*</span><span class="nv"> </span><span class="s">*'</span>
<span class="w"> </span><span class="nt">workflow_dispatch</span><span class="p">:</span>
<span class="nt">jobs</span><span class="p">:</span>
<span class="w"> </span><span class="nt">rebase</span><span class="p">:</span>
<span class="w"> </span><span class="nt">runs-on</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">ubuntu-latest</span>
<span class="w"> </span><span class="nt">steps</span><span class="p">:</span>
<span class="w"> </span><span class="p p-Indicator">-</span><span class="w"> </span><span class="nt">uses</span><span class="p">:</span><span class="w"> </span><span class="l l-Scalar l-Scalar-Plain">peter-evans/rebase@v2</span>
<span class="w"> </span><span class="nt">with</span><span class="p">:</span>
<span class="w"> </span><span class="c1"># token: ${{ secrets.GH_PAT }} </span>
<span class="w"> </span><span class="c1"># exclude-drafts: true</span>
<span class="w"> </span><span class="nt">exclude-labels</span><span class="p">:</span><span class="w"> </span><span class="p p-Indicator">|</span>
<span class="w"> </span><span class="no">no-rebase</span>
<span class="w"> </span><span class="no">dependencies</span>
</code></pre></div>
<p>The action works reliably and allows to skip all Dependabot PRs (tagged with a <code>dependencies</code> label). The latter is important to do because the Dependabot refuses to automatically update its <span class="caps">PR</span> once you make any manual changes to it, like rebasing it yourself.
The <code>token</code> parameter allows the action to push on your behalf. Otherwise, Github Actions pushes do not trigger other Github Actions (mainly, <span class="caps">CI</span>). This means that you will only be able to know if the code has any conflicts with the <code>main</code> branch, but not whether it is still safe to merge.</p>
<p>If this approach is not viable for you (e.g., you don’t have admin rights on the repo or don’t trust the action with your <span class="caps">PAT</span> token), you need to rebase on your machine. Below I provide a script (licensed under the Simplified <span class="caps">BSD</span> license) that rebases all PRs except those made by Dependabot:</p>
<div class="highlight"><pre><span></span><code><span class="ch">#!/usr/bin/env bash</span>
<span class="c1"># Copyright 2023 Andrew Berezovskyi</span>
<span class="c1"># SPDX-License-Identifier: BSD-2-Clause</span>
<span class="nb">set</span><span class="w"> </span>-uo<span class="w"> </span>pipefail
<span class="nb">set</span><span class="w"> </span>-e
<span class="c1"># set -x</span>
<span class="nv">err</span><span class="o">=</span><span class="m">0</span>
git_main_branch<span class="w"> </span><span class="o">()</span><span class="w"> </span><span class="o">{</span>
<span class="w"> </span><span class="nb">command</span><span class="w"> </span>git<span class="w"> </span>rev-parse<span class="w"> </span>--git-dir<span class="w"> </span><span class="p">&</span>><span class="w"> </span>/dev/null<span class="w"> </span><span class="o">||</span><span class="w"> </span><span class="k">return</span>
<span class="w"> </span><span class="nb">local</span><span class="w"> </span>ref
<span class="w"> </span><span class="k">for</span><span class="w"> </span>ref<span class="w"> </span><span class="k">in</span><span class="w"> </span>refs/<span class="o">{</span>heads,remotes/<span class="o">{</span>origin,upstream<span class="o">}}</span>/<span class="o">{</span>main,trunk,mainline,default<span class="o">}</span>
<span class="w"> </span><span class="k">do</span>
<span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="nb">command</span><span class="w"> </span>git<span class="w"> </span>show-ref<span class="w"> </span>-q<span class="w"> </span>--verify<span class="w"> </span><span class="nv">$ref</span>
<span class="w"> </span><span class="k">then</span>
<span class="w"> </span><span class="nb">echo</span><span class="w"> </span><span class="si">${</span><span class="nv">ref</span><span class="p">:</span><span class="nv">t</span><span class="si">}</span>
<span class="w"> </span><span class="k">return</span>
<span class="w"> </span><span class="k">fi</span>
<span class="w"> </span><span class="k">done</span>
<span class="w"> </span><span class="nb">echo</span><span class="w"> </span>master
<span class="o">}</span>
<span class="k">if</span><span class="w"> </span>!<span class="w"> </span><span class="nb">eval</span><span class="w"> </span>git<span class="w"> </span>diff<span class="w"> </span>--quiet<span class="w"> </span><span class="p">;</span><span class="w"> </span><span class="k">then</span>
<span class="w"> </span>><span class="p">&</span><span class="m">2</span><span class="w"> </span><span class="nb">echo</span><span class="w"> </span><span class="s2">"Git repo is not clean. Commit all the changes first."</span>
<span class="w"> </span><span class="nb">exit</span><span class="w"> </span><span class="m">1</span>
<span class="k">fi</span>
<span class="nv">CURR_BR</span><span class="o">=</span><span class="s2">"</span><span class="k">$(</span>git<span class="w"> </span>branch<span class="w"> </span>--show-current<span class="k">)</span><span class="s2">"</span>
<span class="nv">MAIN_BR</span><span class="o">=</span><span class="s2">"</span><span class="k">$(</span>git_main_branch<span class="k">)</span><span class="s2">"</span>
<span class="nb">trap</span><span class="w"> </span><span class="s1">'git checkout "${CURR_BR}"'</span><span class="w"> </span>err<span class="w"> </span><span class="nb">exit</span><span class="w"> </span>SIGINT<span class="w"> </span>SIGTERM
git<span class="w"> </span>checkout<span class="w"> </span><span class="s2">"</span><span class="si">${</span><span class="nv">MAIN_BR</span><span class="si">}</span><span class="s2">"</span>
git<span class="w"> </span>pull<span class="w"> </span>--ff-only
<span class="nv">PR_LIST</span><span class="o">=</span><span class="s2">"</span><span class="k">$(</span>sort<span class="w"> </span><<span class="o">(</span>gh<span class="w"> </span>pr<span class="w"> </span>list<span class="k">)</span><span class="s2"> <(gh pr list -A app/dependabot) | uniq -u | cut -f1)"</span>
<span class="k">while</span><span class="w"> </span><span class="nv">IFS</span><span class="o">=</span><span class="s2">""</span><span class="w"> </span><span class="nb">read</span><span class="w"> </span>-r<span class="w"> </span>pr<span class="w"> </span><span class="o">||</span><span class="w"> </span><span class="o">[</span><span class="w"> </span>-n<span class="w"> </span><span class="s2">"</span><span class="nv">$pr</span><span class="s2">"</span><span class="w"> </span><span class="o">]</span>
<span class="k">do</span>
<span class="w"> </span><span class="nb">printf</span><span class="w"> </span><span class="s1">'Processing PR #%s\n'</span><span class="w"> </span><span class="s2">"</span><span class="nv">$pr</span><span class="s2">"</span>
<span class="w"> </span>gh<span class="w"> </span>pr<span class="w"> </span>checkout<span class="w"> </span><span class="s2">"</span><span class="nv">$pr</span><span class="s2">"</span><span class="w"> </span><span class="o">||</span><span class="w"> </span><span class="nv">err</span><span class="o">=</span><span class="nv">$?</span>
<span class="w"> </span><span class="c1"># --reapply-cherry-picks if needed</span>
<span class="w"> </span><span class="c1"># https://stackoverflow.com/questions/61905448/git-cherry-pick-and-then-rebase</span>
<span class="w"> </span><span class="o">[</span><span class="w"> </span><span class="s2">"</span><span class="nv">$err</span><span class="s2">"</span><span class="w"> </span>-eq<span class="w"> </span><span class="s2">"128"</span><span class="w"> </span><span class="o">]</span><span class="w"> </span><span class="o">&&</span><span class="w"> </span>git<span class="w"> </span>rebase<span class="w"> </span>
<span class="w"> </span><span class="c1"># rebase -i if needed</span>
<span class="w"> </span>git<span class="w"> </span>rebase<span class="w"> </span><span class="s2">"</span><span class="si">${</span><span class="nv">MAIN_BR</span><span class="si">}</span><span class="s2">"</span><span class="w"> </span><span class="o">&&</span><span class="w"> </span>git<span class="w"> </span>pull<span class="w"> </span>--rebase<span class="w"> </span>origin<span class="w"> </span><span class="s2">"</span><span class="si">${</span><span class="nv">MAIN_BR</span><span class="si">}</span><span class="s2">"</span><span class="w"> </span><span class="o">&&</span><span class="w"> </span>git<span class="w"> </span>push<span class="w"> </span>--force-with-lease
<span class="k">done</span><span class="w"> </span><span class="o"><<<</span><span class="w"> </span><span class="s2">"</span><span class="si">${</span><span class="nv">PR_LIST</span><span class="si">}</span><span class="s2">"</span>
</code></pre></div>
<p>Some explanation for the script:</p>
<ul>
<li><code>git pull --ff-only</code> is done under the assumption that you don’t commit to the main branch yourself and thus, no conflicts should ever exist on that branch.</li>
<li><code>git_main_branch()</code> allows the script to be used with the repos that use <code>main</code>, <code>master</code>, or <code>trunk</code> main branch.</li>
<li><code>sort X Y | uniq -u</code> pattern is used because Github has a bad support for negative patterns as of 2023.</li>
<li><code>git push --force-with-lease</code> prevents you from overwriting any commits during a force-push that were made by someone else, thus providing some degree of safety.</li>
<li><code>[ "$err" -eq "128" ] && git rebase</code> is done to rebase your local feature branch first, in case someone else made a similar rebase before you.</li>
<li><code>trap "git checkout '${CURR_BR}'"</code> will restore the checked out branch you were on before running the script (whether the scripts succeeds or fails).</li>
<li><code>set -u</code> makes the script fail if any undefined variables are used, <code>set -o pipefail</code> makes a piped command fail if any of its stages fail (e.g. if gzip fails in <code>tar | gzip | gpg</code>), <code>set -e</code> terminates the script immediately after the first error, and <code>set -x</code> could be used to print every command that this script runs.</li>
</ul>
<p>You can make the script available anywhere in your system if you put the script under <code>/usr/local/bin/</code> (or <code>$HOME/.local/bin</code> just for your user account) and make it executable: <code>chmod +x /usr/local/bin/git-rebase-all</code>.</p>
<p>Finally, this script only requires the <a href="https://cli.github.com/">Github <span class="caps">CLI</span></a> and plain old Bash to be installed on your system for this to work. Happy rebasing! 🦸♂️</p>Notes from “The Innovator’s Dilemma” by Clayton M. Christensen2017-04-30T00:00:00+02:002017-04-30T00:00:00+02:00Andrew Berezovskyitag:berezovskyi.me,2017-04-30:/2017/04/notes-from-the-innovators-dilemma-by-clayton-m-christensen/<blockquote>
<p>The book is really good for people who are skeptical of the startup scene, both from the side of starting one (i.e. despising startup creation just for the <em>sake of creating a startup</em>) as well as for those in a managerial position in established companies, thinking that they produce by all means a <em>superior product</em>. While both of them are seemingly right, the market forces might decide otherwise.</p>
</blockquote>
<p><a class="imagelink" href="https://www.goodreads.com/book/show/17290916-the-innovator-s-dilemma"><img alt="" src="https://berezovskyi.me/static/2017/04-innovators-dilemma/cover.jpg" /></a></p>
<p>So the first thing the book dismisses is the <em>lack of competence</em> within the enterprise to develop a technically competitive solution. Actually, it was usually the other way around – the very …</p><blockquote>
<p>The book is really good for people who are skeptical of the startup scene, both from the side of starting one (i.e. despising startup creation just for the <em>sake of creating a startup</em>) as well as for those in a managerial position in established companies, thinking that they produce by all means a <em>superior product</em>. While both of them are seemingly right, the market forces might decide otherwise.</p>
</blockquote>
<p><a class="imagelink" href="https://www.goodreads.com/book/show/17290916-the-innovator-s-dilemma"><img alt="" src="https://berezovskyi.me/static/2017/04-innovators-dilemma/cover.jpg" /></a></p>
<p>So the first thing the book dismisses is the <em>lack of competence</em> within the enterprise to develop a technically competitive solution. Actually, it was usually the other way around – the very first prototypes of the solutions that would disrupt the market in the coming decade were often conceived within the very organisations toppled by those disruptive innovations. Those prototypes were usually demonstrated to the management and dismissed.</p>
<p>Second, the concept of <em>innovation</em> is split into that of a <em>disruptive innovation</em> and a <em>sustaining innovation</em>. Both innovations change the way things are done today and render old solutions obsolete. However, a <em>sustaining innovation</em> represents an improvement (sometimes extraordinarily difficult) over a known technology (e.g. more TBs per drive platter, less diesel engine emissions etc.), while a <em>disruptive innovation</em> represents an alternative way to solve a customer problem, sometimes even using a mediocre solution with subpar performance.</p>
<p>And that is where the attention is drawn to the fact that <em>organisational processes and values</em> drive <em>very good managers</em> to take the <em>decisions that make sense</em>. Those decisions are to discard the disruptive technology that provides worse performance, has a smaller market and thus lower margins in favour of investing in the existing technology. The existing technology is in high demand by the key customers, and improvements to it promise great revenues.</p>
<p>This is where the discussion of <em>resource dependence</em> starts. Turns out, managers (even including the <span class="caps">CEO</span>) who are able to see that an emerging technology is likely to be the <em>next big thing</em> within a decade are not able to fight the internal company process of investing into the most profitable projects. Another aspect is that for a publicly traded company, their shares are valued on the YoY revenue growth and the larger the company becomes, the smaller fraction of this <em>needed growth</em> a disruptive technology project can provide.</p>
<p>The real problem is that in most fields a <em>technology oversupply</em> exists. The book suggests that this and the emergence of the disruptive technology cause a <em>change in the basis of competition</em>. For example, a desktop user needs a hard drive. Companies compete hard to deliver a drive with a bigger capacity. At some point though, say, <span class="caps">1TB</span> (in 2017) is plenty for most users and they are no longer excited twice as much over a <span class="caps">2TB</span> drive. Instead, they want the size to reduce. Then, the speed to go up. The book explains that it causes the <em>shadow prices</em> for certain features to reduce dramatically, and it fundamentally affects the margins on the established products.</p>
<p>One solution to this problem often employed by the enterprises is to move upmarket: keep making better products but sell them instead to richer customers ready to pay more. The book suggests that this strategy didn’t work for many companies who went out of business (e.g. manufacturers of 5.25” HDDs etc.). Instead, it is sometimes best to create a small organisation outside the parent enterprise to work on a disruptive technology, finding a new market for it in its current form in order to turn a profit far before it takes over the big market.</p>
<p>The book concludes with an imaginary case study of evaluating how disruptive an electric vehicle (<span class="caps">EV</span>) could be for a typical manufacturer. Spoiler: in the late 90s, when the book was written, Prof. Christensen drew a figure showing how <span class="caps">EV</span> technology develops faster than the consumer demand for speed (limited by the law) and range (100 miles is what most people would need). Surprise surprise, EVs took <a href="https://archive.is/cTwYc">37% of sales volume in 2016 in Norway</a>.</p>Notes from “Serve to win” by Novak Djokovic2017-01-22T00:00:00+01:002017-01-22T00:00:00+01:00Andrew Berezovskyitag:berezovskyi.me,2017-01-22:/2017/01/notes-from-serve-to-win-by-novak-djokovic/<blockquote>
<p>I really enjoyed the book, it was very refreshing to read about the life
of a top athlete outside the training ground. Usually they brag about
super special training schedule and top teams supporting them, but this
book was about everything except that.</p>
</blockquote>
<p><a class="imagelink" href="https://www.goodreads.com/book/show/17910549-serve-to-win"><img alt="" src="https://berezovskyi.me/static/2017/01-serve-to-win/cover.jpg" /></a></p>
<p>“Sitting in a tiny living room […], I watched Pete
Sampras win the Wimbledon and I knew: one day that would be me” (p. xvi)</p>
<p>To test if you are sensitive to gluten, he suggests to
keep it off your menu for 2 weeks and then eat it for one day and see if
you see any difference …</p><blockquote>
<p>I really enjoyed the book, it was very refreshing to read about the life
of a top athlete outside the training ground. Usually they brag about
super special training schedule and top teams supporting them, but this
book was about everything except that.</p>
</blockquote>
<p><a class="imagelink" href="https://www.goodreads.com/book/show/17910549-serve-to-win"><img alt="" src="https://berezovskyi.me/static/2017/01-serve-to-win/cover.jpg" /></a></p>
<p>“Sitting in a tiny living room […], I watched Pete
Sampras win the Wimbledon and I knew: one day that would be me” (p. xvi)</p>
<p>To test if you are sensitive to gluten, he suggests to
keep it off your menu for 2 weeks and then eat it for one day and see if
you see any difference in your performance before doing <span class="caps">ELISA</span> tests or
consulting doctors. Afterwards he recommends the same experiment for
dairy (the one without yoghurt cultures, e.g. acidophilus) and sugar
(i.e. sucrose, not fructose) (p. xxv).</p>
<p>In the section titled “The Art of Discipline” he talks
about how almost every minute of his day is scheduled by his team and
that is the only way to beat the best of the best. He emphasises the
need to sleep same amount of time at the same time every day over any
other part of his schedule (pp. 16, 91). For that reason he cut on
caffeine except in gel form before the match. He explains it with the
following table of the Chinese view on body recovery functions (p. 28):</p>
<ul>
<li>23:00 – 3:00 liver (good time to be asleep)</li>
<li>3:00 – 5:00 lungs</li>
<li>5:00 – 7:00 intestine</li>
<li>7:00 – 9:00 stomach (good time to have breakfast)</li>
</ul>
<p>Next he “takes down” wheat and gluten it contains. He
argues that most of the modern wheat and products containing it are <span class="caps">GMO</span>
modified. He also argues that most of us have some degree of non-celiac
wheat sensitivity and it can just make us feel stuffed and slow.
Finally, he suggests reducing wheat consumption because of its high
glycemic index, which determines how quickly the food causes a spike in
our blood sugar (p. 36).</p>
<p>After that the book does the same for
lactose-containing products, warning us of finding a way to substitute
its calcium contents. If we can’t give up on dairy, Novak suggests that
we consume as much as possible with yoghurt cultures, e.g. acidophilus.
He also points out that most yogurts contain insane amounts of sugar (p. 50).</p>
<p>So how do we feed ourselves then? Djokovic suggests
many things but I noted a few that I already eat (or can easily start
eating) (pp. 52, 156):</p>
<ul>
<li>Oatmeal, buckwheat, millet</li>
<li>Meat, fish, eggs</li>
<li>Healthy oils</li>
<li>Salads</li>
</ul>
<p>He suggests leaving proteins for the evening though.</p>
<p>He also tells us that our body reacts to every “signal”
we send it, like whether we eat fast or not, whether we are distracted
or not during the lunchtime. He prefers to eat calmly and quietly (p. 58).</p>
<p>Next advice goes back to the morning routine. Djokovic
does these things in the morning (pp. 67, 99):</p>
<ul>
<li>A glass of warm (so that stomach doesn’t draw much
blood to warm it up) water first thing.</li>
<li>Two spoons of honey (he likes mānuka honey most).</li>
<li>Some cardio warm-up.</li>
<li>Usual stretching like we did in <span class="caps">PT</span> classes.</li>
<li>Never skips breakfast.</li>
</ul>
<p>He also insists on getting a massage at least once a month and
getting a <em>foam roller</em> for the rest of the month. Another idea of his is to use
yoga and intellectually stimulating activities to push our mind in a
same manner as we push our bodies (p. 99).</p>
<p>Aside from eating all kinds of fruits, he also allows
peanut butter (not the Skippy kind but the one without sugar or
additives). He also takes protein supplements from rice and peas. He
flies frequently and takes melatonin supplements to balance his sleep.</p>
<p>Finally, he reminds us that healthy body and mind are not
self-goal but <strong>gateways to success</strong> (p. 145).</p>Deep Work notes2017-01-09T00:00:00+01:002017-01-09T00:00:00+01:00Andrew Berezovskyitag:berezovskyi.me,2017-01-09:/2017/01/deep-work-notes/<blockquote>
<p>I read a handful of self-help books in the past years. Due to a number of reasons, I didn’t have a chance to apply many of the techniques that seemed useful at a time, so I want to catalogue them in 2017 for my future reference. This is the second summary in the series after <a href="https://berezovskyi.me/2015/03/review-hbr-guide-to-getting-the-right-work-done/"><span class="caps">HBR</span> Guide to Getting the Right Work Done</a>.</p>
</blockquote>
<p><a class="imagelink" href="https://www.goodreads.com/book/show/29433560-deep-work"><img alt="" src="https://berezovskyi.me/static/2017/01-deep_work/deep-work-rules-for-focused-success-in-a-distracted-world_1_fullsize.jpg" /></a></p>
<blockquote>
<p>My apologies in advance if you expected a gist of the book that would let you skip reading it altogether. This would require much more work and serve no additional purpose for me as a refresher …</p></blockquote><blockquote>
<p>I read a handful of self-help books in the past years. Due to a number of reasons, I didn’t have a chance to apply many of the techniques that seemed useful at a time, so I want to catalogue them in 2017 for my future reference. This is the second summary in the series after <a href="https://berezovskyi.me/2015/03/review-hbr-guide-to-getting-the-right-work-done/"><span class="caps">HBR</span> Guide to Getting the Right Work Done</a>.</p>
</blockquote>
<p><a class="imagelink" href="https://www.goodreads.com/book/show/29433560-deep-work"><img alt="" src="https://berezovskyi.me/static/2017/01-deep_work/deep-work-rules-for-focused-success-in-a-distracted-world_1_fullsize.jpg" /></a></p>
<blockquote>
<p>My apologies in advance if you expected a gist of the book that would let you skip reading it altogether. This would require much more work and serve no additional purpose for me as a refresher.</p>
</blockquote>
<h2 id="part-1-or-setting-the-stage">Part 1, or Setting The Stage<a class="headerlink" href="#part-1-or-setting-the-stage" title="Permanent link">¶</a></h2>
<h3 id="chapter-1">Chapter 1<a class="headerlink" href="#chapter-1" title="Permanent link">¶</a></h3>
<ul>
<li>Consumer tools like iPad are easy to use, but the work behind them is increasingly more complex (p. 29) and those tools are unlikely to aid us in this complexity (p. 31).</li>
<li>Many people knew Ruby, but only <span class="caps">DHH</span> created Ruby on Rails (p. 32).</li>
<li>Newport paraphrases Sertillanges to say that we must study something systematically if we need to advance our understanding of relevant fields (p. 33).</li>
<li>All this leads to the idea of <em>deliberate effort</em> vs. having information at your fingertips (p. 34).</li>
<li>Then the problem of multitasking is raised (p. 42), where Newport argues (supported by some references) that if interrupted, not only we need extra time to go back to the original task, but also we bring <em>attention residue</em> to the new task, <strong>effectively not giving it our full attention because we keep thinking about the interrupted work</strong>.</li>
<li>On p. 43 he argues that proper efforts can increase our impactful output by a factor of 10.</li>
</ul>
<h3 id="chapter-2">Chapter 2<a class="headerlink" href="#chapter-2" title="Permanent link">¶</a></h3>
<ul>
<li>Deep concentrated work benefits are hard to measure, so business doesn’t pay much attention to supporting their employees (p. 53)</li>
<li>Also, he argues that proper planning involves many steps (like <a href="https://christophdollis.com/marketing/time/GTD-quick-reference-card.pdf"><span class="caps">GTD</span></a>), so people resort to email that defines their agenda (p. 59).</li>
</ul>
<h3 id="chapter-3">Chapter 3<a class="headerlink" href="#chapter-3" title="Permanent link">¶</a></h3>
<p>Here he tries to convince us that the efforts described in the book will not only be effective but rewarding:</p>
<ul>
<li>Flow research on p. 84</li>
<li>Gallaher research on p. 85</li>
<li>Craftsmanship ideas on p. 89</li>
</ul>
<h2 id="part-2-or-getting-the-sht-done">Part 2, or Getting The Sh*t Done<a class="headerlink" href="#part-2-or-getting-the-sht-done" title="Permanent link">¶</a></h2>
<h3 id="rule-1-work-deeply-or-the-101-of-productivity">Rule #1: Work Deeply or The 101 of Productivity<a class="headerlink" href="#rule-1-work-deeply-or-the-101-of-productivity" title="Permanent link">¶</a></h3>
<ul>
<li>Opens with the discussion of the Eudaimonia Machine (<a href="https://www.linkedin.com/pulse/den-ultimata-arbetsplatsen-eudaimonia-machine-henrik-persson-grubb">notes on this</a>)</li>
<li>We can’t just lock ourselves in this “perfect room” and make perfect work (p. 98).</li>
<li>It is due to the fact that our mind is filled with desires all day (p. 99).</li>
<li>Routines and rituals should help us overcome this problem (p. 100).</li>
<li>There are two main approaches to deep work: monk-style (fully eliminate what is less than important) and chunk-style (limit when we allow busyness in our lives). Most of can’t go monk-style for a number of reasons (p. 102).</li>
<li>To keep those deep work chunks consistent, we can use <em>chain method</em>: we commit to deep work under certain conditions (e.g. every weekday from 9 to 11) and keep track how many consecutive times we stuck to the commitment (p. 110).</li>
<li>90-minute chuck might be a good starting point for your experiments (p. 112).</li>
<li>You might need to develop an ability to switch to deep work whenever you have time like journalists do (p. 117)</li>
<li>For this, you might want to think ahead what exactly will you do when you get a chance to concentrate (p. 120).</li>
<li><strong><span class="dquo">“</span>Great creative minds think like artists but work like accountants”</strong> (p. 119).</li>
<li>It’s not necessary to think in the closed room. Newport was thinking about his PhD on the go all the time (pp. 121, 144, 170).</li>
<li>If you are struggling to make progress, try changing the environment (p. 123).</li>
<li>Deep work does not preclude collaboration. <em>Hub and spoke</em> model is discussed on p. 132.</li>
<li><span class="caps">4DX</span> framework (p. 136):<ul>
<li>More work means less focus. Practice laser focus.</li>
<li>Keep lead (e.g. number of new bugs this week) and lag (e.g. number of 5-star reviews last month) measures of your work.</li>
<li>Track your deep work and important achievements.</li>
<li>Do your own “performance reviews”.</li>
</ul>
</li>
</ul>
<p>He also talks about taking a break:</p>
<ul>
<li>To combat <em>attention residue</em>, walk in a low-distraction environment (e.g. a quiet park) for 50 minutes. If keep alert during this time, it won’t work. But the place doesn’t have to be nice and cosy (experiment worked even when it was cold outside, see p. 147).</li>
<li>When you finish your day, it’s important to convince your brain that you can pick up the work tomorrow and there is nothing to worry about. He suggests a form of “brain dump” (p. 151) with actionable points at the end of the day as well as a plan for tomorrow (p. 152).</li>
</ul>
<h3 id="rule-2-embrace-boredom-or-how-to-make-deep-work-the-default-state-and-rule-3-quit-social-networks-or-only-pick-the-tools-that-offer-far-more-than-they-require-in-return">Rule #2: Embrace Boredom or How to make deep work the default state and Rule #3: Quit social networks or Only pick the tools that offer far more than they require in return<a class="headerlink" href="#rule-2-embrace-boredom-or-how-to-make-deep-work-the-default-state-and-rule-3-quit-social-networks-or-only-pick-the-tools-that-offer-far-more-than-they-require-in-return" title="Permanent link">¶</a></h3>
<ul>
<li>We are not just getting distracted by notifications and stuff: we are at <span class="caps">WAR</span> with the social media and notification-driven apps, because they are designed to be addictive (if you think it’s a joke, read <a href="https://www.goodreads.com/book/show/22668729-hooked">Hooked: How to Build Habit-Forming Products</a>).</li>
<li>We tend to underestimate the time we spend on things. <span class="caps">UK</span> youth spent around 10 hours a week more than it thought (meters recorded 28h vs 15h estimated in the questionnaires).</li>
<li>The main approach is to use only tools that have far more benefit than the amount effort/resources they require from you (p. 187, 191).</li>
<li>When you want to procrastinate or just need to use those tools, set yourself an allowance and make sure they don’t creep in your work chunks (e.g. check your email every 45 minutes vs enabling notifications, p. 163).</li>
</ul>
<h3 id="rule-4-drain-the-shallows-or-how-to-ditch-all-commitments-that-are-not-beneficial-for-you">Rule #4: Drain the shallows or How to ditch all commitments that are not beneficial for you<a class="headerlink" href="#rule-4-drain-the-shallows-or-how-to-ditch-all-commitments-that-are-not-beneficial-for-you" title="Permanent link">¶</a></h3>
<ul>
<li>Usually, there are no more than 4 hours of deep work you can do well every day (p. 220).</li>
<li>To make the best use of your workday and reflect on wasted time, <strong>set yourself a daily schedule and record the actual one</strong>, but instead of checking how well you stuck to it, check whether things you did instead were more important (pp. 222, 227).</li>
<li>How to measure important work? Estimate how many months will it take an intern to learn how to do it for you! (p. 231).</li>
<li>You need to stop somewhere. Set yourself a daily limit. You might think that it’s impossible, but you can do more work per hour if you commit to X hours of work a day. Self-praise and motivating examples on p. 236.</li>
<li>If anybody asks you for some commitment that would require you to either shift priorities against the importance of the work or work more than X hours, find a way to ditch that commitment. Common excuses on p. 264.</li>
<li>When you communicate with people, think not about what is going to answer the question of your colleague, but what is going to help him to stop asking further questions (p. 249).</li>
<li>If the email is badly composed (hard to understand, requires additional research) and nothing will set on fire if you’ll ignore it, then just ignore that email.</li>
</ul>Installing Redis from source on ARM2015-10-25T02:10:00+01:002015-10-25T02:10:00+01:00Andrew Berezovskyitag:berezovskyi.me,2015-10-25:/2015/10/redis-on-arm/<p>Ubuntu has quite old packages in the default repositories. It is especially
important for web development, where version compatibility may break often.</p>
<p>ownCloud requires a modern version of Redis to use it as a cache and to keep
track of the file locks.</p>
<p>PPAs that provide Redis packages do not build for the <span class="caps">ARM</span> arch, however. Therefore,
with my new <a class="reference external" href="https://www.scaleway.com">Scaleway</a> server, I’ll have to do it
by hand:</p>
<pre class="code literal-block">
apt build-essential
apt libjemalloc-dev
</pre>
<p>Here, <cite>apt</cite> is my handy <cite>alias apt=”sudo apt-get install”</cite>. If you ran into
<cite>jemalloc</cite> problems before this article, be sure to perform a <cite>distclean</cite> before …</p><p>Ubuntu has quite old packages in the default repositories. It is especially
important for web development, where version compatibility may break often.</p>
<p>ownCloud requires a modern version of Redis to use it as a cache and to keep
track of the file locks.</p>
<p>PPAs that provide Redis packages do not build for the <span class="caps">ARM</span> arch, however. Therefore,
with my new <a class="reference external" href="https://www.scaleway.com">Scaleway</a> server, I’ll have to do it
by hand:</p>
<pre class="code literal-block">
apt build-essential
apt libjemalloc-dev
</pre>
<p>Here, <cite>apt</cite> is my handy <cite>alias apt=”sudo apt-get install”</cite>. If you ran into
<cite>jemalloc</cite> problems before this article, be sure to perform a <cite>distclean</cite> before
re-attempting a new build:</p>
<pre class="code literal-block">
make distclean
make
</pre>
<p>If this fails as well, then try the <cite>libc</cite> allocator:</p>
<pre class="code literal-block">
make distclean
MALLOC=libc make
</pre>
<p>But I had success with the default allocator, so most probably you won’t
have to resort to this hack.</p>
<p>After a successful build, be sure to run <cite>make test</cite> that should give you a
similar output:</p>
<img alt="unit tests on ARM" src="https://berezovskyi.me/static/2015/redis/tests.png" />
<p>Whoa, easy, Redis! Did you just call my quad-core <span class="caps">ARM</span> server a <em>slow</em> computer?</p>
<p>I had a stack trace generation test failure but I ignored it and went ahead as
it is just a logging feature:</p>
<pre class="code literal-block">
sudo make install
sudo ./utils/install_server.sh
</pre>
<p>The server should be running, you can restart it this way:</p>
<pre class="code literal-block">
sudo service redis_6379 restart
</pre>
<p>Finally, the Redis client for <span class="caps">PHP</span> needs to be updated (once other
packages get updated, it might be the only thing you might need to do):</p>
<pre class="code literal-block">
apt-get install php-pear php5-dev libpcre3-dev
pear upgrade -Z
pecl install -Z redis
</pre>
<p>Ignore the segfault (it seems to be a known bug, having its roots in the <span class="caps">PHP</span>
itself), as the packages were upgraded successfully.</p>
<p>You may need to <cite>service php5-fpm restart</cite> by hand.</p>
C/C++ based projects on resin.io2015-05-31T20:22:00+02:002015-05-31T20:22:00+02:00Andrew Berezovskyitag:berezovskyi.me,2015-05-31:/2015/05/c-cpp-based-projects-on-resin-io/<p>I learned about <a class="reference external" href="https://resin.io/">resin.io</a> long time ago (thanks to my
friend <a class="reference external" href="https://twitter.com/shaunrmulligan">Shaun Mulligan</a> from <em>resin.io</em>)
but didn’t dare to try it out for a long time. Maybe, because most of the
examples were in Node.js and targeted Raspberry Pi. At the time, I was doing a
project in <em>ad-hoc and wireless sensor networks</em> and implemented it using the
Beaglebone Black, Arduino, an <span class="caps">LWIR</span> camera (in my case, <a class="reference external" href="http://www.flir.com/cores/content/?id=66257"><span class="caps">FLIR</span> Lepton</a>), a reed switch and a pair of
XBee modules. I used C/C++ on Beaglebone and with a partner we used
Python/Django on Heroku.</p>
<p>By the …</p><p>I learned about <a class="reference external" href="https://resin.io/">resin.io</a> long time ago (thanks to my
friend <a class="reference external" href="https://twitter.com/shaunrmulligan">Shaun Mulligan</a> from <em>resin.io</em>)
but didn’t dare to try it out for a long time. Maybe, because most of the
examples were in Node.js and targeted Raspberry Pi. At the time, I was doing a
project in <em>ad-hoc and wireless sensor networks</em> and implemented it using the
Beaglebone Black, Arduino, an <span class="caps">LWIR</span> camera (in my case, <a class="reference external" href="http://www.flir.com/cores/content/?id=66257"><span class="caps">FLIR</span> Lepton</a>), a reed switch and a pair of
XBee modules. I used C/C++ on Beaglebone and with a partner we used
Python/Django on Heroku.</p>
<p>By the time I was done with the project and <em>resin.io</em> announced the <a class="reference external" href="https://resin.io/blog/blog-for-swag/">#blog4swag</a> competition, they supported Beaglebone
Black as well. So I decided to see how hard can it be to port a small part of
the project to use <em>resin.io</em>?</p>
<blockquote>
Here I must say that after I edited the <cite>.img</cite> file to grant myself <span class="caps">SSH</span>
access to the host <span class="caps">OS</span> and edited the <span class="caps">DTB</span> files, I still couldn’t manage to
enable the <span class="caps">SPI</span> on the Beaglebone that was then running Yocto Linux built by
<em>resin.io</em>. Thus, the rest of the article will cover the setup on Rasperry
Pi B+.</blockquote>
<p>As I wanted to try porting the application with a minimal effort, I decided to
use the original repository, hence the established directory structure.</p>
<p>I started off by adding a <cite>Dockerfile</cite> to the root directory.</p>
<pre class="code text literal-block">
FROM resin/rpi-raspbian:wheezy
RUN apt-get update && apt-get install -y jp2a make imagemagick gcc-4.7 g++-4.7 python2.7
# RUN apt-get install -y cmake libcurl4-openssl-dev libopencv-dev
COPY . /app
WORKDIR /app/sample/lepton-pgm
RUN CC=gcc-4.7 make
CMD modprobe spi-dev
CMD python server.py
</pre>
<p>There are two interesting parts in the Dockerfile above:</p>
<ol class="arabic simple">
<li><cite><span class="caps">RUN</span></cite> statements are executed on the <em>resin.io</em> servers and can be cached to
speed up subsequent builds. <cite><span class="caps">CMD</span></cite> statements are executed on the device when
the container is run.</li>
<li><span class="caps">SPI</span> is enabled via the <cite>modprobe spi-dev</cite> command.</li>
</ol>
<p>As I wrote before, the original project streamed the data to a Heroku dyno.
However, I was pleasantly surprised to know that <em>resin.io</em> offers the port
forwarding to the nodes even behind the <span class="caps">NAT</span>, so for my simplistic need I no
longer required the cloud-based server.</p>
<p>Instead, I wrote a simple script in Python:</p>
<pre class="code python literal-block">
<span class="ch">#!/usr/bin/env python</span><span class="w">
</span><span class="kn">from</span> <span class="nn">SimpleHTTPServer</span> <span class="kn">import</span> <span class="n">SimpleHTTPRequestHandler</span><span class="w">
</span><span class="kn">import</span> <span class="nn">SocketServer</span><span class="w">
</span><span class="kn">import</span> <span class="nn">subprocess</span><span class="w">
</span><span class="kn">import</span> <span class="nn">urlparse</span><span class="w">
</span><span class="n">PORT</span> <span class="o">=</span> <span class="mi">8080</span><span class="w">
</span><span class="k">class</span> <span class="nc">AsciiHandler</span><span class="p">(</span><span class="n">SimpleHTTPRequestHandler</span><span class="p">):</span><span class="w">
</span> <span class="k">def</span> <span class="nf">do_GET</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span><span class="w">
</span> <span class="n">parsedParams</span> <span class="o">=</span> <span class="n">urlparse</span><span class="o">.</span><span class="n">urlparse</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">path</span><span class="p">)</span><span class="w">
</span> <span class="c1"># request is either for a file to be served up or our page</span><span class="w">
</span> <span class="k">if</span> <span class="n">parsedParams</span><span class="o">.</span><span class="n">path</span> <span class="o">==</span> <span class="s2">"/"</span><span class="p">:</span><span class="w">
</span> <span class="bp">self</span><span class="o">.</span><span class="n">send_response</span><span class="p">(</span><span class="mi">200</span><span class="p">)</span><span class="w">
</span> <span class="bp">self</span><span class="o">.</span><span class="n">send_header</span><span class="p">(</span><span class="s1">'Content-Type'</span><span class="p">,</span> <span class="s1">'text/html'</span><span class="p">)</span><span class="w">
</span> <span class="bp">self</span><span class="o">.</span><span class="n">end_headers</span><span class="p">()</span><span class="w">
</span> <span class="bp">self</span><span class="o">.</span><span class="n">wfile</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s2">"<!DOCTYPE html>"</span><span class="p">);</span><span class="w">
</span> <span class="bp">self</span><span class="o">.</span><span class="n">wfile</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s2">"<html><head></head><body><pre>"</span><span class="p">);</span><span class="w">
</span> <span class="n">proc</span> <span class="o">=</span> <span class="n">subprocess</span><span class="o">.</span><span class="n">Popen</span><span class="p">([</span><span class="s1">'./show_ascii'</span><span class="p">],</span> <span class="n">stdout</span><span class="o">=</span><span class="n">subprocess</span><span class="o">.</span><span class="n">PIPE</span><span class="p">)</span><span class="w">
</span> <span class="k">while</span> <span class="kc">True</span><span class="p">:</span><span class="w">
</span> <span class="n">line</span> <span class="o">=</span> <span class="n">proc</span><span class="o">.</span><span class="n">stdout</span><span class="o">.</span><span class="n">readline</span><span class="p">()</span><span class="w">
</span> <span class="k">if</span> <span class="n">line</span> <span class="o">!=</span> <span class="s1">''</span><span class="p">:</span><span class="w">
</span> <span class="bp">self</span><span class="o">.</span><span class="n">wfile</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="n">line</span><span class="p">)</span><span class="w">
</span> <span class="k">else</span><span class="p">:</span><span class="w">
</span> <span class="k">break</span><span class="w">
</span> <span class="bp">self</span><span class="o">.</span><span class="n">wfile</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s2">"</pre>"</span><span class="p">)</span><span class="w">
</span> <span class="bp">self</span><span class="o">.</span><span class="n">wfile</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s2">"<br><img src='image.png'>"</span><span class="p">)</span><span class="w">
</span> <span class="bp">self</span><span class="o">.</span><span class="n">wfile</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s2">"</body></html>"</span><span class="p">)</span><span class="w">
</span> <span class="bp">self</span><span class="o">.</span><span class="n">wfile</span><span class="o">.</span><span class="n">close</span><span class="p">()</span><span class="w">
</span> <span class="k">else</span><span class="p">:</span><span class="w">
</span> <span class="n">SimpleHTTPRequestHandler</span><span class="o">.</span><span class="n">do_GET</span><span class="p">(</span><span class="bp">self</span><span class="p">)</span><span class="w">
</span><span class="n">httpd</span> <span class="o">=</span> <span class="n">SocketServer</span><span class="o">.</span><span class="n">TCPServer</span><span class="p">((</span><span class="s2">""</span><span class="p">,</span> <span class="n">PORT</span><span class="p">),</span> <span class="n">AsciiHandler</span><span class="p">)</span><span class="w">
</span><span class="nb">print</span> <span class="s2">"serving at port"</span><span class="p">,</span> <span class="n">PORT</span><span class="w">
</span><span class="n">httpd</span><span class="o">.</span><span class="n">serve_forever</span><span class="p">()</span>
</pre>
<p>Here we could have made port number a parameter but <em>resin.io</em> doesn’t allow a
port other than 80 or 8080 to be forwarded, thus it makes little sense to do so.</p>
<p>The <span class="caps">SPI</span> interaction happens in the subprocess call. This script was originally
used for the debugging purposes in the project (this is why the image was
converted to an <span class="caps">ASCII</span>-art, so that the camera output can be viewed over the <span class="caps">SSH</span>
or serial connection):</p>
<pre class="code bash literal-block">
<span class="ch">#!/bin/bash
</span><span class="w">
</span>./raspberry_pi_capture<span class="w">
</span>convert<span class="w"> </span>image.pgm<span class="w"> </span>-depth<span class="w"> </span><span class="m">16</span><span class="w"> </span>-resize<span class="w"> </span><span class="m">400</span>%<span class="w"> </span>image.png<span class="w">
</span>convert<span class="w"> </span>image.pgm<span class="w"> </span>-depth<span class="w"> </span><span class="m">16</span><span class="w"> </span>jpg:-<span class="w"> </span><span class="p">|</span><span class="w"> </span>jp2a<span class="w"> </span>-<span class="w"> </span>--width<span class="o">=</span><span class="m">80</span>
</pre>
<p>The image is enlarged so much due to the relatively low resolution of the <span class="caps">LWIR</span>
camera (80 by 60 pixels) to make it reasonably sized on an <span class="caps">HD</span> screen.</p>
<p>The main program retrieves the <span class="caps">SPI</span> device path from the environment variables
set in the <em>resin.io</em> console:</p>
<img alt="ENV variables" src="https://berezovskyi.me/static/2015/resin/env.png" />
<p>To do this, it uses a standard <cite>getenv(3)</cite> call from <cite>stdlib.h</cite>. This was the
only change that I made to the original C code.</p>
<p>Here is how the final result looks like in the browser:</p>
<img alt="final result" src="https://berezovskyi.me/static/2015/resin/web.png" />
<p>The source code is available on <a class="reference external" href="https://bitbucket.org/berezovskyi/doorflirt-resin">Bitbucket</a></p>
<!-- In the next posts we'll see how to change the provided `.img` to gain SSH access -->
<!-- to the board, hopefully we'll work out how to manage the DTO for the -->
<!-- Beaglebone in Yocto Linux; how to use Arduino as the TTL cable for the -->
<!-- Beaglebone; how to interface the sensors from the SEED studio on the Intel -->
<!-- Edison inside the *resin.io* container and other . -->
<p>Finally, I would like to say that <em>resin.io</em> is a very nice service that
provides Heroku-like interface to the embedded boards and requires little to no
changes even for the low-level C code. However, debugging is hard and <em>resin.io</em>
is not making it any easier by restricting the <span class="caps">SSH</span> access to the host <span class="caps">OS</span>.</p>
<p>Happy hacking!</p>
<img alt="successful deploy" src="https://berezovskyi.me/static/2015/resin/unicorn.png" />
Programming Arduino Pro Mini with USBasp V2.02015-03-22T20:02:00+01:002015-03-22T20:02:00+01:00Andrew Berezovskyitag:berezovskyi.me,2015-03-22:/2015/03/programming-arduino-pro-mini-with-usbasp-v2.0/<p><strong><span class="caps">UPD</span> 2016-05-14:</strong> Arduino Nano with <span class="caps">CH340</span> ships from Aliexpress for less
than $2 – I recommend you buy it instead (unless you know what you’re doing).</p>
<p>Do you really need to pay $25 for an Arduino? Many of my friends have the
<a class="reference external" href="http://arduino.cc/en/Main/ArduinoBoardUno">original Arduino</a> and they work great, but I wanted to see how cheap I can
go. Initially, I purchased the <a class="reference external" href="http://www.ebay.com/itm/New-SunFounder-Lab-UNO-R3-Project-LCD-Starter-Kit-For-Arduino-Nano-Mega-2560-/161221722737">SunFounder Starter Kit</a> and it worked 100% as
advertised. Today we’ll see if we can get a fully featured Arduino under $5.</p>
<p>Recently, I came across the dirt cheap Arduino <em>Pro Mini</em> clones and decided
to buy …</p><p><strong><span class="caps">UPD</span> 2016-05-14:</strong> Arduino Nano with <span class="caps">CH340</span> ships from Aliexpress for less
than $2 – I recommend you buy it instead (unless you know what you’re doing).</p>
<p>Do you really need to pay $25 for an Arduino? Many of my friends have the
<a class="reference external" href="http://arduino.cc/en/Main/ArduinoBoardUno">original Arduino</a> and they work great, but I wanted to see how cheap I can
go. Initially, I purchased the <a class="reference external" href="http://www.ebay.com/itm/New-SunFounder-Lab-UNO-R3-Project-LCD-Starter-Kit-For-Arduino-Nano-Mega-2560-/161221722737">SunFounder Starter Kit</a> and it worked 100% as
advertised. Today we’ll see if we can get a fully featured Arduino under $5.</p>
<p>Recently, I came across the dirt cheap Arduino <em>Pro Mini</em> clones and decided
to buy one to see if it works! I also got the clone of the <a class="reference external" href="http://www.fischl.de/usbasp/">USBasp</a> programmer:</p>
<img alt="cheap programmer" src="https://berezovskyi.me/static/2015/arduinopromini-usbaspv2/ebay.png" />
<p>Finally, I had some time during the semester break to play with it. Below you
will find the steps I had to follow to program the <em>Pro Mini</em> from Arduino
<span class="caps">IDE</span>.</p>
<p>First, you’ll need to solder the pins onto the Pro Mini. I wanted to save some
space and soldered the side pins to the bottom side. As a result, the board
doesn’t fit into the breadboard perfectly. So if you intend to use it mostly
in a breadboard, take this into consideration. Additionally, some pins are
duplicated, so you might not need to solder some pins at all.</p>
<p>Next step is to insert <em>Pro Mini</em> into the breadboard as well as wire the
<span class="caps">IDC</span>-10 pins (see the pinout labeled as <em>Kabel</em>).</p>
<img alt="pinout of the USBASP programmer" src="https://berezovskyi.me/static/2015/arduinopromini-usbaspv2/usbasp-pinout.png" />
<img alt="pinout of the Arduino Pro mini" src="https://berezovskyi.me/static/2015/arduinopromini-usbaspv2/promini-pinout.png" />
<p><em>Source:</em> <a class="reference external" href="http://www.s6z.de/cms/index.php/arduino/nuetzliches/31-usb-isp-programmer-fuer-atmel-avr-usbasp"><span class="caps">USB</span> <span class="caps">ISP</span> Programmer für Atmel <span class="caps">AVR</span> (<span class="caps">USBASP</span>)</a></p>
<p>After plugging the <em>USBasp</em> into the <span class="caps">USB</span> port, you should see the blinking <span class="caps">LED</span>
(programmed into Pro Mini at the factory) and the <span class="caps">VCC</span> should output the
correct voltage (3.3V or 5V, depending on your version of Pro Mini):</p>
<img alt="wiring diagram for the USBASP programmer & Arduino" src="https://berezovskyi.me/static/2015/arduinopromini-usbaspv2/connection.jpg" />
<p><em>Without the load (Pro Mini), USPasp outputs proper 5.00V</em></p>
<p>Finally, the computer part (I use Ubuntu 14.04 <span class="caps">LTS</span>). If you use Windows, get
the driver from the <a class="reference external" href="http://www.fischl.de/usbasp/">USBasp page</a>. Change the
following settings in the Arduino <span class="caps">IDE</span>:</p>
<ul class="simple">
<li>Under <strong>Tools > Programmer</strong>, select <em>USBasp</em>.</li>
<li>Under <strong>Tools > Board</strong>, select your version of <em>Arduino Pro or Pro Mini</em>.</li>
</ul>
<p>Finally, you need to update your <cite>udev</cite> rules, otherwise you’ll run into
permission issues (more rules in <a class="reference external" href="https://wiki.archlinux.org/index.php/Udev#Accessing_firmware_programmers_and_USB_virtual_comm_devices">Arch Wiki</a>):</p>
<pre class="code literal-block">
$ cat /etc/udev/rules.d/41-arvdude.rules
# USBasp Programmer rules http://www.fischl.de/usbasp/
SUBSYSTEMS=="usb", ATTRS{idVendor}=="16c0", ATTRS{idProduct}=="05dc", GROUP="andrew", MODE="0666"
</pre>
<p>Now, load a sample sketch under <strong>File > Examples > 01. Basics > Blink</strong> and
then use <em>Upload Using Programmer</em>. If you don’t see any errors,
congratulations! You might still encounter a warning similar to this:</p>
<pre class="code literal-block">
avrdude: warning: cannot set sck period. please check for usbasp firmware update.
</pre>
<p>It can be resolved by reprogramming the programmer itself, as described in the
article <a class="reference external" href="http://blog.lincomatic.com/?p=1480">How to Update the Firmware on a USBasp V2.0</a>. You will need another programmer for
this, however.</p>
<p>If you are excited to continue hacking, but still looking for some
inspiration, check out these resources:</p>
<ul class="simple">
<li><a class="reference external" href="http://www.instructables.com/">http://www.instructables.com/</a></li>
<li><a class="reference external" href="http://makezine.com/projects/">http://makezine.com/projects/</a></li>
<li><a class="reference external" href="http://hackaday.io/">http://hackaday.io/</a></li>
<li><a class="reference external" href="http://dangerousprototypes.com/">http://dangerousprototypes.com/</a></li>
<li><a class="reference external" href="https://courses.cit.cornell.edu/ee476/ideas/EE476.project.ideas.html">https://courses.cit.cornell.edu/ee476/ideas/<span class="caps">EE476</span>.project.ideas.html</a></li>
<li><a class="reference external" href="http://habrahabr.ru/hub/arduino/">http://habrahabr.ru/hub/arduino/</a> (in Russian)</li>
</ul>
Review: HBR Guide to Getting the Right Work Done2015-03-11T22:53:00+01:002015-03-11T22:53:00+01:00Andrew Berezovskyitag:berezovskyi.me,2015-03-11:/2015/03/review-hbr-guide-to-getting-the-right-work-done/<p>New guide from <span class="caps">HBR</span> doesn’t sell you on a new technique, but instead opens with
a chapter titled <em>“You can’t get it all done”</em>. The book presents a reader
with two main ideas that seem rather obvious. First idea suggests that to get
more time for our tasks, we must stop doing things we’re not supposed to. and
that unswerving commitment to daily “rituals” forms the foundation of most
successful people.</p>
<blockquote>
The title of that chapter immediately reminded me of the article published
on <em>The Atlantic</em> and titled <a class="reference external" href="http://www.theatlantic.com/magazine/archive/2012/07/why-women-still-cant-have-it-all/309020/">Why Women Still Can’t Have It All</a>. After …</blockquote><p>New guide from <span class="caps">HBR</span> doesn’t sell you on a new technique, but instead opens with
a chapter titled <em>“You can’t get it all done”</em>. The book presents a reader
with two main ideas that seem rather obvious. First idea suggests that to get
more time for our tasks, we must stop doing things we’re not supposed to. and
that unswerving commitment to daily “rituals” forms the foundation of most
successful people.</p>
<blockquote>
The title of that chapter immediately reminded me of the article published
on <em>The Atlantic</em> and titled <a class="reference external" href="http://www.theatlantic.com/magazine/archive/2012/07/why-women-still-cant-have-it-all/309020/">Why Women Still Can’t Have It All</a>. After reading the book, I still think that the
article deserves huge attention and respective changes in the society, but
start to understand that not just women but all of us will have to make
some tough choices at some point in our life.</blockquote>
<p>The book is not written by a single author, but rather includes separate
articles on productivity prepared by different experts who wrote books as
well published articles in <span class="caps">HBR</span> on this topic. I was positively surprised by a
variety of topics and the simplicity of the arguments in support of certain
habits that authors want to instill into the reader.</p>
<p>Below is a short summary of each section that I would like to keep as a
reference for a regular review in future.</p>
<div class="section" id="section-1-introduction">
<h3>Section 1: Introduction</h3>
<p>The <em>first chapter</em>, titled <strong>“You can’t get it all done”</strong>, carries a very
important advice for every “lifehacker”: find one solution that works for your
organizational challenges and repeat as long as it works well.</p>
<p><em>Second chapter</em> gives a rule of a thumb for setting goals: if you want to
achieve something specific, you should start by setting a specific goal (§1).
In order to change bad habits on your way, use “replacement” if-then plans (§9).</p>
</div>
<div class="section" id="section-2-priorities">
<h3>Section 2: Priorities</h3>
<p><em>Chapter 4</em> offers a career advice that can be shortened to this: figure out
which part of your work brings the biggest gains and for next 6 month
prioritize daily tasks that contribute to those gains (even if it leads to
confrontation with a boss).</p>
<p><em>Chapter 5</em> recommends to refuse helping others unless:</p>
<ul class="simple">
<li>You’re the right person.</li>
<li>It is the right time.</li>
<li>You have enough information.</li>
</ul>
<p>Otherwise, as <em>chapter 6</em> insists, <strong>say “no”</strong>. Keeping a laser focus on your
goals and preparing a polite “no” email template was advised.</p>
</div>
<div class="section" id="section-3-time">
<h3>Section 3: Time</h3>
<p><em>Chapter 7</em> offered a method for extreme fire-fighting. Work in a following
loop until fire is extinguished:</p>
<ul class="simple">
<li>15 minutes on quick tasks;</li>
<li>35 minutes on a hard task;</li>
<li>10 minutes of rest.</li>
</ul>
<p><em>Chapter 8</em> offered to <strong>use rewards</strong> to fight procrastination.</p>
<p>I would go for this advice only to build better habits, e.g. go for a walk
after finishing a report (actually, that’s what <em>chapters 12 <span class="amp">&</span> 14</em> suggest).</p>
<blockquote>
Interesting read: <a class="reference external" href="http://blog.pickcrew.com/habits-and-systems-not-goals/">Start the new year with habits and systems, not goals</a>.</blockquote>
<p><em>Chapter 9</em> is about long-term projects. Takeaway: no more than 5 of them
and start by keeping your expectations low so that you are not afraid.</p>
<p><em>Chapter 10</em> gave some hard arguments to fight for your peace of mind. There
are 3 things that lower your <span class="caps">IQ</span>:</p>
<ul class="simple">
<li>Distraction - 10 points</li>
<li>Lost night of sleep - 10 points</li>
<li>Smoking marijuana - 5 points</li>
</ul>
<p>Not sure about the factual correctness, but if it’s true, I better use that advice.</p>
<p><em>Chapter 11</em> offers a way to be honest with yourself about your <em>own</em> progress:
book a 20-minute <strong>meeting with yourself</strong> once a week. Yes, you heard it right.</p>
<blockquote>
I will actually try to reserve some time to review my week’s notes I made
in my notebook.</blockquote>
<p><em>Chapter 12</em> is all about <span class="caps">TODO</span> lists. One thing was funny and ridiculous:</p>
<blockquote>
<div class="line-block">
<div class="line">Make […] two lists […] by buckets, one by week.</div>
<div class="line">Bonus: You get the joy of crossing off one task in <span class="caps">TWO</span> places.</div>
</div>
</blockquote>
<p><em>Chapter 13</em> gives simple pipeline for classifying tasks:</p>
<ul class="simple">
<li>Do those take less than 2 minutes now</li>
<li>Schedule other important tasks for later</li>
<li>Discard or delegate the rest. If you can’t let go of certain things, put
them into <em>Later</em> list.</li>
</ul>
<p>From the book:</p>
<blockquote>
Perhaps, someday, maybe, I’ll do something on that list.</blockquote>
<p><em>Chapter 14</em> lists rewards for fun <span class="amp">&</span> profit. <strong>Review from time to time!</strong></p>
<blockquote>
<p>While many people think that rewarding yourself is silly (mainly, because
they view it as applying carrot <span class="amp">&</span> the stick to themselves), I think we
should just call it a habit or, perhaps, a schedule. For example, people
don’t skip workdays because a predefined weekend is “silly”. Instead, it’s
a normal course of things that we rest after we work.</p>
<p>I started to treat everything important that is a chore as work, while
treating important tasks for my personal development that I do with joy as rewards.</p>
</blockquote>
</div>
<div class="section" id="section-4-delegation">
<h3>Section 4: Delegation</h3>
<p>I must note that while I was amused by the monkey allegory used, I couldn’t
take the section seriously as I’m not in a position to delegate much now (even
though a lot of team members of the projects I participate in will strongly disagree).</p>
<p><em>Chapter 15</em> was very memorable because now I know <em>who’s got the monkey</em>.
Nice explanation, <em>why</em> (and <em>how</em>) a manager should not take the problems
from those he manages.</p>
<p><em>Chapter 16</em> is the shortest chapter in the book, it’s just two pages. It
gives a table with clear approach to managing subordinates of different level
of professionalism. I recalled my internship and my manager who intentionally
excercised as little supervision as possible and I think that greatly
contributed to my self-organization (while work progress suffered no harm).</p>
</div>
<div class="section" id="section-5-rituals">
<h3>Section 5: Rituals</h3>
<p>I think this was the most brilliant section and I think it will become the one
I’ll revisit most.</p>
<p>From <em>chapter 17</em> I would like to keep a habit of <strong>going to sleep at the same
time</strong> and <strong>working first 90 minutes on the most important task</strong>.</p>
<p><em>Chapter 18</em> goes further suggesting that we should work the whole day in this
rhythm, <strong>taking generous brakes</strong> in between.</p>
<p><em>Chapter 19</em> suggests the following way to manage time: <strong>plan 5 minutes every
morning</strong>, <strong>refocus every hour</strong> and do a <strong>5-minute evening review</strong>.</p>
<p><em>Chapter 20</em> suggests to keep a diary (which is not new to me at all), but
with entries that answer these questions:</p>
<ul class="simple">
<li>Progress today</li>
<li>Setbacks today</li>
<li>Good things</li>
<li>Difficult things</li>
<li>One thing that will make tomorrow go better</li>
</ul>
<!-- -->
<blockquote>
As a side note, keeping a diary was highly praised in the book by Chade-
Meng Tan, <a class="reference external" href="http://www.amazon.com/Search-Inside-Yourself-Unexpected-Achieving/dp/0062116932/">Search Inside Yourself</a>. I’ve been keeping the
diary myself for the last two years and I enjoy it much. It is very
interesting to reread the notes I took on the days of major changes, such
as moving to another city or long weeks of focused work.</blockquote>
</div>
<div class="section" id="section-6-energy">
<h3>Section 6: Energy</h3>
<p><em>Chapter 21</em> warns against working without breaks and super long hours. Even
though I strongly support this idea, I must say that the chapter itself lacked
strong arguments to support that, but I still remember those listed in <em>“Search
Inside Yourself”</em>.</p>
<p><em>Chapter 22</em> suggested many steps to keep yourself full of energy (and a list
that can help to assist us how grave is our exhaustion is, which is graded in
a way to make everyone feel very bad) but one idea I liked more than others –
look at upsetting situations through lenses:</p>
<ul class="simple">
<li>Reverse lens - how your opponent could be right.</li>
<li>Long lens - how would you view it half a year later.</li>
<li>Wide lens - what can you learn from this situation.</li>
</ul>
<!-- -->
<blockquote>
<p>Let me explain why I think that list list has significant problem. After
you’ve calculated your points, they mark a certain grade on a linear
scale. Grades are the following:</p>
<ul class="simple">
<li>Excellent</li>
<li>Strong</li>
<li>Significant deficits</li>
<li>Poor</li>
<li>Full-fledged crisis</li>
</ul>
<p>An attentive reader would notice how quickly you fall from “strong” into “poor”.</p>
<p><span class="caps">P.S.</span> I scored “Significant deficits”, so you can call it a bias.</p>
</blockquote>
<p><em>Chapter 23</em> vouched for the <strong>8-hour sleep</strong> again and suggested to jot down
any ideas that can prevent us from falling asleep before going to bed.</p>
<blockquote>
That’s exactly why I prefer to write the diary in my bed (see <em>chapter
20</em>).</blockquote>
<p>It also suggested a radical <strong>coffee nap</strong> lifehack (p. 149) that I did when I
was studying for my bachelor’s (without coffee though) and it worked amazingly
well to my great surprise!</p>
</div>
<div class="section" id="section-7-email">
<h3>Section 7: Email</h3>
<p>I got myself prepared to this section long before hitting it: removed email
and Facebook (except Messenger) from my mobile phone and wasn’t spending too
much time on it (sorry to all my friends who suffer from my late replies).</p>
<blockquote>
<span class="caps">P.S.</span> Three weeks later after the exams are finished. Email is back on my
phone, but with manual synchronization.</blockquote>
<p>As to the folder system suggested in <em>chapter 24</em>, I started to use Zappier to
create Trello cards for letters that I label with <em>reply</em> or <em>hold</em> in GMail.
I consider proposal to use Yammer really bad. Wasn’t surprised to find out
that the author of this chapter was not working in a corporation and thus
didn’t have to use this software every day.</p>
<p><em>Chapter 25</em> is full of provocative challenges, and I decided to take on this one:</p>
<blockquote>
<p><strong>Reply to every e-mail</strong></p>
<p>For two weeks, make your entire morning an e-mail processing zone.
See whether […] a 100% response rate makes you more effective.</p>
</blockquote>
</div>
<div class="section" id="verdict-aka-tl-dr">
<h3>Verdict (aka tl;dr)</h3>
<p>I think this a great book on productivity, I read it during the exam month and
applied some of its ideas in my preparation.</p>
<p>If you feel your day could’ve gone better, get yourself a copy. Otherwise,
keep calm <span class="amp">&</span> carry on.</p>
<blockquote>
Special thanks to <a class="reference external" href="http://hen-drik.de/">Hendrik Heuer</a> for reviewing the draft of this review. I’ll keep trying!</blockquote>
</div>
Install cvBlob on Debian2015-02-19T17:26:00+01:002015-02-19T17:26:00+01:00Andrew Berezovskyitag:berezovskyi.me,2015-02-19:/2015/02/install-cvblob-on-debian/<p><em>cvBlob</em> installation looked like an easy task but took me a little while to
figure out.</p>
<p>First, there are no <cite>libcv4 libcvaux4</cite> libraries in Debian (at least in
<em>Wheezy</em>). I installed <cite>libopencv-dev</cite> instead.</p>
<p>Next, there was a very strange problem that persisted after <em>cvBlob</em> installation:</p>
<pre class="code text literal-block">
$ ./red_object_tracking
./red_object_tracking: error while loading shared libraries: libcvblob.so:
cannot open shared object file: No such file or directory
</pre>
<p>The solution was to run <cite>sudo ldconfig</cite> beforehand.</p>
<p>Full list of commands:</p>
<pre class="code bash literal-block">
sudo<span class="w"> </span>apt-get<span class="w"> </span>install<span class="w"> </span>mercurial<span class="w"> </span>cmake<span class="w"> </span>libopencv-dev<span class="w">
</span>hg<span class="w"> </span>clone<span class="w"> </span>https://code.google.com/p/cvblob/<span class="w">
</span><span class="nb">cd</span><span class="w"> </span>cvblob<span class="w">
</span>cmake<span class="w"> </span>.<span class="w">
</span>make<span class="w">
</span>make<span class="w"> </span>install<span class="w">
</span>sudo<span class="w"> </span>ldconfig<span class="w">
</span><span class="nb">cd</span><span class="w"> </span>samples …</pre><p><em>cvBlob</em> installation looked like an easy task but took me a little while to
figure out.</p>
<p>First, there are no <cite>libcv4 libcvaux4</cite> libraries in Debian (at least in
<em>Wheezy</em>). I installed <cite>libopencv-dev</cite> instead.</p>
<p>Next, there was a very strange problem that persisted after <em>cvBlob</em> installation:</p>
<pre class="code text literal-block">
$ ./red_object_tracking
./red_object_tracking: error while loading shared libraries: libcvblob.so:
cannot open shared object file: No such file or directory
</pre>
<p>The solution was to run <cite>sudo ldconfig</cite> beforehand.</p>
<p>Full list of commands:</p>
<pre class="code bash literal-block">
sudo<span class="w"> </span>apt-get<span class="w"> </span>install<span class="w"> </span>mercurial<span class="w"> </span>cmake<span class="w"> </span>libopencv-dev<span class="w">
</span>hg<span class="w"> </span>clone<span class="w"> </span>https://code.google.com/p/cvblob/<span class="w">
</span><span class="nb">cd</span><span class="w"> </span>cvblob<span class="w">
</span>cmake<span class="w"> </span>.<span class="w">
</span>make<span class="w">
</span>make<span class="w"> </span>install<span class="w">
</span>sudo<span class="w"> </span>ldconfig<span class="w">
</span><span class="nb">cd</span><span class="w"> </span>samples<span class="w">
</span>make
</pre>
<p>Optionally, you might need to install <cite>libcv2.3 libcv-dev libcvaux-dev</cite>. See
<a class="reference external" href="https://packages.debian.org/source/wheezy/opencv">Debian packages</a> for more infomation</p>
Update Git on Debian 7 to Git 2.32015-02-19T15:14:00+01:002015-02-19T15:14:00+01:00Andrew Berezovskyitag:berezovskyi.me,2015-02-19:/2015/02/update-git-on-debian/<p>Add the following repository to the <cite>sources.list</cite>:</p>
<pre class="code bash literal-block">
deb<span class="w"> </span>http://ppa.launchpad.net/git-core/ppa/ubuntu<span class="w"> </span>precise<span class="w"> </span>main<span class="w">
</span>deb-src<span class="w"> </span>http://ppa.launchpad.net/git-core/ppa/ubuntu<span class="w"> </span>precise<span class="w"> </span>main
</pre>
<p>Now, run <cite>sudo apt-get update</cite> and get the following output:</p>
<pre class="code text literal-block">
W: GPG error: http://ppa.launchpad.net precise Release: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY A1715D88E1DF1F24
</pre>
<p>And fix it by running</p>
<pre class="code bash literal-block">
sudo<span class="w"> </span>apt-key<span class="w"> </span>adv<span class="w"> </span>--keyserver<span class="w"> </span>keyserver.ubuntu.com<span class="w"> </span>--recv-keys<span class="w"> </span>A1715D88E1DF1F24
</pre>
<p>Now you can run</p>
<pre class="code bash literal-block">
sudo<span class="w"> </span>apt-get<span class="w"> </span>install<span class="w"> </span>git
</pre>
<p>And afterwards verify your setup:</p>
<pre class="code bash literal-block">
$<span class="w"> </span>lsb_release<span class="w"> </span>-a<span class="w">
</span>No<span class="w"> </span>LSB<span class="w"> </span>modules<span class="w"> </span>are<span class="w"> </span>available.<span class="w">
</span>Distributor<span class="w"> </span>ID:<span class="w"> </span>Debian<span class="w">
</span>Description …</pre><p>Add the following repository to the <cite>sources.list</cite>:</p>
<pre class="code bash literal-block">
deb<span class="w"> </span>http://ppa.launchpad.net/git-core/ppa/ubuntu<span class="w"> </span>precise<span class="w"> </span>main<span class="w">
</span>deb-src<span class="w"> </span>http://ppa.launchpad.net/git-core/ppa/ubuntu<span class="w"> </span>precise<span class="w"> </span>main
</pre>
<p>Now, run <cite>sudo apt-get update</cite> and get the following output:</p>
<pre class="code text literal-block">
W: GPG error: http://ppa.launchpad.net precise Release: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY A1715D88E1DF1F24
</pre>
<p>And fix it by running</p>
<pre class="code bash literal-block">
sudo<span class="w"> </span>apt-key<span class="w"> </span>adv<span class="w"> </span>--keyserver<span class="w"> </span>keyserver.ubuntu.com<span class="w"> </span>--recv-keys<span class="w"> </span>A1715D88E1DF1F24
</pre>
<p>Now you can run</p>
<pre class="code bash literal-block">
sudo<span class="w"> </span>apt-get<span class="w"> </span>install<span class="w"> </span>git
</pre>
<p>And afterwards verify your setup:</p>
<pre class="code bash literal-block">
$<span class="w"> </span>lsb_release<span class="w"> </span>-a<span class="w">
</span>No<span class="w"> </span>LSB<span class="w"> </span>modules<span class="w"> </span>are<span class="w"> </span>available.<span class="w">
</span>Distributor<span class="w"> </span>ID:<span class="w"> </span>Debian<span class="w">
</span>Description:<span class="w"> </span>Debian<span class="w"> </span>GNU/Linux<span class="w"> </span><span class="m">7</span>.7<span class="w"> </span><span class="o">(</span>wheezy<span class="o">)</span><span class="w">
</span>Release:<span class="w"> </span><span class="m">7</span>.7<span class="w">
</span>Codename:<span class="w"> </span>wheezy<span class="w">
</span>$<span class="w"> </span>git<span class="w"> </span>--version<span class="w">
</span>git<span class="w"> </span>version<span class="w"> </span><span class="m">2</span>.3.0
</pre>
<p>Now you can use <cite>simple</cite> push, new <cite>remote</cite> syntax and <cite>-C</cite> flag as well as many other features!</p>
<p><strong><span class="caps">UPD</span> (12.04.15):</strong></p>
<p>It turned out that I forgot to describe the installation process for a <cite>libc6</cite>
dependency. We will install it from Debian <em>testing</em>.</p>
<p>First, you need to create a file <cite>/etc/apt/apt.conf.d/99defaultrelease</cite>:</p>
<pre class="code bash literal-block">
APT::Default-Release<span class="w"> </span><span class="s2">"stable"</span><span class="p">;</span>
</pre>
<p>Then, <cite>/etc/apt/sources.list.d/testing.list</cite>:</p>
<pre class="code bash literal-block">
deb<span class="w"> </span>http://ftp.de.debian.org/debian/<span class="w"> </span>testing<span class="w"> </span>main<span class="w"> </span>contrib<span class="w"> </span>non-free<span class="w">
</span>deb-src<span class="w"> </span>http://ftp.de.debian.org/debian/<span class="w"> </span>testing<span class="w"> </span>main<span class="w"> </span>contrib<span class="w"> </span>non-free<span class="w">
</span>deb<span class="w"> </span>http://security.debian.org/<span class="w"> </span>testing/updates<span class="w"> </span>main<span class="w"> </span>contrib<span class="w"> </span>non-free
</pre>
<p>Run <cite>apt-get update</cite> and the execute:</p>
<pre class="code bash literal-block">
apt-get<span class="w"> </span>install<span class="w"> </span>-t<span class="w"> </span>testing<span class="w"> </span>libc6
</pre>
<p>After this, repeat the installation command:</p>
<pre class="code bash literal-block">
sudo<span class="w"> </span>apt-get<span class="w"> </span>install<span class="w"> </span>git
</pre>
<p>Thanks to <a class="reference external" href="https://github.com/djmaze">Martin</a> for pointing this problem out!</p>
<p>Sources:</p>
<ul class="simple">
<li><a class="reference external" href="https://wiki.debian.org/SecureApt#How_to_find_and_add_a_key">https://wiki.debian.org/SecureApt#How_to_find_and_add_a_key</a></li>
<li><a class="reference external" href="http://ubuntuforums.org/showthread.php?t=1263676&p=7932168#post7932168">http://ubuntuforums.org/showthread.php?t=1263676&p=7932168#post7932168</a></li>
<li><a class="reference external" href="http://serverfault.com/questions/22414/how-can-i-run-debian-stable-but-install-some-packages-from-testing">http://serverfault.com/questions/22414/how-can-i-run-debian-stable-but-install-some-packages-from-testing</a></li>
</ul>
Clang fatal error: standard headers not found2015-02-16T13:32:00+01:002015-02-16T13:32:00+01:00Andrew Berezovskyitag:berezovskyi.me,2015-02-16:/2015/02/clang-fatal-error-headers-not-found/<p>In the morning I decided to try building the <a class="reference external" href="https://github.com/dropbox/json11">json11</a> library. I almost submitted
a github issue but then understood that the error quite silly and was probably originating from my broken setup:</p>
<pre class="code bash literal-block">
$<span class="w"> </span>make<span class="w"> </span><span class="nb">test</span><span class="w">
</span>clang++<span class="w"> </span>-O<span class="w"> </span>-std<span class="o">=</span>c++11<span class="w"> </span>-stdlib<span class="o">=</span>libc++<span class="w"> </span>json11.cpp<span class="w"> </span>test.cpp<span class="w"> </span>-o<span class="w"> </span><span class="nb">test</span><span class="w"> </span>-fno-rtti<span class="w"> </span>-fno-exceptions<span class="w">
</span>In<span class="w"> </span>file<span class="w"> </span>included<span class="w"> </span>from<span class="w"> </span>json11.cpp:22:<span class="w">
</span>./json11.hpp:53:10:<span class="w"> </span>fatal<span class="w"> </span>error:<span class="w"> </span><span class="s1">'string'</span><span class="w"> </span>file<span class="w"> </span>not<span class="w"> </span>found<span class="w">
</span><span class="c1">#include <string>
</span><span class="w"> </span>^<span class="w">
</span><span class="m">1</span><span class="w"> </span>error<span class="w"> </span>generated.<span class="w">
</span>test.cpp:1:10:<span class="w"> </span>fatal<span class="w"> </span>error:<span class="w"> </span><span class="s1">'string'</span><span class="w"> </span>file<span class="w"> </span>not<span class="w"> </span>found<span class="w">
</span><span class="c1">#include <string>
</span><span class="w"> </span>^<span class="w">
</span><span class="m">1</span><span class="w"> </span>error<span class="w"> </span>generated.
</pre>
<p>As you might see, <cite>string</cite> is a part of the standard library.</p>
<p>Let …</p><p>In the morning I decided to try building the <a class="reference external" href="https://github.com/dropbox/json11">json11</a> library. I almost submitted
a github issue but then understood that the error quite silly and was probably originating from my broken setup:</p>
<pre class="code bash literal-block">
$<span class="w"> </span>make<span class="w"> </span><span class="nb">test</span><span class="w">
</span>clang++<span class="w"> </span>-O<span class="w"> </span>-std<span class="o">=</span>c++11<span class="w"> </span>-stdlib<span class="o">=</span>libc++<span class="w"> </span>json11.cpp<span class="w"> </span>test.cpp<span class="w"> </span>-o<span class="w"> </span><span class="nb">test</span><span class="w"> </span>-fno-rtti<span class="w"> </span>-fno-exceptions<span class="w">
</span>In<span class="w"> </span>file<span class="w"> </span>included<span class="w"> </span>from<span class="w"> </span>json11.cpp:22:<span class="w">
</span>./json11.hpp:53:10:<span class="w"> </span>fatal<span class="w"> </span>error:<span class="w"> </span><span class="s1">'string'</span><span class="w"> </span>file<span class="w"> </span>not<span class="w"> </span>found<span class="w">
</span><span class="c1">#include <string>
</span><span class="w"> </span>^<span class="w">
</span><span class="m">1</span><span class="w"> </span>error<span class="w"> </span>generated.<span class="w">
</span>test.cpp:1:10:<span class="w"> </span>fatal<span class="w"> </span>error:<span class="w"> </span><span class="s1">'string'</span><span class="w"> </span>file<span class="w"> </span>not<span class="w"> </span>found<span class="w">
</span><span class="c1">#include <string>
</span><span class="w"> </span>^<span class="w">
</span><span class="m">1</span><span class="w"> </span>error<span class="w"> </span>generated.
</pre>
<p>As you might see, <cite>string</cite> is a part of the standard library.</p>
<p>Let’s see what clang is on my system:</p>
<pre class="code bash literal-block">
$<span class="w"> </span>clang<span class="w"> </span>--version<span class="w">
</span>Ubuntu<span class="w"> </span>clang<span class="w"> </span>version<span class="w"> </span><span class="m">3</span>.4-1ubuntu3<span class="w"> </span><span class="o">(</span>tags/RELEASE_34/final<span class="o">)</span><span class="w"> </span><span class="o">(</span>based<span class="w"> </span>on<span class="w"> </span>LLVM<span class="w"> </span><span class="m">3</span>.4<span class="o">)</span><span class="w">
</span>Target:<span class="w"> </span>x86_64-pc-linux-gnu<span class="w">
</span>Thread<span class="w"> </span>model:<span class="w"> </span>posix
</pre>
<p>Surprisingly enough, the solution was found in the StackOverflow <a class="reference external" href="http://stackoverflow.com/questions/24342312/clang-seems-to-use-the-gcc-libraries#comment44822808_24342365">comment</a>:</p>
<pre class="code bash literal-block">
sudo<span class="w"> </span>apt-get<span class="w"> </span>install<span class="w"> </span>libc++-dev
</pre>
<p>While fighting this issue I found some package management commands useful:</p>
<ul class="simple">
<li><cite>apt-get remove</cite> doesn’t always remove an existing library. <cite>apt-get purge</cite> solves it.</li>
<li>In order to see all package names installed that match a pattern, run <cite>dpkg -l | grep “^rc” | awk ‘{print $2}’ | grep clang</cite>.</li>
<li>You can pipe the output of the previous command directly to <cite>xargs sudo apt-get purge -y</cite>.</li>
<li>If you can’t get anything to work to remove a package, use <cite>sudo dpkg —purge —force-all clang</cite>. Warning: it <em>will</em> break your system if previous commands warned you. Run <cite>sudo apt-get install -f</cite> to fix packages afterwards, but be sure you know what you’re doing.</li>
</ul>
Deploying sample Silex app to Heroku2015-02-15T21:11:00+01:002015-02-15T21:11:00+01:00Andrew Berezovskyitag:berezovskyi.me,2015-02-15:/2015/02/deploying-sample-silex-app-to-heroku/<p>For the last couple of weeks I met quite a few people who were praising <span class="caps">PHP</span> and I had an idea to have a brief look at
it once again after more than 4-year break.</p>
<p>I decided to push a sample application to Heroku by following their tutorial but that turned out to be nontrivial on
my Ubuntu 14.<span class="caps">04LTS</span>. Below I’ll give a brief list of commands that I needed in addition to those provided by Heroku
to get the app running locally before pushing it to Heroku.</p>
<p>Initially, we start by naviagiting to the <a href="https://github.com/heroku/php-getting-started">repository</a> and following …</p><p>For the last couple of weeks I met quite a few people who were praising <span class="caps">PHP</span> and I had an idea to have a brief look at
it once again after more than 4-year break.</p>
<p>I decided to push a sample application to Heroku by following their tutorial but that turned out to be nontrivial on
my Ubuntu 14.<span class="caps">04LTS</span>. Below I’ll give a brief list of commands that I needed in addition to those provided by Heroku
to get the app running locally before pushing it to Heroku.</p>
<p>Initially, we start by naviagiting to the <a href="https://github.com/heroku/php-getting-started">repository</a> and following
its first block of commands:</p>
<div class="highlight"><pre><span></span><code>git<span class="w"> </span>clone<span class="w"> </span>git@github.com:heroku/php-getting-started.git<span class="w"> </span><span class="c1"># or clone your own fork</span>
<span class="nb">cd</span><span class="w"> </span>php-getting-started
composer<span class="w"> </span>update
foreman<span class="w"> </span>start<span class="w"> </span>web
</code></pre></div>
<p>There is a couple of catches here:</p>
<ul>
<li>composer is installed locally by default</li>
<li><code>vendor/bin/heroku-php-apache2</code> script requires <span class="caps">PHP</span> 5.5.11 or newer as well as Apache 2.4.10 or newer. As you might
imagine, Ubuntu 14.04 has <span class="caps">PHP</span> 5.5 and Apache 2.4 but not as new as those. </li>
<li>it also accesses those binaries through <code>php-fpm</code> and <code>httpd</code> while Ubuntu only provides <code>php5-fpm</code> and <code>apache2</code>.</li>
</ul>
<h2 id="composer-installation">Composer installation<a class="headerlink" href="#composer-installation" title="Permanent link">¶</a></h2>
<p>Use these commands for the global installation:</p>
<div class="highlight"><pre><span></span><code>curl<span class="w"> </span>-sS<span class="w"> </span>https://getcomposer.org/installer<span class="w"> </span><span class="p">|</span><span class="w"> </span>php
mv<span class="w"> </span>composer.phar<span class="w"> </span>/usr/local/bin/composer
</code></pre></div>
<h2 id="php-apache-fight"><span class="caps">PHP</span> <span class="amp">&</span> Apache fight<a class="headerlink" href="#php-apache-fight" title="Permanent link">¶</a></h2>
<p>I decided to use the <a href="https://launchpad.net/~ondrej/+archive/ubuntu/php5-5.6"><span class="caps">PPA</span> by Ondřej Surý</a> which at the time of
writing provides <span class="caps">PHP</span> 5.6.5 and Apache 2.4.11. I followed the instructions on <a href="https://www.digitalocean.com/community/questions/how-to-upgrade-from-php-v-5-5-9-to-v-5-6?answer=17338">DigitalOcean community forum</a>:</p>
<div class="highlight"><pre><span></span><code>sudo<span class="w"> </span>apt-get<span class="w"> </span>install<span class="w"> </span>software-properties-common
sudo<span class="w"> </span>add-apt-repository<span class="w"> </span>ppa:ondrej/php5-5.6
sudo<span class="w"> </span>apt-get<span class="w"> </span>update
sudo<span class="w"> </span>apt-get<span class="w"> </span>upgrade
sudo<span class="w"> </span>apt-get<span class="w"> </span>install<span class="w"> </span>php5
</code></pre></div>
<p>You also need to run the following commands:</p>
<div class="highlight"><pre><span></span><code>sudo<span class="w"> </span>apt-get<span class="w"> </span>install<span class="w"> </span>php5-fpm<span class="w"> </span>apache2
ln<span class="w"> </span>-s<span class="w"> </span>/usr/sbin/php5-fpm<span class="w"> </span>/usr/sbin/php-fpm
sudo<span class="w"> </span>ln<span class="w"> </span>-s<span class="w"> </span>/usr/sbin/apache2<span class="w"> </span>/usr/sbin/httpd
</code></pre></div>
<p>After that I ran into a problem with undefined Apache variables:</p>
<div class="highlight"><pre><span></span><code>$<span class="w"> </span>foreman<span class="w"> </span>start<span class="w"> </span>web
<span class="m">22</span>:28:44<span class="w"> </span>web.1<span class="w"> </span><span class="p">|</span><span class="w"> </span>started<span class="w"> </span>with<span class="w"> </span>pid<span class="w"> </span><span class="m">7574</span>
<span class="m">22</span>:28:44<span class="w"> </span>web.1<span class="w"> </span><span class="p">|</span><span class="w"> </span><span class="o">[</span>Sun<span class="w"> </span>Feb<span class="w"> </span><span class="m">15</span><span class="w"> </span><span class="m">22</span>:28:44.931421<span class="w"> </span><span class="m">2015</span><span class="o">]</span><span class="w"> </span><span class="o">[</span>core:warn<span class="o">]</span><span class="w"> </span><span class="o">[</span>pid<span class="w"> </span><span class="m">7594</span><span class="o">]</span><span class="w"> </span>AH00111:<span class="w"> </span>Config<span class="w"> </span>variable<span class="w"> </span><span class="si">${</span><span class="nv">APACHE_LOCK_DIR</span><span class="si">}</span><span class="w"> </span>is<span class="w"> </span>not<span class="w"> </span>defined
<span class="m">22</span>:28:44<span class="w"> </span>web.1<span class="w"> </span><span class="p">|</span><span class="w"> </span><span class="o">[</span>Sun<span class="w"> </span>Feb<span class="w"> </span><span class="m">15</span><span class="w"> </span><span class="m">22</span>:28:44.931469<span class="w"> </span><span class="m">2015</span><span class="o">]</span><span class="w"> </span><span class="o">[</span>core:warn<span class="o">]</span><span class="w"> </span><span class="o">[</span>pid<span class="w"> </span><span class="m">7594</span><span class="o">]</span><span class="w"> </span>AH00111:<span class="w"> </span>Config<span class="w"> </span>variable<span class="w"> </span><span class="si">${</span><span class="nv">APACHE_PID_FILE</span><span class="si">}</span><span class="w"> </span>is<span class="w"> </span>not<span class="w"> </span>defined
<span class="m">22</span>:28:44<span class="w"> </span>web.1<span class="w"> </span><span class="p">|</span><span class="w"> </span><span class="o">[</span>Sun<span class="w"> </span>Feb<span class="w"> </span><span class="m">15</span><span class="w"> </span><span class="m">22</span>:28:44.931481<span class="w"> </span><span class="m">2015</span><span class="o">]</span><span class="w"> </span><span class="o">[</span>core:warn<span class="o">]</span><span class="w"> </span><span class="o">[</span>pid<span class="w"> </span><span class="m">7594</span><span class="o">]</span><span class="w"> </span>AH00111:<span class="w"> </span>Config<span class="w"> </span>variable<span class="w"> </span><span class="si">${</span><span class="nv">APACHE_RUN_USER</span><span class="si">}</span><span class="w"> </span>is<span class="w"> </span>not<span class="w"> </span>defined
<span class="m">22</span>:28:44<span class="w"> </span>web.1<span class="w"> </span><span class="p">|</span><span class="w"> </span><span class="o">[</span>Sun<span class="w"> </span>Feb<span class="w"> </span><span class="m">15</span><span class="w"> </span><span class="m">22</span>:28:44.931487<span class="w"> </span><span class="m">2015</span><span class="o">]</span><span class="w"> </span><span class="o">[</span>core:warn<span class="o">]</span><span class="w"> </span><span class="o">[</span>pid<span class="w"> </span><span class="m">7594</span><span class="o">]</span><span class="w"> </span>AH00111:<span class="w"> </span>Config<span class="w"> </span>variable<span class="w"> </span><span class="si">${</span><span class="nv">APACHE_RUN_GROUP</span><span class="si">}</span><span class="w"> </span>is<span class="w"> </span>not<span class="w"> </span>defined
<span class="m">22</span>:28:44<span class="w"> </span>web.1<span class="w"> </span><span class="p">|</span><span class="w"> </span><span class="o">[</span>Sun<span class="w"> </span>Feb<span class="w"> </span><span class="m">15</span><span class="w"> </span><span class="m">22</span>:28:44.931495<span class="w"> </span><span class="m">2015</span><span class="o">]</span><span class="w"> </span><span class="o">[</span>core:warn<span class="o">]</span><span class="w"> </span><span class="o">[</span>pid<span class="w"> </span><span class="m">7594</span><span class="o">]</span><span class="w"> </span>AH00111:<span class="w"> </span>Config<span class="w"> </span>variable<span class="w"> </span><span class="si">${</span><span class="nv">APACHE_LOG_DIR</span><span class="si">}</span><span class="w"> </span>is<span class="w"> </span>not<span class="w"> </span>defined
<span class="m">22</span>:28:44<span class="w"> </span>web.1<span class="w"> </span><span class="p">|</span><span class="w"> </span><span class="o">[</span>Sun<span class="w"> </span>Feb<span class="w"> </span><span class="m">15</span><span class="w"> </span><span class="m">22</span>:28:44.936673<span class="w"> </span><span class="m">2015</span><span class="o">]</span><span class="w"> </span><span class="o">[</span>core:warn<span class="o">]</span><span class="w"> </span><span class="o">[</span>pid<span class="w"> </span><span class="m">7594</span><span class="o">]</span><span class="w"> </span>AH00111:<span class="w"> </span>Config<span class="w"> </span>variable<span class="w"> </span><span class="si">${</span><span class="nv">APACHE_LOG_DIR</span><span class="si">}</span><span class="w"> </span>is<span class="w"> </span>not<span class="w"> </span>defined
<span class="m">22</span>:28:44<span class="w"> </span>web.1<span class="w"> </span><span class="p">|</span><span class="w"> </span>AH00526:<span class="w"> </span>Syntax<span class="w"> </span>error<span class="w"> </span>on<span class="w"> </span>line<span class="w"> </span><span class="m">75</span><span class="w"> </span>of<span class="w"> </span>/etc/apache2/apache2.conf:
<span class="m">22</span>:28:44<span class="w"> </span>web.1<span class="w"> </span><span class="p">|</span><span class="w"> </span>Invalid<span class="w"> </span>Mutex<span class="w"> </span>directory<span class="w"> </span><span class="k">in</span><span class="w"> </span>argument<span class="w"> </span>file:<span class="si">${</span><span class="nv">APACHE_LOCK_DIR</span><span class="si">}</span>
</code></pre></div>
<p>This is another error in that script that has to be fixed, but for now I used the answer from the <a href="https://serverfault.com/a/608619/118645">ServerFault</a>:</p>
<div class="highlight"><pre><span></span><code>$<span class="w"> </span><span class="nb">source</span><span class="w"> </span>/etc/apache2/envvars
</code></pre></div>
<p>However, after that I hit the same error about Apache. This time, however, I was attentive enough to notice that the
error message also mentioned that two modules are needed. Let’s see what I have:</p>
<div class="highlight"><pre><span></span><code>$<span class="w"> </span>apache2ctl<span class="w"> </span>-M
Loaded<span class="w"> </span>Modules:
<span class="w"> </span>core_module<span class="w"> </span><span class="o">(</span>static<span class="o">)</span>
<span class="w"> </span>so_module<span class="w"> </span><span class="o">(</span>static<span class="o">)</span>
<span class="w"> </span>watchdog_module<span class="w"> </span><span class="o">(</span>static<span class="o">)</span>
<span class="w"> </span>http_module<span class="w"> </span><span class="o">(</span>static<span class="o">)</span>
<span class="w"> </span>log_config_module<span class="w"> </span><span class="o">(</span>static<span class="o">)</span>
<span class="w"> </span>logio_module<span class="w"> </span><span class="o">(</span>static<span class="o">)</span>
<span class="w"> </span>version_module<span class="w"> </span><span class="o">(</span>static<span class="o">)</span>
<span class="w"> </span>unixd_module<span class="w"> </span><span class="o">(</span>static<span class="o">)</span>
<span class="w"> </span>access_compat_module<span class="w"> </span><span class="o">(</span>shared<span class="o">)</span>
<span class="w"> </span>alias_module<span class="w"> </span><span class="o">(</span>shared<span class="o">)</span>
<span class="w"> </span>auth_basic_module<span class="w"> </span><span class="o">(</span>shared<span class="o">)</span>
<span class="w"> </span>authn_core_module<span class="w"> </span><span class="o">(</span>shared<span class="o">)</span>
<span class="w"> </span>authn_file_module<span class="w"> </span><span class="o">(</span>shared<span class="o">)</span>
<span class="w"> </span>authz_core_module<span class="w"> </span><span class="o">(</span>shared<span class="o">)</span>
<span class="w"> </span>authz_host_module<span class="w"> </span><span class="o">(</span>shared<span class="o">)</span>
<span class="w"> </span>authz_user_module<span class="w"> </span><span class="o">(</span>shared<span class="o">)</span>
<span class="w"> </span>autoindex_module<span class="w"> </span><span class="o">(</span>shared<span class="o">)</span>
<span class="w"> </span>deflate_module<span class="w"> </span><span class="o">(</span>shared<span class="o">)</span>
<span class="w"> </span>dir_module<span class="w"> </span><span class="o">(</span>shared<span class="o">)</span>
<span class="w"> </span>env_module<span class="w"> </span><span class="o">(</span>shared<span class="o">)</span>
<span class="w"> </span>filter_module<span class="w"> </span><span class="o">(</span>shared<span class="o">)</span>
<span class="w"> </span>mime_module<span class="w"> </span><span class="o">(</span>shared<span class="o">)</span>
<span class="w"> </span>mpm_prefork_module<span class="w"> </span><span class="o">(</span>shared<span class="o">)</span>
<span class="w"> </span>negotiation_module<span class="w"> </span><span class="o">(</span>shared<span class="o">)</span>
<span class="w"> </span>php5_module<span class="w"> </span><span class="o">(</span>shared<span class="o">)</span>
<span class="w"> </span>setenvif_module<span class="w"> </span><span class="o">(</span>shared<span class="o">)</span>
<span class="w"> </span>status_module<span class="w"> </span><span class="o">(</span>shared<span class="o">)</span>
</code></pre></div>
<p>Sure thing, both <code>mod_proxy</code> and <code>mod_proxy_fcgi</code> are missing from this list. Let’s enable them:</p>
<div class="highlight"><pre><span></span><code>sudo<span class="w"> </span>a2enmod<span class="w"> </span>proxy_fcgi
</code></pre></div>
<p>After that, I also had to enable <code>rewrite</code> module as well as get my hands dirty with root-hell:</p>
<div class="highlight"><pre><span></span><code>$<span class="w"> </span>sudo<span class="w"> </span>-s
<span class="c1"># . /etc/apache2/envvars</span>
<span class="c1"># export HOME=/root</span>
</code></pre></div>
<p>And finally, I was able to start the server:</p>
<div class="highlight"><pre><span></span><code><span class="c1"># foreman start web </span>
<span class="m">02</span>:10:22<span class="w"> </span>web.1<span class="w"> </span><span class="p">|</span><span class="w"> </span>started<span class="w"> </span>with<span class="w"> </span>pid<span class="w"> </span><span class="m">13567</span>
<span class="m">02</span>:10:22<span class="w"> </span>web.1<span class="w"> </span><span class="p">|</span><span class="w"> </span>DOCUMENT_ROOT<span class="w"> </span>changed<span class="w"> </span>to<span class="w"> </span><span class="s1">'web/'</span>
<span class="m">02</span>:10:22<span class="w"> </span>web.1<span class="w"> </span><span class="p">|</span><span class="w"> </span><span class="m">4</span><span class="w"> </span>processes<span class="w"> </span>at<span class="w"> </span>128MB<span class="w"> </span>memory<span class="w"> </span>limit.
<span class="m">02</span>:10:22<span class="w"> </span>web.1<span class="w"> </span><span class="p">|</span><span class="w"> </span>Starting<span class="w"> </span>php-fpm...
<span class="m">02</span>:10:24<span class="w"> </span>web.1<span class="w"> </span><span class="p">|</span><span class="w"> </span>Starting<span class="w"> </span>httpd...
<span class="m">02</span>:10:24<span class="w"> </span>web.1<span class="w"> </span><span class="p">|</span><span class="w"> </span>Application<span class="w"> </span>ready<span class="w"> </span><span class="k">for</span><span class="w"> </span>connections<span class="w"> </span>on<span class="w"> </span>port<span class="w"> </span><span class="m">5000</span>.
</code></pre></div>
<p>However, any access attempts resulted in errors:</p>
<div class="highlight"><pre><span></span><code><span class="m">02</span>:10:29<span class="w"> </span>web.1<span class="w"> </span><span class="p">|</span><span class="w"> </span><span class="o">[</span>Mon<span class="w"> </span>Feb<span class="w"> </span><span class="m">16</span><span class="w"> </span><span class="m">02</span>:10:29.622321<span class="w"> </span><span class="m">2015</span><span class="o">]</span><span class="w"> </span><span class="o">[</span>proxy:error<span class="o">]</span><span class="w"> </span><span class="o">[</span>pid<span class="w"> </span><span class="m">13678</span><span class="o">]</span><span class="w"> </span><span class="o">(</span><span class="m">13</span><span class="o">)</span>Permission<span class="w"> </span>denied:<span class="w"> </span>AH02454:<span class="w"> </span>FCGI:<span class="w"> </span>attempt<span class="w"> </span>to<span class="w"> </span>connect<span class="w"> </span>to<span class="w"> </span>Unix<span class="w"> </span>domain<span class="w"> </span>socket<span class="w"> </span>/tmp/heroku.fcgi.5000.sock<span class="w"> </span><span class="o">(</span>heroku-fcgi<span class="o">)</span><span class="w"> </span>failed
<span class="m">02</span>:10:29<span class="w"> </span>web.1<span class="w"> </span><span class="p">|</span><span class="w"> </span><span class="o">[</span>Mon<span class="w"> </span>Feb<span class="w"> </span><span class="m">16</span><span class="w"> </span><span class="m">02</span>:10:29.622399<span class="w"> </span><span class="m">2015</span><span class="o">]</span><span class="w"> </span><span class="o">[</span>proxy:error<span class="o">]</span><span class="w"> </span><span class="o">[</span>pid<span class="w"> </span><span class="m">13678</span><span class="o">]</span><span class="w"> </span>AH00959:<span class="w"> </span>ap_proxy_connect_backend<span class="w"> </span>disabling<span class="w"> </span>worker<span class="w"> </span><span class="k">for</span><span class="w"> </span><span class="o">(</span>heroku-fcgi<span class="o">)</span><span class="w"> </span><span class="k">for</span><span class="w"> </span>60s
</code></pre></div>
<p>… until I opened another terminal in parallel and executed <code>sudo chmod 0667 /tmp/heroku.fcgi.5000.sock</code> (inspired by <a href="https://github.com/deis/deis/issues/1091">this</a>).</p>
<p><strong><span class="caps">P.S.</span></strong> There is an <a href="https://github.com/heroku/heroku-buildpack-php/issues/55">issue</a> opened supposedly
by the owner of the script itself that somehow acknowledges planned effort on supporting ‘debianisms’ but
it doesn’t make the situation any better.</p>Using EOSInfo utility to get your Canon EOS information2014-08-16T15:34:00+02:002014-08-16T15:34:00+02:00Andrew Berezovskyitag:berezovskyi.me,2014-08-16:/2014/08/eos-info/<p>You can use these tools to get the information for your old Canon camera. Per platform:</p>
<ul class="simple">
<li>Windows (<a class="reference external" href="http://astrojargon.net/eosinfo.aspx">http://astrojargon.net/eosinfo.aspx</a>)</li>
<li>macOs (<a class="reference external" href="http://astrojargon.net/40DShutterCount.aspx">http://astrojargon.net/40DShutterCount.aspx</a>)</li>
</ul>
<p>I haven’t found a similar tool for Linux, but you might still be happy to find out that you can [run Linux](<a class="reference external" href="http://www.magiclantern.fm/forum/index.php?topic=14847.0">http://www.magiclantern.fm/forum/index.php?topic=14847.0</a>) on newer camera versions that have an <span class="caps">ARM</span> onboard!</p>
<p>Backup links:</p>
<ul class="simple">
<li><a class="reference external" href="http://archive.is/3tZlh">http://archive.is/3tZlh</a></li>
<li><a class="reference external" href="http://archive.is/PCE7U">http://archive.is/<span class="caps">PCE7U</span></a></li>
<li><a class="reference external" href="https://cloud.berezovskiy.me/index.php/s/ArN9NhpIbezcFhX">https://cloud.berezovskiy.me/index.php/s/ArN9NhpIbezcFhX</a> (for installers)</li>
</ul>
<p><em>Updated on 15 Dec‘16.</em></p>
Work-life balance & weekend reading2014-08-15T15:11:00+02:002014-08-15T15:11:00+02:00Andrew Berezovskyitag:berezovskyi.me,2014-08-15:/2014/08/work-life-balance-weekend-reading/<p>Links:</p>
<ul class="simple">
<li><a class="reference external" href="http://www.lindsredding.com/2012/03/11/a-overdue-lesson-in-perspective/">http://www.lindsredding.com/2012/03/11/a-overdue-lesson-in-perspective/</a></li>
<li><a class="reference external" href="http://www.economist.com/news/briefing/21611074-how-new-technology-shaking-up-oldest-business-more-bang-your-buck">http://www.economist.com/news/briefing/21611074-how-new-technology-shaking-up-oldest-business-more-bang-your-buck</a></li>
<li><a class="reference external" href="http://www.wired.com/2014/08/edward-snowden/">http://www.wired.com/2014/08/edward-snowden/</a></li>
<li><a class="reference external" href="https://medium.com/@sarahkendzior/the-minimum-wage-worker-strikes-back-fa4c36eb306b">https://medium.com/@sarahkendzior/the-minimum-wage-worker-strikes-back-fa4c36eb306b</a></li>
</ul>
Learning GNU screen2014-04-23T12:20:00+02:002014-04-23T12:20:00+02:00Andrew Berezovskyitag:berezovskyi.me,2014-04-23:/2014/04/learning-gnu-screen/<p>I recently started to remotely log into several servers quite often so I felt a need to maintain reliable connections to them and I considered a few choices:</p>
<ul class="simple">
<li><span class="caps">GNU</span> screen</li>
<li><a class="reference external" href="http://mosh.mit.edu">Mosh</a></li>
<li><a class="reference external" href="https://wiki.archlinux.org/index.php/tmux">Tmux</a></li>
</ul>
<p>As the beginner, I decided to stick to the easiest option - <cite>screen</cite>. It comes preinstalled on many server and many administrators install them alongside vim, emacs and git.</p>
<p>I decided to use this blog post for two purposes: to collect the most helpful links to learn screen; and to plan for deeper explorations in future (in this case, Mosh and Tmux).</p>
<div class="section" id="useful-screen-resources">
<h3>Useful screen resources</h3>
<ul class="simple">
<li><a class="reference external" href="http://aperiodic.net/screen/quick_reference#window_management">http://aperiodic.net/screen …</a></li></ul></div><p>I recently started to remotely log into several servers quite often so I felt a need to maintain reliable connections to them and I considered a few choices:</p>
<ul class="simple">
<li><span class="caps">GNU</span> screen</li>
<li><a class="reference external" href="http://mosh.mit.edu">Mosh</a></li>
<li><a class="reference external" href="https://wiki.archlinux.org/index.php/tmux">Tmux</a></li>
</ul>
<p>As the beginner, I decided to stick to the easiest option - <cite>screen</cite>. It comes preinstalled on many server and many administrators install them alongside vim, emacs and git.</p>
<p>I decided to use this blog post for two purposes: to collect the most helpful links to learn screen; and to plan for deeper explorations in future (in this case, Mosh and Tmux).</p>
<div class="section" id="useful-screen-resources">
<h3>Useful screen resources</h3>
<ul class="simple">
<li><a class="reference external" href="http://aperiodic.net/screen/quick_reference#window_management">http://aperiodic.net/screen/quick_reference#window_management</a></li>
<li><a class="reference external" href="http://www.mattcutts.com/blog/a-quick-tutorial-on-screen/">http://www.mattcutts.com/blog/a-quick-tutorial-on-screen/</a></li>
<li><a class="reference external" href="http://www.howtoforge.com/linux_screen">http://www.howtoforge.com/linux_screen</a></li>
<li><a class="reference external" href="http://www.rackaid.com/blog/linux-screen-tutorial-and-how-to/">http://www.rackaid.com/blog/linux-screen-tutorial-and-how-to/</a></li>
<li><a class="reference external" href="http://www.cyberciti.biz/tips/linux-screen-command-howto.html">http://www.cyberciti.biz/tips/linux-screen-command-howto.html</a></li>
<li><a class="reference external" href="http://magazine.redhat.com/2007/09/27/a-guide-to-gnu-screen/">http://magazine.redhat.com/2007/09/27/a-guide-to-gnu-screen/</a></li>
</ul>
</div>
Moving Google Drive folder2014-04-21T20:31:00+02:002014-04-21T20:31:00+02:00Andrew Berezovskyitag:berezovskyi.me,2014-04-21:/2014/04/moving-google-drive-folder/<p><strong><span class="caps">UPD</span>:</strong> My approach was partly successful, because Google Drive still decided to resync all my files after I successfully moved the root folder. If you have any idea what I could’ve missed, you’re welcome to leave a comment below.</p>
<p>Let’s describe what we aim to do: we have Google Drive on our computer in a synced state, but we want to move the <em>whole</em> Google Drive folder to another path (or in case of Windows, most probably - another disk).</p>
<blockquote>
<p>All actions described below were performed on Google Drive for Windows (App version: 1.15.6464.0228). Windows …</p></blockquote><p><strong><span class="caps">UPD</span>:</strong> My approach was partly successful, because Google Drive still decided to resync all my files after I successfully moved the root folder. If you have any idea what I could’ve missed, you’re welcome to leave a comment below.</p>
<p>Let’s describe what we aim to do: we have Google Drive on our computer in a synced state, but we want to move the <em>whole</em> Google Drive folder to another path (or in case of Windows, most probably - another disk).</p>
<blockquote>
<p>All actions described below were performed on Google Drive for Windows (App version: 1.15.6464.0228). Windows version is 6.3 (build 9600) - in other words, it’s Windows 8.1. </p>
<p>You can check the version of your Google Drive client by right-clicking the Google Drive icon in the toolbar and selecting “About”, as shown in the image below.</p>
</blockquote>
<p><img alt="Drive client about window" src="https://berezovskyi.me/static/2014/moving-google-drive-folder/screen-374.png" /></p>
<p><img alt="Drive client version information" src="https://berezovskyi.me/static/2014/moving-google-drive-folder/screen-373.png" /></p>
<p>Google Drive client doesn’t allow you to do such thing by default: it’s not available in settings and if you follow a common advice to close Drive, move the folder and upon a GDrive client start locate a new folder as suggested in a dialog, you’ll end up seeing an alert “This is not your original Google Drive folder”. You can see a screenshot of such a dialog below:</p>
<p><img alt="Drive client missing folder warning" src="https://berezovskyi.me/static/2014/moving-google-drive-folder/relocategoogledrive.png" /></p>
<p>At some point I came across the <a href="https://rainabba.blogspot.se/2013/07/how-to-really-move-your-google-drive.html">article written by Rainabba</a> claiming to describe how to <span class="caps">REALLY</span> [sic] move the GDrive folder. After following his instructions of hex file editing (I used free <a href="https://mh-nexus.de/en/hxd/">HxD hex editor</a>), I was still unable to open the Drive. After trying to open it as a SQLite database, I understood it was damaged because the strings were of different length.</p>
<p>So I decided to edit both files in a correct manner - by using SQLite editor. For this task I decided to use the <a href="https://addons.mozilla.org/en-US/firefox/addon/sqlite-manager/">SQLite Manager</a> which is a Firefox add-on.</p>
<h3 id="main-steps">Main steps<a class="headerlink" href="#main-steps" title="Permanent link">¶</a></h3>
<ol>
<li>Stop Google Drive client. You must close is completely, ensuring the tray icon is not visible. You can verify that the process is not running by pressing <code>Ctrl</code>+<code>Shift</code>+<code>Esc</code> and looking for a process named “googledrivesync.exe” under <em>Details</em> tab.</li>
<li>Update configuration files under <code>C:\Users\*****\AppData\Local\Google\Drive</code>. Here you should replace <code>******</code> by your account name. We’ll dedicate the rest of our discussion to these files.</li>
<li>Start Google Drive. While this time it’ll fail, you’ll get an important value from the log file after this run.</li>
<li>Make final updates to config files.</li>
<li>Run Google Drive successfully.</li>
</ol>
<h3 id="updating-snapshotdb-and-sync_configdb">Updating snapshot.db and sync_config.db<a class="headerlink" href="#updating-snapshotdb-and-sync_configdb" title="Permanent link">¶</a></h3>
<p>We can start by opening <code>sync_config.db</code> in the SQLite Manager:</p>
<p><img alt="" src="https://berezovskyi.me/static/2014/moving-google-drive-folder/screen-375.png" /></p>
<blockquote>
<p>If you can’t see any files, select “All files” in the file extension of the file opening dialog.</p>
</blockquote>
<p>After opening the table <code>data</code> you shall see the following:</p>
<p><img alt="" src="https://berezovskyi.me/static/2014/moving-google-drive-folder/screen-376.png" /></p>
<p>Edit the <code>local_sync_root_path</code> so it now points to a new folder. Just out of a common sense I left the characters <code>\\\\?</code> as in original path.</p>
<p>Now rename the file <code>sync_log.log</code> to some other name, e.g. <code>sync_log.old</code>. We’ll need some data from it later, so a clean log file will be easier for us to search inside.</p>
<p>Next, open the <code>snapshot.db</code>. Open the <code>local_entry</code> table and search for string “Google Drive” as shown below:</p>
<p><img alt="" src="https://berezovskyi.me/static/2014/moving-google-drive-folder/screen-378.png" /></p>
<p>Search results must look like this:</p>
<p><img alt="" src="https://berezovskyi.me/static/2014/moving-google-drive-folder/screen-379.png" /></p>
<p>Edit the path in a same fashion as before. Start Google Drive and it should probably crash. Don’t worry and simply close it. Now open the log file named <code>sync_log.log</code>. We’ll be looking for the following lines inside of it:</p>
<div class="highlight"><pre><span></span><code>2014-04-21 19:31:16,598 +0200 ERROR pid=4932 1220:LaunchThreads
logging:1586 Root inode has changed. Old inode = 1407374883737647,
new inode = 1125899906853835
2014-04-21 19:31:16,598 +0200 ERROR pid=4932 1220:LaunchThreads
common.sync_app:1195 root folder missing or invalid.
</code></pre></div>
<p>If you were attentive, the entry you’ve just edited also had the same id as an “Old inode”. Now we need to update the following items in the database:</p>
<ul>
<li><code>local_entry</code> row with <code>id=1407374883737647</code> (use the value you’ve just obtained).</li>
<li>all rows from <code>local_relation</code> where <code>parent_inode_number=1407374883737647</code></li>
<li>and the final step - row #1 from the <code>mapping</code> table with <code>resource_id</code> <code>folder:root</code>.</li>
</ul>
<p>After you replace all values of the old inode with a new one, start Google Drive client and it should run without giving you any errors.</p>Small plans for January2014-01-13T00:54:00+01:002014-01-13T00:54:00+01:00Andrew Berezovskyitag:berezovskyi.me,2014-01-13:/2014/01/small-plans-for-january/<p>This is a great year, I hope! So in order to make it great, we need to put some efforts to make it bright.</p>
<blockquote>
<div class="line-block">
<div class="line">To strive, to seek, to find, and not to yield</div>
<div class="line">- Alfred Tennyson</div>
</div>
</blockquote>
<p>I have few resolutions for the new year, but nothing earth-shaking:</p>
<ul class="simple">
<li>healthy rythm</li>
<li>productive workflow</li>
<li>more books, less talks</li>
<li>less artificial, more real (people, meal, entertainment)</li>
<li>only grow, always move forward</li>
</ul>
<p>In order to achieve these ambitious goals (I think you shalln’t be deceived by their simplicity), I need to reach some goals:</p>
<ul class="simple">
<li>migrate to Ubuntu successfully (especially solve dependency on those small …</li></ul><p>This is a great year, I hope! So in order to make it great, we need to put some efforts to make it bright.</p>
<blockquote>
<div class="line-block">
<div class="line">To strive, to seek, to find, and not to yield</div>
<div class="line">- Alfred Tennyson</div>
</div>
</blockquote>
<p>I have few resolutions for the new year, but nothing earth-shaking:</p>
<ul class="simple">
<li>healthy rythm</li>
<li>productive workflow</li>
<li>more books, less talks</li>
<li>less artificial, more real (people, meal, entertainment)</li>
<li>only grow, always move forward</li>
</ul>
<p>In order to achieve these ambitious goals (I think you shalln’t be deceived by their simplicity), I need to reach some goals:</p>
<ul class="simple">
<li>migrate to Ubuntu successfully (especially solve dependency on those small Windows-specific tools)</li>
<li>put up the Ubuntu experience post (include the apt restore script from gist)</li>
<li>update <span class="caps">CV</span> to XeLaTeX</li>
<li>clean up my <span class="caps">VPS</span> box (filter out all unneeded hard dependencies in <cite>requirements.txt</cite>, clean up nginx configurations - awstats in <a class="reference external" href="http://www.goitworld.com/analysis-access-logs-of-nginx-by-awstats/">1</a> <a class="reference external" href="http://kamisama.me/2013/03/20/install-configure-and-protect-awstats-for-multiple-nginx-vhost-on-debian/">2</a> <a class="reference external" href="http://blog.bytetouch.com/system-administration/how-to-awstats-installation-and-configuration-on-debian/">3</a>, bandwidth <a class="reference external" href="http://plusbryan.com/my-first-5-minutes-on-a-server-or-essential-security-for-linux-servers">etc</a>)</li>
<li>do all important work <span class="caps">IRL</span></li>
</ul>
<p>Good night, a lot of work ahead!</p>
Creating shortcut function in Fabric to create a Pelican draft2013-12-25T00:00:00+01:002013-12-25T00:00:00+01:00Andrew Berezovskyitag:berezovskyi.me,2013-12-25:/2013/12/creating-shortcut-function-in-fabric-to-create-a-pelican-draft/<p>I migrated from Wordpress to Pelican few month ago and so far I was satisfied with it, mainly because my demands to the blogging platform are far lower than one might imagine. But as atrue engineer, I always strive to eliminate any duplication in code or in actions.</p>
<p>For this reason I’ve created one more Fabric function that creates a draft for me, properly setting the date and slug for me:</p>
<div class="highlight"><pre><span></span><span class="n">drafts_path</span> <span class="o">=</span> <span class="s1">'content/drafts/'</span>
<span class="k">def</span> <span class="nf">draft</span><span class="p">(</span><span class="n">title</span><span class="p">):</span>
<span class="kn">from</span> <span class="nn">datetime</span> <span class="kn">import</span> <span class="n">date</span>
<span class="kn">from</span> <span class="nn">time</span> <span class="kn">import</span> <span class="n">strftime</span><span class="p">,</span> <span class="n">gmtime</span>
<span class="kn">from</span> <span class="nn">unidecode</span> <span class="kn">import</span> <span class="n">unidecode</span>
<span class="kn">import</span> <span class="nn">re</span>
<span class="kn">from</span> <span class="nn">subprocess</span> <span class="kn">import</span> <span class="n">call</span>
<span class="n">today_iso</span> <span class="o">=</span> <span class="n">date</span><span class="o">.</span><span class="n">today …</span></pre></div><p>I migrated from Wordpress to Pelican few month ago and so far I was satisfied with it, mainly because my demands to the blogging platform are far lower than one might imagine. But as atrue engineer, I always strive to eliminate any duplication in code or in actions.</p>
<p>For this reason I’ve created one more Fabric function that creates a draft for me, properly setting the date and slug for me:</p>
<div class="highlight"><pre><span></span><span class="n">drafts_path</span> <span class="o">=</span> <span class="s1">'content/drafts/'</span>
<span class="k">def</span> <span class="nf">draft</span><span class="p">(</span><span class="n">title</span><span class="p">):</span>
<span class="kn">from</span> <span class="nn">datetime</span> <span class="kn">import</span> <span class="n">date</span>
<span class="kn">from</span> <span class="nn">time</span> <span class="kn">import</span> <span class="n">strftime</span><span class="p">,</span> <span class="n">gmtime</span>
<span class="kn">from</span> <span class="nn">unidecode</span> <span class="kn">import</span> <span class="n">unidecode</span>
<span class="kn">import</span> <span class="nn">re</span>
<span class="kn">from</span> <span class="nn">subprocess</span> <span class="kn">import</span> <span class="n">call</span>
<span class="n">today_iso</span> <span class="o">=</span> <span class="n">date</span><span class="o">.</span><span class="n">today</span><span class="p">()</span><span class="o">.</span><span class="n">isoformat</span><span class="p">()</span>
<span class="n">now_iso</span> <span class="o">=</span> <span class="n">strftime</span><span class="p">(</span><span class="s2">"%Y-%m-</span><span class="si">%d</span><span class="s2"> %H:%M"</span><span class="p">,</span> <span class="n">gmtime</span><span class="p">())</span>
<span class="n">file_slug</span> <span class="o">=</span> <span class="n">unidecode</span><span class="p">(</span><span class="n">title</span><span class="o">.</span><span class="n">decode</span><span class="p">(</span><span class="s1">'utf-8'</span><span class="p">))</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span>
<span class="n">file_slug</span> <span class="o">=</span> <span class="n">re</span><span class="o">.</span><span class="n">sub</span><span class="p">(</span><span class="s2">"\s+"</span><span class="p">,</span> <span class="s2">"-"</span><span class="p">,</span> <span class="n">file_slug</span><span class="p">)</span>
<span class="n">file_slug</span> <span class="o">=</span> <span class="n">re</span><span class="o">.</span><span class="n">sub</span><span class="p">(</span><span class="s2">"[-]+"</span><span class="p">,</span> <span class="s2">"-"</span><span class="p">,</span> <span class="n">file_slug</span><span class="p">)</span><span class="o">.</span><span class="n">lstrip</span><span class="p">(</span><span class="s1">'-'</span><span class="p">)</span>
<span class="n">file_name</span> <span class="o">=</span> <span class="s2">"</span><span class="si">%s</span><span class="s2">-</span><span class="si">%s</span><span class="s2">.rst"</span> <span class="o">%</span> <span class="p">(</span><span class="n">today_iso</span><span class="p">,</span> <span class="n">file_slug</span><span class="p">)</span>
<span class="n">file_path</span> <span class="o">=</span> <span class="s2">"</span><span class="si">%s%s</span><span class="s2">"</span> <span class="o">%</span> <span class="p">(</span><span class="n">drafts_path</span><span class="p">,</span> <span class="n">file_name</span><span class="p">)</span>
<span class="k">if</span> <span class="ow">not</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">exists</span><span class="p">(</span><span class="n">file_path</span><span class="p">):</span>
<span class="n">draft_fd</span> <span class="o">=</span> <span class="nb">open</span><span class="p">(</span><span class="n">file_path</span><span class="p">,</span> <span class="s2">"w+"</span><span class="p">)</span>
<span class="nb">print</span><span class="p">(</span><span class="n">title</span><span class="p">,</span> <span class="n">file</span><span class="o">=</span><span class="n">draft_fd</span><span class="p">)</span>
<span class="nb">print</span><span class="p">(</span><span class="s1">'='</span><span class="o">*</span><span class="nb">len</span><span class="p">(</span><span class="n">title</span><span class="p">),</span> <span class="n">file</span><span class="o">=</span><span class="n">draft_fd</span><span class="p">)</span>
<span class="nb">print</span><span class="p">(</span><span class="s1">''</span><span class="p">,</span> <span class="n">file</span><span class="o">=</span><span class="n">draft_fd</span><span class="p">)</span>
<span class="nb">print</span><span class="p">(</span><span class="s1">':date: </span><span class="si">%s</span><span class="s1">'</span> <span class="o">%</span> <span class="n">now_iso</span><span class="p">,</span> <span class="n">file</span><span class="o">=</span><span class="n">draft_fd</span><span class="p">)</span>
<span class="nb">print</span><span class="p">(</span><span class="s1">':slug: </span><span class="si">%s</span><span class="s1">'</span> <span class="o">%</span> <span class="n">file_slug</span><span class="p">,</span> <span class="n">file</span><span class="o">=</span><span class="n">draft_fd</span><span class="p">)</span>
<span class="nb">print</span><span class="p">(</span><span class="s1">':status: draft'</span><span class="p">,</span> <span class="n">file</span><span class="o">=</span><span class="n">draft_fd</span><span class="p">)</span>
<span class="nb">print</span><span class="p">(</span><span class="s1">''</span><span class="p">,</span> <span class="n">file</span><span class="o">=</span><span class="n">draft_fd</span><span class="p">)</span>
<span class="n">draft_fd</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
<span class="k">else</span><span class="p">:</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">"WARNING: file already exists"</span><span class="p">)</span>
<span class="n">call</span><span class="p">([</span><span class="s1">'editor'</span><span class="p">,</span> <span class="n">file_path</span><span class="p">])</span>
</pre></div>
Pelican on Windows2013-10-03T15:37:00+02:002013-10-03T15:37:00+02:00admintag:berezovskyi.me,2013-10-03:/2013/10/pelican-on-windows/<p>I enjoy using pelican so for so much. However, few issues hit my mind recently:</p>
<ul class="simple">
<li><a class="reference external" href="http://medium.com">Medium</a> is such a nice place to write that I can merely resist my temptation;</li>
<li>There is no ability to run person search across the static website;</li>
<li>I’m tied to <span class="caps">UNIX</span> environment in order to run the Pelican development server for preview.</li>
</ul>
<p>I recalled a great quote:</p>
<blockquote>
<p>Once you say you’re going to settle for second, that’s what happens to you in life.</p>
<p class="attribution">—John F. Kennedy</p>
</blockquote>
<p>So I decided to see if it’s possible to resolve all of that issues for …</p><p>I enjoy using pelican so for so much. However, few issues hit my mind recently:</p>
<ul class="simple">
<li><a class="reference external" href="http://medium.com">Medium</a> is such a nice place to write that I can merely resist my temptation;</li>
<li>There is no ability to run person search across the static website;</li>
<li>I’m tied to <span class="caps">UNIX</span> environment in order to run the Pelican development server for preview.</li>
</ul>
<p>I recalled a great quote:</p>
<blockquote>
<p>Once you say you’re going to settle for second, that’s what happens to you in life.</p>
<p class="attribution">—John F. Kennedy</p>
</blockquote>
<p>So I decided to see if it’s possible to resolve all of that issues for me.</p>
<div class="section" id="medium-1">
<h3>Medium</h3>
<p>Once I started to look closer at <em>Medium</em>, I started to realized that 90% of jealousy will be solved by simply getting nice-looking fonts.</p>
<p>Fonts used by <em>Medium</em>:</p>
<ul class="simple">
<li><a class="reference external" href="https://typekit.com/fonts/freight-sans-pro">Freight Sans Pro</a></li>
<li><a class="reference external" href="https://typekit.com/fonts/ff-tisa-web-pro"><span class="caps">FF</span> Tisa Pro</a></li>
</ul>
<p>What I used instead:</p>
<ul class="simple">
<li><a class="reference external" href="http://www.google.com/fonts/specimen/Source+Sans+Pro">Source Sans Pro</a></li>
<li><a class="reference external" href="http://www.google.com/fonts/specimen/Noto+Sans">Noto Sans</a></li>
</ul>
<p>Future improvements:</p>
<ul class="simple">
<li><a class="reference external" href="http://www.fontsquirrel.com/fonts/list/style/Slab%20Serif">Slab Serif fonts on FontSquirrel</a></li>
<li><a class="reference external" href="http://www.fontsquirrel.com/fonts/arvo">Arvo on FontSquirrel</a></li>
<li><a class="reference external" href="http://www.losttype.com/klinic/"><span class="caps">KLINIC</span> <span class="caps">SLAB</span></a></li>
<li><a class="reference external" href="http://dzineblog.com/2012/01/28-free-slab-serif-fonts.html">28 Free Slab Serif Fonts</a></li>
<li><a class="reference external" href="http://designinstruct.com/articles/resources/font-collections/free-slab-serif-fonts/">10 Beautiful and Free Slab Serif Fonts</a></li>
</ul>
<p>Some fonts are not provided web-friendly format. FontSqirell’s <a class="reference external" href="http://www.fontsquirrel.com/tools/webfont-generator">WebFont Generator</a> is designed to solve this issue.</p>
<p>Oh, yeah, <em>Medium</em> promises true <span class="caps">WISIWIG</span>. <a class="reference external" href="http://docutils.sourceforge.net/docs/user/rst/quickref.html">Learn <span class="caps">RST</span></a>, bitch!</p>
</div>
<div class="section" id="running-pelican-on-windows">
<h3>Running Pelican on Windows</h3>
<p>In order to use it, you need to install few packages build for you by 3rd parties:</p>
<ul class="simple">
<li><a class="reference external" href="http://www.lfd.uci.edu/~gohlke/pythonlibs/#lxml"><span class="caps">LXML</span></a></li>
<li><a class="reference external" href="http://www.voidspace.org.uk/python/modules.shtml#pycrypto">PyCrypto</a> (needed for Fabric)</li>
</ul>
<p>Then you can run <cite>pip install -r requirements.txt</cite> with Administrator priviledges.</p>
<p>Then, depending on your template, you might need to replace the date/time format only available under <span class="caps">UNIX</span> with a generic one (See <a class="reference external" href="http://docs.python.org/2/library/datetime.html#strftime-strptime-behavior">strftime directives</a>).</p>
</div>
Rename all *.rst files in a directory according to their date2013-08-10T20:25:00+02:002013-08-10T20:25:00+02:00Andrew Berezovskyitag:berezovskyi.me,2013-08-10:/2013/08/rename-rst-by-date/<p><strong><span class="caps">TODO</span>:</strong></p>
<ul class="simple">
<li>add verbose mode</li>
<li>move awk output into variable and test if file already begins with a date</li>
</ul>
<div class="highlight"><pre><span></span><span class="ch">#!/bin/sh</span>
<span class="k">for</span><span class="w"> </span>f<span class="w"> </span><span class="k">in</span><span class="w"> </span><span class="k">$(</span>find<span class="w"> </span>./content/<span class="w"> </span>-name<span class="w"> </span><span class="s1">'*.rst'</span><span class="k">)</span><span class="p">;</span><span class="w"> </span><span class="k">do</span>
<span class="w"> </span><span class="nv">name</span><span class="o">=</span><span class="k">$(</span>basename<span class="w"> </span><span class="s2">"</span><span class="nv">$f</span><span class="s2">"</span><span class="k">)</span>
<span class="w"> </span><span class="nv">dd</span><span class="o">=</span><span class="k">$(</span>dirname<span class="w"> </span><span class="s2">"</span><span class="nv">$f</span><span class="s2">"</span><span class="k">)</span>
<span class="w"> </span><span class="nv">d</span><span class="o">=</span><span class="s2">"</span><span class="nv">$dd</span><span class="s2">/</span><span class="k">$(</span>cat<span class="w"> </span><span class="s2">"</span><span class="nv">$f</span><span class="s2">"</span><span class="w"> </span><span class="p">|</span><span class="w"> </span>grep<span class="w"> </span><span class="s1">':date:'</span><span class="w"> </span><span class="p">|</span><span class="w"> </span>awk<span class="w"> </span><span class="s1">'{print $2}'</span><span class="k">)</span><span class="s2">-</span><span class="nv">$name</span><span class="s2">"</span>
<span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="o">[</span><span class="w"> </span>!<span class="w"> </span>-f<span class="w"> </span><span class="s2">"</span><span class="nv">$d</span><span class="s2">"</span><span class="w"> </span><span class="o">]</span><span class="p">;</span><span class="w"> </span><span class="k">then</span>
<span class="w"> </span>mv<span class="w"> </span><span class="s2">"</span><span class="nv">$f</span><span class="s2">"</span><span class="w"> </span><span class="s2">"</span><span class="nv">$d</span><span class="s2">"</span>
<span class="w"> </span><span class="k">else</span>
<span class="w"> </span><span class="nb">echo</span><span class="w"> </span><span class="s2">"File '</span><span class="nv">$d</span><span class="s2">' already exists! Skiped '</span><span class="nv">$f</span><span class="s2">'"</span>
<span class="w"> </span><span class="k">fi</span>
<span class="k">done</span>
</pre></div>
Pro Git2013-06-14T21:04:00+02:002013-06-14T21:04:00+02:00Andrew Berezovskyitag:berezovskyi.me,2013-06-14:/2013/06/pro-git/<p>Over years, I used Git a lot but I can hardly name myself a proficient git user. More or less it can be due to lack of learning discipline. I never learned Git specifically.</p>
<p>Recently I started to notice that most of the problems I’m trying to resolve were successfully resolved before. And it’s a good fit for my blogging ‘deep dive into linux’ topic to write a post or two about my git experience and tips.</p>Moving from Jekyll to Octopress2013-06-14T19:55:00+02:002013-06-14T19:55:00+02:00Andrew Berezovskyitag:berezovskyi.me,2013-06-14:/2013/06/moving-from-jekyll-to-octopress/<p>Hi again. Today I can proudly say that I was productively procrastinating! As you might know, my “Deep dive into Linux” journey has just began and today it saved me at least few hours.</p>
<p>While cleaning up my <span class="caps">1TB</span> drive residing inside my desktop to make sure that all junk is removed whereas all important files are properly backed up to the cloud, I noticed that inside my old website folder there were at least 7 backup archives which were almost identical. They were consuming a lot of space and since going to the university I’ve being actively using …</p><p>Hi again. Today I can proudly say that I was productively procrastinating! As you might know, my “Deep dive into Linux” journey has just began and today it saved me at least few hours.</p>
<p>While cleaning up my <span class="caps">1TB</span> drive residing inside my desktop to make sure that all junk is removed whereas all important files are properly backed up to the cloud, I noticed that inside my old website folder there were at least 7 backup archives which were almost identical. They were consuming a lot of space and since going to the university I’ve being actively using <code>git</code> to keep my bacon safe ;) But that website was initially developed while I was back in school and knew nothing about <span class="caps">VCS</span>.</p>
<p>And I already had a repository containing the last backup as initial commit and a hadful of improvements. So I decided to create a new repository and progressively unpack backups in historical order. After I finished, I got the following commit history:</p>
<div class="highlight"><pre><span></span><code>* a662b50 2013-06-14 '2011-11-30 CHANGES'
* 4849770 2013-06-14 '2011-11-30 gitignore update'
* 651073d 2013-06-14 '2011-11-30 REMOVE log file'
* 020d015 2011-09-19 '2011-09-19 REMOVED'
* b266571 2011-09-19 '2011-09-19 ADDED'
* 240cda1 2011-09-19 '2011-09-19 UPDATE GITIGNORE'
* 12d0ff6 2011-09-19 '2011-09-19 CHANGED'
* c6aff9f 2011-08-23 '2011-08-23 ADDED'
* e8f3ca3 2011-08-23 '2011-08-23 change DB name'
* 5815657 2011-08-23 '2011-08-23 Add wr-counter'
* b852e21 2011-08-23 '2011-08-23 Add IO-82 photo session album'
* 888c1af 2011-08-23 '2011-08-23 Add softtime poll'
* 6d93120 2011-08-23 '2011-08-23 Add poll'
* e126ebd 2011-08-23 'Remove DB files'
* 3a5e42d 2011-04-25 '2011-04-25 CHANGED'
* 3ea7973 2011-03-08 '2011-03-08 ADDED/REMOVED'
* 7b83c77 2011-03-08 '2011-03-08 CHANGED'
* 7f25721 2011-03-08 'Ignore cache files'
* c32668f 2011-01-08 '2011-01-21 NEW FILES'
* 4078adc 2011-01-08 '2011-01-21 CHANGES'
* 7a974c1 2010-01-17 '2010-01-17'
* 70bf95b 2010-01-17 'Add gitignore file'
</code></pre></div>
<p>Well, wait. Here comes a little bit of magic. How I managed to make commits with correct dates? In short, I forgot. So I had to find a solution afterwards, which turned out to be simple, but took some time to apply correctly:</p>
<div class="highlight"><pre><span></span><code>git<span class="w"> </span>filter-branch<span class="w"> </span>-f<span class="w"> </span>--env-filter<span class="w"> </span><span class="se">\</span>
<span class="w"> </span><span class="s1">'if [ $GIT_COMMIT = 651073d077e66282f1bd19ad55111ba5e07fad10 ]</span>
<span class="s1"> then</span>
<span class="s1"> export GIT_AUTHOR_DATE="2011-11-30T15:40:00"</span>
<span class="s1"> export GIT_COMMITTER_DATE="2011-11-30T15:40:00"</span>
<span class="s1"> fi</span>
<span class="s1"> if [ $GIT_COMMIT = 48497704ac731d337c7fd48c4f6139abd9972af9 ]</span>
<span class="s1"> then</span>
<span class="s1"> export GIT_AUTHOR_DATE="2011-11-30T15:41:00"</span>
<span class="s1"> export GIT_COMMITTER_DATE="2011-11-30T15:41:00"</span>
<span class="s1"> fi</span>
<span class="s1"> if [ $GIT_COMMIT = a662b50db73872d8cb14602eb6b7f7288b778fc6 ]</span>
<span class="s1"> then</span>
<span class="s1"> export GIT_AUTHOR_DATE="2011-11-30T15:42:00"</span>
<span class="s1"> export GIT_COMMITTER_DATE="2011-11-30T15:42:00"</span>
<span class="s1"> fi'</span>
</code></pre></div>
<p>Apply this code with care and note that <code>-f</code> switch must go directly after <code>filter-branch</code>. Hope this will save you a lot of time.</p>
<p>After that I began searching the internet for a repository concatenating solution. Task: there are two folders with a git repository in each and identical folder stucture;commit tree is almost flat; need to <strong>merge two repositories</strong> into one and <strong>preserve commit history</strong> (both).</p>
<p>What I stumbled across was a <a href="https://search.cpan.org/dist/Git-FastExport/lib/Git/FastExport/Stitch.pm">Git-FastExport <span class="caps">CPAN</span> module</a> and a script <code>git-stitch-repo</code>. Before proceeding, I installed <code>cpanminus</code>:</p>
<div class="highlight"><pre><span></span><code>sudo<span class="w"> </span>apt-get<span class="w"> </span>install<span class="w"> </span>liblocal-lib-perl
sudo<span class="w"> </span>apt-get<span class="w"> </span>install<span class="w"> </span>cpanminus
cpanm<span class="w"> </span>Git::FastExport::Stitch
</code></pre></div>
<p>I fetched working repository into folder <code>smartfon</code> and backup repository into folder <code>smartfon-archive</code>. I also created folder <code>smarfon-result</code> and initialized empty git repository there.</p>
<p>Then I ran the following command from <code>smarfon-result</code>:</p>
<div class="highlight"><pre><span></span><code>git-stitch-repo<span class="w"> </span>../smartfon-archive<span class="w"> </span>../smartfon<span class="w"> </span><span class="p">|</span><span class="w"> </span>/usr/lib/git-core/git-fast-import<span class="w"> </span>
</code></pre></div>
<p>Then a saw the following commit tree:</p>
<div class="highlight"><pre><span></span><code>* 6206703 2013-05-21 'fix xmlns'
* c5b065e 2013-05-21 'add self-link'
* a0926da 2013-05-21 'Fix the rss link'
...
* f693806 2013-05-18 'remove unused external scripts'
* 2b2bece 2013-05-18 'Initial commit'
* 020d015 2011-09-19 '2011-09-19 REMOVED'
* b266571 2011-09-19 '2011-09-19 ADDED'
* 240cda1 2011-09-19 '2011-09-19 UPDATE GITIGNORE'
* 12d0ff6 2011-09-19 '2011-09-19 CHANGED'
* c6aff9f 2011-08-23 '2011-08-23 ADDED'
* e8f3ca3 2011-08-23 '2011-08-23 change DB name'
* 5815657 2011-08-23 '2011-08-23 Add wr-counter'
* b852e21 2011-08-23 '2011-08-23 Add IO-82 photo session album'
* 888c1af 2011-08-23 '2011-08-23 Add softtime poll'
* 6d93120 2011-08-23 '2011-08-23 Add poll'
* e126ebd 2011-08-23 'Remove DB files'
* 3a5e42d 2011-04-25 '2011-04-25 CHANGED'
* 3ea7973 2011-03-08 '2011-03-08 ADDED/REMOVED'
* 7b83c77 2011-03-08 '2011-03-08 CHANGED'
* 7f25721 2011-03-08 'Ignore cache files'
* c32668f 2011-01-08 '2011-01-21 NEW FILES'
* 4078adc 2011-01-08 '2011-01-21 CHANGES'
* 7a974c1 2010-01-17 '2010-01-17'
* 70bf95b 2010-01-17 'Add gitignore file'
</code></pre></div>Things that drive me mad about Linux2013-06-14T12:17:43+02:002013-06-14T12:17:43+02:00Andrew Berezovskyitag:berezovskyi.me,2013-06-14:/2013/06/things-that-drive-me-mad-about-linux/<p>I was having many talks with Linux aficionados who argued that my only obstacle on the way to Linux was lack of knowledge and experience. While I agree for 100% with their opinion, I have few more things to deal with in Linux:</p>
<!--more-->
<h2 id="multimedia">Multimedia<a class="headerlink" href="#multimedia" title="Permanent link">¶</a></h2>
<p>Everyone knows that multimedia support in Linux is … how to put it mildly, inferior.</p>
<p>First of all, Skype sound quality. I desperately need good sound and reliable connection.</p>
<p>Next, for my surprise, I’m using multimedia player quite often. On Windows, my player of preference is PotPlayer/KMPlayer. Unfortunately, I haven’t found anything similar to …</p><p>I was having many talks with Linux aficionados who argued that my only obstacle on the way to Linux was lack of knowledge and experience. While I agree for 100% with their opinion, I have few more things to deal with in Linux:</p>
<!--more-->
<h2 id="multimedia">Multimedia<a class="headerlink" href="#multimedia" title="Permanent link">¶</a></h2>
<p>Everyone knows that multimedia support in Linux is … how to put it mildly, inferior.</p>
<p>First of all, Skype sound quality. I desperately need good sound and reliable connection.</p>
<p>Next, for my surprise, I’m using multimedia player quite often. On Windows, my player of preference is PotPlayer/KMPlayer. Unfortunately, I haven’t found anything similar to these players.</p>
<h2 id="development">Development<a class="headerlink" href="#development" title="Permanent link">¶</a></h2>
<p>I’m using .<span class="caps">NET</span> platform to earn for bread and butter. I heavily use a multitude of refactoring tools and other helpers unavailable in languages which allow more freedom, like C++, Python, Ruby and other.</p>
<p>Maybe, some time later, I’ll eventually become a better programmer and get rid of tooling dependency, but for now I see that it’s the only way to manage complexity of large projects efficiently.</p>
<h2 id="drivers-and-support">Drivers and support<a class="headerlink" href="#drivers-and-support" title="Permanent link">¶</a></h2>
<p>Unfortunately, power consumption on Linux is often more than on Windows due to unoptimized processor frequency scaling, powering of periferal devices and other problems.</p>mkpost for Jekyll2013-06-14T03:38:46+02:002013-06-14T03:38:46+02:00Andrew Berezovskyitag:berezovskyi.me,2013-06-14:/2013/06/mkpost-for-jekyll/<p>In order to speedup post creation, I found and improved a simple Ruby script:</p>
<div class="highlight"><pre><span></span><code><span class="ch">#!/usr/bin/ruby</span>
<span class="nb">require</span><span class="w"> </span><span class="s1">'date'</span>
<span class="nb">require</span><span class="w"> </span><span class="s1">'time'</span>
<span class="nb">puts</span><span class="w"> </span><span class="s1">'What would you like to write about?'</span>
<span class="n">article_title</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="nb">gets</span>
<span class="n">slug</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">article_title</span><span class="o">.</span><span class="n">downcase</span><span class="o">.</span><span class="n">strip</span><span class="o">.</span><span class="n">gsub</span><span class="p">(</span><span class="s1">' '</span><span class="p">,</span><span class="w"> </span><span class="s1">'-'</span><span class="p">)</span>
<span class="n">current_date</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="no">Date</span><span class="o">.</span><span class="n">today</span><span class="o">.</span><span class="n">to_s</span>
<span class="n">current_time</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="no">Time</span><span class="o">.</span><span class="n">now</span>
<span class="n">filename</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">current_date</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="s1">'-'</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="n">slug</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="s1">'.md'</span>
<span class="no">File</span><span class="o">.</span><span class="n">open</span><span class="p">(</span><span class="s2">"_posts/"</span><span class="o">+</span><span class="n">filename</span><span class="p">,</span><span class="w"> </span><span class="s2">"w"</span><span class="p">)</span><span class="w"> </span><span class="k">do</span><span class="w"> </span><span class="o">|</span><span class="n">post</span><span class="o">|</span>
<span class="w"> </span><span class="n">post</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s2">"---</span><span class="se">\n</span><span class="s2">"</span><span class="p">)</span>
<span class="w"> </span><span class="n">post</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s2">"layout: post</span><span class="se">\n</span><span class="s2">"</span><span class="p">)</span>
<span class="w"> </span><span class="n">post</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s2">"title: </span><span class="si">#{</span><span class="n">article_title</span><span class="si">}</span><span class="s2">"</span><span class="p">)</span>
<span class="w"> </span><span class="n">post</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s2">"date: </span><span class="si">#{</span><span class="n">current_time</span><span class="si">}</span><span class="se">\n</span><span class="s2">"</span><span class="p">)</span>
<span class="w"> </span><span class="n">post</span><span class="o">.</span><span class="n">write</span><span class="p">(</span><span class="s2">"---"</span><span class="p">)</span>
<span class="k">end</span>
<span class="nb">puts</span><span class="w"> </span><span class="s1">'Created new file here: _/posts/'</span><span class="o">+</span><span class="n">filename</span>
<span class="c1"># fire up sublime text</span>
<span class="nb">system</span><span class="p">(</span><span class="s2">"subl '_posts/</span><span class="si">#{</span><span class="n">filename</span><span class="si">}</span><span class="s2">' &"</span><span class="p">)</span>
</code></pre></div>VIM %crazy%2013-06-14T02:52:03+02:002013-06-14T02:52:03+02:00Andrew Berezovskyitag:berezovskyi.me,2013-06-14:/2013/06/vim-crazy/<p>Well, I have a very simple use-case: I just copied a chunk of text and it contains line numbers. Can vim handle it??</p>
<p>Easy:</p>
<div class="highlight"><pre><span></span><code><span class="p">:</span>%normal <span class="m">2</span>x
</code></pre></div>
<!-- test -->Jekyll Web Log2013-06-14T02:25:53+02:002013-06-14T02:25:53+02:00Andrew Berezovskyitag:berezovskyi.me,2013-06-14:/2013/06/jekyll-web-log/<p>Hi folks.</p>
<p>From the very beginning, I’d like to say that I’m an avid Windows user. <span class="caps">RMS</span> thinks that we shouldn’t give away freedom in exchange for convenience. Truthfully, I had to fuck a lot with my Ubuntu installation to work properly, to stop hanging on boot, shut down in less than a minute, use two GPUs correctly, stop eating my battery worse than a Hulk and … I think, usual people deserve <em>this</em> convenience <span class="caps">NOT</span> <span class="caps">TO</span> <span class="caps">DO</span> <span class="caps">IT</span> <span class="caps">EVERY</span> <span class="caps">TIME</span> <span class="caps">THEY</span> <span class="caps">BUY</span> A <span class="caps">PC</span>!</p>
<p>But still, I was feeling pretty miserably to fail short with my Linux …</p><p>Hi folks.</p>
<p>From the very beginning, I’d like to say that I’m an avid Windows user. <span class="caps">RMS</span> thinks that we shouldn’t give away freedom in exchange for convenience. Truthfully, I had to fuck a lot with my Ubuntu installation to work properly, to stop hanging on boot, shut down in less than a minute, use two GPUs correctly, stop eating my battery worse than a Hulk and … I think, usual people deserve <em>this</em> convenience <span class="caps">NOT</span> <span class="caps">TO</span> <span class="caps">DO</span> <span class="caps">IT</span> <span class="caps">EVERY</span> <span class="caps">TIME</span> <span class="caps">THEY</span> <span class="caps">BUY</span> A <span class="caps">PC</span>!</p>
<p>But still, I was feeling pretty miserably to fail short with my Linux experience while I was reading <em>Linux System Programming, 2nd Edition by Robert Love</em> and decided to fix it. Anyway, I can’t recall how many times I reinstalled Linux and decided to start from scratch so finally I decided to write all the breathtaking steps from my long journey here.</p>
<!--more-->
<p>As I decided to take the hard path, I also set out to change few more usual parts involved in the process:</p>
<ul>
<li>blog engine</li>
<li>fight plan</li>
</ul>
<p>In regard to blog engine, this is exactly the post devoted to it. I decided to use jekyll because of the following benefits:</p>
<ul>
<li>I’ll have no manual helpers, so I’ll finally learn how to type fast.</li>
<li>It’s written in Ruby and I always dreamed about learning it.</li>
<li>I can impove my text editor usage skills.</li>
</ul>
<p>So I decided to dump beloved Wordpress.</p>
<h2 id="what-ill-be-writing-about">What I’ll be writing about<a class="headerlink" href="#what-ill-be-writing-about" title="Permanent link">¶</a></h2>
<ul>
<li>New programming languages and related experiences;</li>
<li><span class="caps">VIM</span> / Emacs tips;</li>
<li>Linux usage, administration and daily routine;</li>
<li>Thoughts on computing in general, but I’ll keep’em as short as possible;</li>
<li>Debian/Ubuntu packages, sources and PPAs;</li>
<li>LaTeX.</li>
</ul>
<p>This list can expand but I already think it’s a lot.</p>Debian and Ubuntu server locale and encoding2013-04-14T01:09:00+02:002013-04-14T01:09:00+02:00admintag:berezovskyi.me,2013-04-14:/2013/04/debian-and-ubuntu-server-locale-and-encoding/<p>I recently had “fun” supporting server installation of software that
needed locale set properly.</p>
<p>In Debian, you can just use</p>
<pre class="literal-block">
dpkg-reconfigure locales
</pre>
<p>and the console <span class="caps">GUI</span> will pop up.</p>
<p>In Ubuntu server, you’ll have to make more steps:</p>
<p><a class="reference external" href="http://askubuntu.com/questions/89976/how-to-change-the-default-locale-in-ubuntu-10-10-server">http://askubuntu.com/questions/89976/how-to-change-the-default-locale-in-ubuntu-10-10-server</a></p>
<p><a class="reference external" href="https://debian.pro/503">https://debian.pro/503</a></p>
<p><a class="reference external" href="https://help.ubuntu.com/community/Locale">https://help.ubuntu.com/community/Locale</a></p>
<p>And make full use of <span class="caps">UTF</span>,
please: <a class="reference external" href="http://docs.python.org/2/library/locale.html">http://docs.python.org/2/library/locale.html</a></p>
Grave accent in C# class names2013-04-02T16:42:00+02:002013-04-02T16:42:00+02:00admintag:berezovskyi.me,2013-04-02:/2013/04/grave-accent-in-c-class-names/<p>For generic interfaces, the name parameter is the mangled name,
ending with a grave accent (`) and the number of type parameters.
This is true for both generic interface definitions and constructed
generic interfaces. For example, to find <cite>IExample<T></cite> (<cite>IExample(Of T)</cite>
in Visual Basic) or <cite>IExample<string></cite> (<cite>IExample(Of String)</cite> in Visual
Basic), search for “IExample`1”.</p>
<p>From <a class="reference external" href="http://msdn.microsoft.com/en-us/library/ayfa0fcd.aspx">Type.GetInterface Method (String) <span class="caps">MSDN</span> reference page</a></p>
Migration off GMail as part of “spring cleaning”2013-03-30T16:26:00+01:002013-03-30T16:26:00+01:00admintag:berezovskyi.me,2013-03-30:/2013/03/migration-off-gmail-as-part-of-spring-cleaning/<p><strong><span class="caps">UPD</span> Apr ‘14:</strong> Awesome <a class="reference external" href="https://github.com/JoshData/mailinabox">setup scripts</a> got featured on <span class="caps">HN</span>.</p>
<hr class="docutils" />
<p><strong><span class="caps">UPD</span> Mar ‘14:</strong> <em>How to run your own e-mail server with your own domain</em> series on Ars Technica:
<a class="reference external" href="http://arstechnica.com/information-technology/2014/02/how-to-run-your-own-e-mail-server-with-your-own-domain-part-1/">part 1</a>,
<a class="reference external" href="http://arstechnica.com/information-technology/2014/03/taking-e-mail-back-part-2-arming-your-server-with-postfix-dovecot/">part2</a>,
<a class="reference external" href="http://arstechnica.com/business/2014/03/taking-e-mail-back-part-3-fortifying-your-box-against-spammers/">part 3</a>,
<a class="reference external" href="http://arstechnica.com/information-technology/2014/04/taking-e-mail-back-part-4-the-finale-with-webmail-everything-after/">part 4</a>.</p>
<hr class="docutils" />
<p>As part of <a class="reference external" href="http://googleblog.blogspot.ca/2013/03/a-second-spring-of-cleaning.html">“spring cleaning”</a>, Google Reader was scheduled to be shut down.</p>
<p><a class="reference external" href="http://www.slate.com/blogs/future_tense/2013/03/26/andrew_weissmann_fbi_wants_real_time_gmail_dropbox_spying_power.html"><span class="caps">FBI</span> is working with “members of intelligence community” to craft a
proposal for new Internet spy powers as “a top priority this year.”</a></p>
<p>Well, I now have a perfect reason to draft my personal roadmap for this
year and to list tools I’m going to use.</p>
<p><a class="reference external" href="http://library.linode.com/email/postfix/dovecot-mysql-debian-6-squeeze">http://library.linode.com/email …</a></p><p><strong><span class="caps">UPD</span> Apr ‘14:</strong> Awesome <a class="reference external" href="https://github.com/JoshData/mailinabox">setup scripts</a> got featured on <span class="caps">HN</span>.</p>
<hr class="docutils" />
<p><strong><span class="caps">UPD</span> Mar ‘14:</strong> <em>How to run your own e-mail server with your own domain</em> series on Ars Technica:
<a class="reference external" href="http://arstechnica.com/information-technology/2014/02/how-to-run-your-own-e-mail-server-with-your-own-domain-part-1/">part 1</a>,
<a class="reference external" href="http://arstechnica.com/information-technology/2014/03/taking-e-mail-back-part-2-arming-your-server-with-postfix-dovecot/">part2</a>,
<a class="reference external" href="http://arstechnica.com/business/2014/03/taking-e-mail-back-part-3-fortifying-your-box-against-spammers/">part 3</a>,
<a class="reference external" href="http://arstechnica.com/information-technology/2014/04/taking-e-mail-back-part-4-the-finale-with-webmail-everything-after/">part 4</a>.</p>
<hr class="docutils" />
<p>As part of <a class="reference external" href="http://googleblog.blogspot.ca/2013/03/a-second-spring-of-cleaning.html">“spring cleaning”</a>, Google Reader was scheduled to be shut down.</p>
<p><a class="reference external" href="http://www.slate.com/blogs/future_tense/2013/03/26/andrew_weissmann_fbi_wants_real_time_gmail_dropbox_spying_power.html"><span class="caps">FBI</span> is working with “members of intelligence community” to craft a
proposal for new Internet spy powers as “a top priority this year.”</a></p>
<p>Well, I now have a perfect reason to draft my personal roadmap for this
year and to list tools I’m going to use.</p>
<p><a class="reference external" href="http://library.linode.com/email/postfix/dovecot-mysql-debian-6-squeeze">http://library.linode.com/email/postfix/dovecot-mysql-debian-6-squeeze</a></p>
<p><a class="reference external" href="http://paul.frields.org/?p=2609">http://paul.frields.org/?p=2609</a></p>
<p><a class="reference external" href="http://paul.frields.org/?p=2616">http://paul.frields.org/?p=2616</a></p>
<p><a class="reference external" href="http://paul.frields.org/?p=2636">http://paul.frields.org/?p=2636</a></p>
<p><a class="reference external" href="http://technosorcery.net/blog/2010/11/21/offline-email-with-gmail-mutt-postfix-and-offlineimap/">http://technosorcery.net/blog/2010/11/21/offline-email-with-gmail-mutt-postfix-and-offlineimap/</a></p>
ASP MVC Pipeline2013-03-06T01:11:00+01:002013-03-06T01:11:00+01:00admintag:berezovskyi.me,2013-03-06:/2013/03/asp-mvc-pipeline/<p>Best <a class="reference external" href="http://blogs.charteris.com/blogs/gopalk/archive/2009/02/11/how-does-asp-net-mvc-work-part-2.aspx">explanation of model binding, initialization and filters execution
order</a>.</p>
Algolists2013-03-05T05:00:00+01:002013-03-05T05:00:00+01:00admintag:berezovskyi.me,2013-03-05:/2013/03/algolists/<p><a class="reference external" href="https://sites.google.com/site/indy256/">https://sites.google.com/site/indy256/</a></p>
<p><a class="reference external" href="http://algolist.manual.ru/">http://algolist.manual.ru/</a></p>
<p><a class="reference external" href="http://www.amazon.com/Introduction-Design-Analysis-Algorithms-Edition/dp/0132316811/">Introduction to the Design and Analysis of Algorithms (3rd Edition)</a></p>
<p><a class="reference external" href="http://www.amazon.com/Algorithms-4th-Robert-Sedgewick/dp/032157351X/">Algorithms (4th Edition)</a></p>
<p><a class="reference external" href="http://www.amazon.com/gp/product/1849967202/">The Algorithm Design Manual</a></p>
<p><a class="reference external" href="http://www.amazon.com/Algorithms-Nutshell-OReilly-George-Heineman/dp/059651624X/">Algorithms in a Nutshell</a></p>
Latest software sources2013-03-03T17:02:00+01:002013-03-03T17:02:00+01:00admintag:berezovskyi.me,2013-03-03:/2013/03/latest-software-sources/<p><a class="reference external" href="https://launchpad.net/~webupd8team">https://launchpad.net/~webupd8team</a></p>
<p><a class="reference external" href="http://www.lfd.uci.edu/~gohlke/pythonlibs/">http://www.lfd.uci.edu/~gohlke/pythonlibs/</a></p>
<p><a class="reference external" href="http://www.dotdeb.org/">http://www.dotdeb.org/</a></p>
Dewikify word text2012-12-27T02:57:00+01:002012-12-27T02:57:00+01:00admintag:berezovskyi.me,2012-12-27:/2012/12/dewikify-word-text/<p><img alt="image0" src="http://berezovskiy.org.ua/wp-content/uploads/2012/12/SNAG-0042.png" /></p>
Command prompt here (+Admin)2012-12-01T21:51:00+01:002012-12-01T21:51:00+01:00admintag:berezovskyi.me,2012-12-01:/2012/12/command-prompt-here-admin/<p>For usual, Shift+Right Click</p>
<p>For elevated,
<a class="reference external" href="http://www.sevenforums.com/tutorials/47415-open-command-window-here-administrator.html">http://www.sevenforums.com/tutorials/47415-open-command-window-here-administrator.html</a></p>
TOP Paradigm-shifting resources2012-10-16T20:00:00+02:002012-10-16T20:00:00+02:00admintag:berezovskyi.me,2012-10-16:/2012/10/top-paradigm-shifting-resources/<ol class="arabic simple">
<li><a class="reference external" href="http://www.wikipedia.org/">Wikipedia</a></li>
<li><a class="reference external" href="http://www.ted.com/"><span class="caps">TED</span></a></li>
<li><a class="reference external" href="http://www.thersa.org/"><span class="caps">RSA</span></a></li>
<li><a class="reference external" href="http://www.khanacademy.org/">Khan Academy</a></li>
<li><a class="reference external" href="http://stackexchange.com/sites">Stack Exchange</a></li>
<li>Your option expressed in comments!</li>
</ol>
Hodejegerne 20112012-06-03T19:56:00+02:002012-06-03T19:56:00+02:00Andrew Berezovskyitag:berezovskyi.me,2012-06-03:/2012/06/hodejegerne-2011/<p>Reputation.</p>Server monitoring tools2012-04-06T23:21:00+02:002012-04-06T23:21:00+02:00admintag:berezovskyi.me,2012-04-06:/2012/04/server-monitoring-tools/<p>Today I was checking stats of my new and growing web site and found it
to have no visitors today. I visited my site and found it to be down.</p>
<p>previously, I used php-cgi command to get php listening on some port in
my system waiting for nginx requests. Today I replaced it with a php-fpm
implementation, but I’m seriously considering checking my server health regularly.</p>
<p>First, let me mention I’ve already did some <a class="reference external" href="https://web.archive.org/web/20160916123948/http://berezovskiy.org.ua/2011/05/munin-monitoring/">research on Munin
monitoring</a> previously. So today I’m extending my research to a broader
extent of monitoring systems, scripts and services. I’ll …</p><p>Today I was checking stats of my new and growing web site and found it
to have no visitors today. I visited my site and found it to be down.</p>
<p>previously, I used php-cgi command to get php listening on some port in
my system waiting for nginx requests. Today I replaced it with a php-fpm
implementation, but I’m seriously considering checking my server health regularly.</p>
<p>First, let me mention I’ve already did some <a class="reference external" href="https://web.archive.org/web/20160916123948/http://berezovskiy.org.ua/2011/05/munin-monitoring/">research on Munin
monitoring</a> previously. So today I’m extending my research to a broader
extent of monitoring systems, scripts and services. I’ll try to cover
them in the future posts.</p>
<div class="section" id="web-tracking">
<h3>Web tracking</h3>
<p>Here i can mention one service that does its job well: HostTracker.com.
I’ve been using it for 5 years and I’m very happy with its services.</p>
</div>
<div class="section" id="server-monitoring-statistics">
<h3>Server monitoring <span class="amp">&</span> statistics</h3>
<ul class="simple">
<li>Munin (mentioned earlier)</li>
<li>Nagios</li>
<li>rrdTool</li>
</ul>
</div>
<div class="section" id="process-monitoring-tools">
<h3>Process monitoring tools</h3>
<ul class="simple">
<li><a class="reference external" href="http://upstart.ubuntu.com/">upstart</a></li>
<li><a class="reference external" href="http://packages.debian.org/unstable/utils/restartd">restartd</a></li>
<li><a class="reference external" href="http://supervisord.org/introduction.html">supervisor</a></li>
<li><a class="reference external" href="http://smarden.org/runit/">runit</a></li>
<li><a class="reference external" href="http://launchd.macosforge.org/">launchd</a></li>
<li><a class="reference external" href="http://cr.yp.to/daemontools.html">daemontools</a></li>
</ul>
</div>
iPad 3 QSXGA, 1080p and Red One 4K2012-03-22T15:48:00+01:002012-03-22T15:48:00+01:00admintag:berezovskyi.me,2012-03-22:/2012/03/ipad-3-qsxga-1080p-and-red-one-4k/<p>Immediately after iPad 3 presentation, I thought “Did Apple think of people
watching <span class="caps">HD</span> or just about Retina, profits and developers?” (I am a developer,
though). I immediately accepted the idea of FullHD/<span class="caps">HD</span>-ready devices would
emerge and sell better than iPad. That will definitely come.</p>
<p>But I expect Apple’s aim to revolutionize once again. It’s no secret that most
modern films <a class="reference external" href="http://en.wikipedia.org/wiki/Red_Digital_Cinema_Camera_Company#Notable_movies_and_TV_shows_shot_on_Red_One_cameras">are captured on Red One</a> camera. It is operating at
resolution that’s 4 times greater than 1080p - so called <a class="reference external" href="http://en.wikipedia.org/wiki/4K_resolution">4K standard</a>. Apple
is able to pursue Hollywood for creating new “iHD”. Yes, there is …</p><p>Immediately after iPad 3 presentation, I thought “Did Apple think of people
watching <span class="caps">HD</span> or just about Retina, profits and developers?” (I am a developer,
though). I immediately accepted the idea of FullHD/<span class="caps">HD</span>-ready devices would
emerge and sell better than iPad. That will definitely come.</p>
<p>But I expect Apple’s aim to revolutionize once again. It’s no secret that most
modern films <a class="reference external" href="http://en.wikipedia.org/wiki/Red_Digital_Cinema_Camera_Company#Notable_movies_and_TV_shows_shot_on_Red_One_cameras">are captured on Red One</a> camera. It is operating at
resolution that’s 4 times greater than 1080p - so called <a class="reference external" href="http://en.wikipedia.org/wiki/4K_resolution">4K standard</a>. Apple
is able to pursue Hollywood for creating new “iHD”. Yes, there is a major
problem with aspect ratio but iFans would agree to see black stripes (or real-
time tweets <span class="amp">&</span> ads).</p>
Comprehensive list of FREE Online Education resources2012-03-21T17:17:00+01:002012-03-21T17:17:00+01:00admintag:berezovskyi.me,2012-03-21:/2012/03/comprehensive-list-of-free-online-education-resources/<p>Language of teaching - English/Russian. So, let’s begin!</p>
<iframe src="//www.youtube-nocookie.com/embed/zDZFcDGpL4U?rel=0" width="560" height="315" frameborder="0"></iframe><div class="section" id="video">
<h3>Video</h3>
<ol class="arabic simple">
<li><a class="reference external" href="https://www.class-central.com/">https://www.class-central.com/</a> (<strong><span class="caps">META</span>-<span class="caps">AGGREGATOR</span> of the 37 course providers as of August 2014</strong>)</li>
<li><a class="reference external" href="http://www.udacity.com/">http://www.udacity.com/</a></li>
<li><a class="reference external" href="https://www.coursera.org/landing/hub.php">https://www.coursera.org/landing/hub.php</a></li>
<li><a class="reference external" href="https://www.edx.org/">https://www.edx.org/</a></li>
<li><a class="reference external" href="http://ocw.mit.edu/courses/">http://ocw.mit.edu/courses/</a></li>
<li><a class="reference external" href="http://www.khanacademy.org/">http://www.khanacademy.org/</a></li>
<li><a class="reference external" href="http://online.stanford.edu/courses">http://online.stanford.edu/courses</a></li>
<li><a class="reference external" href="http://oyc.yale.edu/">http://oyc.yale.edu/</a></li>
<li><a class="reference external" href="http://www.ted.com/">http://www.ted.com/</a></li>
<li><a class="reference external" href="http://www.thersa.org/">http://www.thersa.org/</a></li>
<li><a class="reference external" href="http://bigthink.com/">http://bigthink.com/</a></li>
<li><a class="reference external" href="https://thenewcircle.com/s">https://thenewcircle.com/s</a></li>
<li><a class="reference external" href="http://www.saylor.org/">http://www.saylor.org/</a></li>
<li><a class="reference external" href="https://hexlet.org">https://hexlet.org</a></li>
<li><a class="reference external" href="http://shad.yandex.ru/lectures/">http://shad.yandex.ru/lectures/</a></li>
<li><a class="reference external" href="http://www.lektorium.tv/">http://www.lektorium.tv/</a></li>
<li><a class="reference external" href="http://techforum.mail.ru/video/">http://techforum.mail.ru/video/</a></li>
<li><a class="reference external" href="http://www.microsoftvirtualacademy.com/home.aspx">http://www.microsoftvirtualacademy.com/home.aspx …</a></li></ol></div><p>Language of teaching - English/Russian. So, let’s begin!</p>
<iframe src="//www.youtube-nocookie.com/embed/zDZFcDGpL4U?rel=0" width="560" height="315" frameborder="0"></iframe><div class="section" id="video">
<h3>Video</h3>
<ol class="arabic simple">
<li><a class="reference external" href="https://www.class-central.com/">https://www.class-central.com/</a> (<strong><span class="caps">META</span>-<span class="caps">AGGREGATOR</span> of the 37 course providers as of August 2014</strong>)</li>
<li><a class="reference external" href="http://www.udacity.com/">http://www.udacity.com/</a></li>
<li><a class="reference external" href="https://www.coursera.org/landing/hub.php">https://www.coursera.org/landing/hub.php</a></li>
<li><a class="reference external" href="https://www.edx.org/">https://www.edx.org/</a></li>
<li><a class="reference external" href="http://ocw.mit.edu/courses/">http://ocw.mit.edu/courses/</a></li>
<li><a class="reference external" href="http://www.khanacademy.org/">http://www.khanacademy.org/</a></li>
<li><a class="reference external" href="http://online.stanford.edu/courses">http://online.stanford.edu/courses</a></li>
<li><a class="reference external" href="http://oyc.yale.edu/">http://oyc.yale.edu/</a></li>
<li><a class="reference external" href="http://www.ted.com/">http://www.ted.com/</a></li>
<li><a class="reference external" href="http://www.thersa.org/">http://www.thersa.org/</a></li>
<li><a class="reference external" href="http://bigthink.com/">http://bigthink.com/</a></li>
<li><a class="reference external" href="https://thenewcircle.com/s">https://thenewcircle.com/s</a></li>
<li><a class="reference external" href="http://www.saylor.org/">http://www.saylor.org/</a></li>
<li><a class="reference external" href="https://hexlet.org">https://hexlet.org</a></li>
<li><a class="reference external" href="http://shad.yandex.ru/lectures/">http://shad.yandex.ru/lectures/</a></li>
<li><a class="reference external" href="http://www.lektorium.tv/">http://www.lektorium.tv/</a></li>
<li><a class="reference external" href="http://techforum.mail.ru/video/">http://techforum.mail.ru/video/</a></li>
<li><a class="reference external" href="http://www.microsoftvirtualacademy.com/home.aspx">http://www.microsoftvirtualacademy.com/home.aspx</a></li>
<li><a class="reference external" href="http://www.intuit.ru">http://www.intuit.ru</a></li>
</ol>
</div>
<div class="section" id="books-papers-and-patents">
<h3>Books, papers and patents</h3>
<ol class="arabic simple">
<li><a class="reference external" href="http://resrc.io/">http://resrc.io/</a></li>
<li><a class="reference external" href="http://it-ebooks.info/">http://it-ebooks.info/</a></li>
<li><a class="reference external" href="http://www.foxebook.net/">http://www.foxebook.net/</a></li>
<li><a class="reference external" href="http://www.wowebook.org/">http://www.wowebook.org/</a></li>
<li><a class="reference external" href="http://c-books.info/">http://c-books.info/</a></li>
<li><a class="reference external" href="http://elbitz.net">http://elbitz.net</a></li>
<li><a class="reference external" href="http://www.ebookvortex.com/">http://www.ebookvortex.com/</a></li>
<li><a class="reference external" href="http://citeseer.ist.psu.edu/index">http://citeseer.ist.psu.edu/index</a></li>
</ol>
</div>
<div class="section" id="text-article-directories-documentation">
<h3>Text <span class="amp">&</span> Article directories + Documentation:</h3>
<ol class="arabic simple">
<li><a class="reference external" href="http://www.ibm.com/developerworks/topics/">http://www.ibm.com/developerworks/topics/</a></li>
<li><a class="reference external" href="http://www.dzone.com/links/index.html">http://www.dzone.com/links/index.html</a></li>
<li><a class="reference external" href="http://habrahabr.ru/">http://habrahabr.ru/</a></li>
<li><a class="reference external" href="http://www.howtoforge.com/">http://www.howtoforge.com/</a></li>
<li><a class="reference external" href="http://net.tutsplus.com/">http://net.tutsplus.com/</a></li>
<li><a class="reference external" href="http://readthedocs.org/">http://readthedocs.org/</a></li>
<li><a class="reference external" href="http://seom.info/seo-book/">http://seom.info/seo-book/</a></li>
<li><a class="reference external" href="http://rutracker.org/forum/viewtopic.php?t=3943631">Encyclopaedia Britannica (<span class="caps">UK</span>) Ltd - Encyclopaedia Britannica 2012.
Ultimate Reference Suite [2012, <span class="caps">ENG</span>]</a></li>
<li><a class="reference external" href="http://html.adobe.com/">http://html.adobe.com/</a></li>
</ol>
<p>And counting! Feel free to post links in comments!</p>
<p><strong>Paid:</strong></p>
<ol class="arabic simple">
<li><a class="reference external" href="https://www.codeschool.com/">https://www.codeschool.com/</a></li>
<li><a class="reference external" href="http://teamtreehouse.com/library">http://teamtreehouse.com/library</a></li>
</ol>
<p><strong><span class="caps">UPD</span></strong>: Inpire yourself by reading <a class="reference external" href="http://slon.ru/ipad/seven_aspects_of_the_21st_century_education_system-796470.xhtml"><span class="caps">SEVEN</span> <span class="caps">ASPECTS</span> <span class="caps">OF</span> <span class="caps">THE</span> <span class="caps">21ST</span>-<span class="caps">CENTURY</span>
<span class="caps">EDUCATION</span> <span class="caps">SYSTEM</span></a> (aka <a class="reference external" href="http://slon.ru/ipad/7_elementov_sistemy_obrazovaniya_xxi_veka-786760.xhtml">7 ЭЛЕМЕНТОВ СИСТЕМЫ ОБРАЗОВАНИЯ <span class="caps">XXI</span>
ВЕКА</a>) by <span class="caps">PAVEL</span> <span class="caps">DUROV</span>.
<strong><span class="caps">UPD2</span></strong>: Durov actually stole the idea completely from <span class="caps">RSA</span> (see the video in the top section of the page).</p>
<img alt="clipart" src="http://berezovskiy.org.ua/wp-content/uploads/2012/03/education-150x150.jpg" />
</div>
One day2012-03-19T13:34:00+01:002012-03-19T13:34:00+01:00Andrew Berezovskyitag:berezovskyi.me,2012-03-19:/2012/03/one-day/<p>https://www.imdb.com/title/tt1563738/</p>
<p>I think, the main idea of this breathtaking film is not to screw up everything…</p>Disable ActiveX warning for local web pages in Internet Explorer 92012-03-12T01:06:00+01:002012-03-12T01:06:00+01:00admintag:berezovskyi.me,2012-03-12:/2012/03/disable-activex-warning-for-local-web-pages-in-internet-explorer-9/<p>Go to Internet options and switch to tab Advanced:</p>
<div class="figure align-center">
<img alt="SNAG-0011" src="http://berezovskiy.org.ua/wp-content/uploads/2012/03/SNAG-0011.png" />
</div>
Restore Ubuntu GRUB after Windows 8 installation2012-03-12T00:20:00+01:002012-03-12T00:20:00+01:00admintag:berezovskyi.me,2012-03-12:/2012/03/restore-ubuntu-grub-after-windows-8-installation/<p>Use this package to
recover: <a class="reference external" href="https://help.ubuntu.com/community/Boot-Repair">https://help.ubuntu.com/community/Boot-Repair</a></p>
Django soft image thumbnail replacement2012-03-11T20:35:00+01:002012-03-11T20:35:00+01:00admintag:berezovskyi.me,2012-03-11:/2012/03/django-soft-image-thumbnail-replacement/<p>Using new template tag, you’re now free to cache images before rolling
out new design and avoid heavy load (maybe via random call)!</p>
<p><a class="reference external" href="https://docs.djangoproject.com/en/1.3/ref/templates/builtins/#with">https://docs.djangoproject.com/en/1.3/ref/templates/builtins/#with</a></p>
<pre class="literal-block">
<img src="{{img.url|thumb:"500x500"%}" />
{% if rand % 10 }
{with newthumb=img.newthumb %}}
or <!-- {{img.url|thumb:"500x580"%} -->
{% endif %}
</pre>
Fluent C#2012-03-10T13:36:00+01:002012-03-10T13:36:00+01:00admintag:berezovskyi.me,2012-03-10:/2012/03/fluent-c/<p>The book is awful and riddled with errors. Here is the annotated <a class="reference external" href="https://docs.google.com/document/d/1GNZ77fBu15gPnpmelcujlJVdc_iEvJWjLMd0m2VgStA/edit?hl=en_GB">list of
errors</a> on Google Docs from Jon Skeet. You can find his
full review <a class="reference external" href="http://codeblog.jonskeet.uk/2011/12/05/book-review-fluent-c-rebecca-riordan-sams/">here</a>.</p>
Git deployment2012-03-05T02:06:00+01:002012-03-05T02:06:00+01:00admintag:berezovskyi.me,2012-03-05:/2012/03/git-deployment/<p>Get some inspiration here first:
<a class="reference external" href="http://stackoverflow.com/questions/279169/deploy-a-project-using-git">http://stackoverflow.com/questions/279169/deploy-a-project-using-git</a></p>
<p>If it seems to hard for you, use this example:
<a class="reference external" href="http://ryanflorence.com/simple-git-deployment/">http://ryanflorence.com/simple-git-deployment/</a>.</p>
<p>There is a middle method, but I failed to implement it successfully:
<a class="reference external" href="http://caiustheory.com/automatically-deploying-website-from-remote-git-repository">http://caiustheory.com/automatically-deploying-website-from-remote-git-repository</a></p>
<p>Take a look at
<a class="reference external" href="http://www.dejaaugustine.com/2011/05/leveraging-git-as-a-full-fledged-web-development-tool/">http://www.dejaaugustine.com/2011/05/leveraging-git-as-a-full-fledged-web-development-tool/</a>
and <a class="reference external" href="http://deadlytechnology.com/web-development/deploy-websites-with-git/">http://deadlytechnology.com/web-development/deploy-websites-with-git/</a>
as well.</p>
Django fails with DEBUG=False on production2012-03-05T02:02:00+01:002012-03-05T02:02:00+01:00admintag:berezovskyi.me,2012-03-05:/2012/03/django-fails-with-debugfalse-on-production/<p>First, be sure to eliminate this issue:
<a class="reference external" href="http://stackoverflow.com/a/4975210">http://stackoverflow.com/a/4975210</a></p>
<p>Next, <a class="reference external" href="http://tech.xster.net/tips/django-log-to-file/">enable logging</a> of
all events. That will save you plenty of time.</p>
<p>Next, be sure to include both 404.html and 500.html in the root of your
templates’ folder. See <a class="reference external" href="https://docs.djangoproject.com/en/dev/ref/contrib/flatpages/#django.contrib.flatpages.middleware.FlatpageFallbackMiddleware">here</a>
and <a class="reference external" href="https://code.djangoproject.com/ticket/3335#comment:9">here</a> for details.</p>
<p>If you are using nginx, be sure to include correct fastcgi configuration file:
<a class="reference external" href="http://softwaremaniacs.org/forum/django/9093/">http://softwaremaniacs.org/forum/django/9093/</a> (post before the last). Fairly
equal to <a class="reference external" href="http://serverfault.com/a/229188">http://serverfault.com/a/229188</a>. But extensive configuration
<a class="reference external" href="http://stackoverflow.com/a/605196">http://stackoverflow.com/a/605196</a> didn’t work for me.</p>
MySQL with Django on Debian2012-03-05T01:54:00+01:002012-03-05T01:54:00+01:00admintag:berezovskyi.me,2012-03-05:/2012/03/mysql-with-django-on-debian/<p>First, install MySQL driver for Python:</p>
<pre class="literal-block">
sudo apt-get install python-mysqldb
</pre>
<p>Next, modify your config of MySQL: <a class="reference external" href="http://dba.stackexchange.com/a/8289">http://dba.stackexchange.com/a/8289</a></p>
<p>If you’ve already messed up the install, you can either drop/create
database from scratch, or apply the following script to every table of
your <span class="caps">DB</span>:</p>
<pre class="literal-block">
ALTER TABLE `table` CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;
</pre>
<p>Alternative mirgation path:
<a class="reference external" href="http://docs.joomla.org/Convert_a_MySQL_database_to_UTF-8">http://docs.joomla.org/Convert_a_MySQL_database_to_UTF-8</a></p>
Python hostname2012-03-05T01:48:00+01:002012-03-05T01:48:00+01:00admintag:berezovskyi.me,2012-03-05:/2012/03/python-hostname/<pre class="literal-block">
from socket import gethostname
print gethostname()
if 'prod' in gethostname:
pass
</pre>
Test nginx Configuration File2012-03-05T01:47:00+01:002012-03-05T01:47:00+01:00admintag:berezovskyi.me,2012-03-05:/2012/03/test-nginx-configuration-file/<p>If there is a time when it becomes necessary to test out a nginx.conf
file prior to attempting to use it (<span class="caps">IOW</span> on a live/production system)
here is a handy little command.</p>
<pre class="literal-block">
user@machine ~> nginx -t -c /etc/nginx/nginx.conf
</pre>
SSH alias2012-03-05T01:46:00+01:002012-03-05T01:46:00+01:00admintag:berezovskyi.me,2012-03-05:/2012/03/ssh-alias/<p>By adding this to <tt class="docutils literal"><span class="pre">~/.ssh/config</span></tt>:</p>
<pre class="literal-block">
Host example
HostName example.com
User exampleuser
</pre>
<p>You can reduce that to previous command to <tt class="docutils literal">ssh example</tt></p>
<p>Nice huh?</p>
Sublime Text 22012-03-04T22:36:00+01:002012-03-04T22:36:00+01:00admintag:berezovskyi.me,2012-03-04:/2012/03/sublime-text-2/<pre class="literal-block">
sudo add-apt-repository ppa:webupd8team/sublime-text-2
sudo apt-get update
sudo apt-get install sublime-text-2
</pre>
django default manager2012-02-22T14:21:00+01:002012-02-22T14:21:00+01:00Andrew Berezovskyitag:berezovskyi.me,2012-02-22:/2012/02/django-default-manager/<p>You can add a manager to all models of some type if you subclass an abstract model which declares a manager.</p>
<p>For example, you can declare ugcModel with publication status and published_items manager.</p>
<p>Link: <a href="https://docs.djangoproject.com/en/dev/topics/db/managers/#custom-managers-and-model-inheritance">https://docs.djangoproject.com/en/dev/topics/db/managers/#custom-managers-and-model-inheritance</a></p>MSP430 Launchpad2012-02-15T17:48:00+01:002012-02-15T17:48:00+01:00Andrew Berezovskyitag:berezovskyi.me,2012-02-15:/2012/02/msp430-launchpad/<p>This is a link to a web page: <a href="https://cacheattack.blogspot.com/2011/06/quick-overview-on-interfacing-msp430.html">https://cacheattack.blogspot.com/2011/06/quick-overview-on-interfacing-msp430.html</a></p>
<p>Copy: <a href="https://berezovskyi.me/static/2012/msp430.pdf"><span class="caps">PDF</span></a></p>Git through http proxy2012-02-15T14:41:00+01:002012-02-15T14:41:00+01:00admintag:berezovskyi.me,2012-02-15:/2012/02/git-through-http-proxy/<p>Use this command to globally configure git:</p>
<pre class="literal-block">
git config --global http.proxy http://10.108.4.62:8080
</pre>
Git default remote2012-02-10T23:58:00+01:002012-02-10T23:58:00+01:00admintag:berezovskyi.me,2012-02-10:/2012/02/git-default-remote/<div id="__w2_xl5V7GD_answer_content"><pre class="literal-block">
git branch --set-upstream master <strong>origin</strong>/master
</pre>
<p><strong>origin</strong> - name of the default remote</p>
</div>Sync folders between computers within your home network via SyncToy 2.1!2012-02-10T13:45:00+01:002012-02-10T13:45:00+01:00admintag:berezovskyi.me,2012-02-10:/2012/02/sync-folders-between-computers-within-your-home-network-via-synctoy-2-1/<p>Before I knew this great software for file sync in Windows 7 exists I
used to run PowerShell scripts.</p>
<p>Here is the interface of this program by Microsoft developers:</p>
<div class="figure align-center">
<img alt="SNAG-0030" src="http://berezovskiy.org.ua/wp-content/uploads/2012/02/SNAG-0030-300x247.png" />
</div>
<div class="figure align-center">
<img alt="SNAG-0031" src="http://berezovskiy.org.ua/wp-content/uploads/2012/02/SNAG-0031-300x221.png" />
</div>
<p>It has few operational modes:</p>
<ol class="arabic simple">
<li>Sync folders</li>
<li>Echo folders</li>
<li>Contribute to folders</li>
</ol>
Generating keyboard events2012-02-08T11:48:00+01:002012-02-08T11:48:00+01:00admintag:berezovskyi.me,2012-02-08:/2012/02/generating-keyboard-events/<pre class="literal-block">
import pyatspi
reg = pyatspi.Registry.generateKeyboardEvent
reg(36, None, pyatspi.KEY_preSSRELEASE) #Enter
</pre>
Python chroot2012-02-08T11:44:00+01:002012-02-08T11:44:00+01:00admintag:berezovskyi.me,2012-02-08:/2012/02/python-chroot/<p>What is important to remember is that chroot will allow you cd into /,
and that will correspond to the dir you chrooted in:</p>
<pre class="literal-block">
os.chroot(os.path.abspath(os.path.dirname(__file__)))
for opt in glob.glob("/*"):
print "\t-> %s" % opt
try:
os.chdir("/root/")
print "Chroot FAIL"
print os.getcwd()
except Exception as e:
print "Chroot OK"
</pre>
Nonblocking console input in Python2012-02-08T02:34:00+01:002012-02-08T02:34:00+01:00admintag:berezovskyi.me,2012-02-08:/2012/02/nonblocking-console-input-in-python/<p>By <a class="reference external" href="http://www.darkcoding.net/software/non-blocking-console-io-is-not-possible/#comment-870">Nemesis Fixx</a>:</p>
<div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">sys</span>
<span class="kn">import</span> <span class="nn">select</span>
<span class="kn">import</span> <span class="nn">tty</span>
<span class="kn">import</span> <span class="nn">termios</span>
<span class="kn">from</span> <span class="nn">threading</span> <span class="kn">import</span> <span class="n">Thread</span>
<span class="n">program_run</span> <span class="o">=</span> <span class="kc">True</span>
<span class="n">input_thread_timeout</span> <span class="o">=</span> <span class="mf">0.005</span> <span class="c1">#seconds</span>
<span class="n">quit_key</span> <span class="o">=</span> <span class="s1">'</span><span class="se">\x1b</span><span class="s1">'</span> <span class="c1"># x1b is ESC</span>
<span class="c1">#check stdin for input...</span>
<span class="k">def</span> <span class="nf">isData</span><span class="p">():</span>
<span class="k">return</span> <span class="n">select</span><span class="o">.</span><span class="n">select</span><span class="p">([</span><span class="n">sys</span><span class="o">.</span><span class="n">stdin</span><span class="p">],</span> <span class="p">[],</span> <span class="p">[],</span> <span class="mi">0</span><span class="p">)</span> <span class="o">==</span> <span class="p">([</span><span class="n">sys</span><span class="o">.</span><span class="n">stdin</span><span class="p">],</span> <span class="p">[],</span> <span class="p">[])</span>
<span class="c1">#check n terminate program on terminal condition,</span>
<span class="c1">#from a separate thread</span>
<span class="k">class</span> <span class="nc">waitOnInput</span><span class="p">(</span><span class="n">Thread</span><span class="p">):</span>
<span class="k">def</span> <span class="nf">run</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="n">old_settings</span> <span class="o">=</span> <span class="n">termios</span><span class="o">.</span><span class="n">tcgetattr</span><span class="p">(</span><span class="n">sys</span><span class="o">.</span><span class="n">stdin</span><span class="p">)</span>
<span class="k">try</span><span class="p">:</span>
<span class="n">tty</span><span class="o">.</span><span class="n">setcbreak</span><span class="p">(</span><span class="n">sys</span><span class="o">.</span><span class="n">stdin</span><span class="o">.</span><span class="n">fileno</span><span class="p">())</span>
<span class="k">global</span> <span class="n">program_run</span>
<span class="n">thread_run</span> <span class="o">=</span> <span class="kc">True</span>
<span class="k">while</span> <span class="n">thread_run</span><span class="p">:</span>
<span class="k">if</span> <span class="n">isData</span><span class="p">():</span>
<span class="n">c</span> <span class="o">=</span> <span class="n">sys</span><span class="o">.</span><span class="n">stdin</span><span class="o">.</span><span class="n">read</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>
<span class="k">if</span> <span class="n">c</span> <span class="o">==</span> <span class="n">quit_key</span><span class="p">:</span>
<span class="k">break</span>
<span class="n">thread_run</span> <span class="o">=</span> <span class="kc">False</span>
<span class="n">program_run</span> <span class="o">=</span> <span class="kc">False</span>
<span class="k">finally</span><span class="p">:</span>
<span class="n">termios</span><span class="o">.</span><span class="n">tcsetattr</span><span class="p">(</span><span class="n">sys</span><span class="o">.</span><span class="n">stdin</span><span class="p">,</span> <span class="n">termios</span><span class="o">.</span><span class="n">TCSADRAIN</span><span class="p">,</span> <span class="n">old_settings</span><span class="p">)</span>
<span class="n">thread_run</span> <span class="o">=</span> <span class="kc">False</span>
<span class="n">t …</span></pre></div><p>By <a class="reference external" href="http://www.darkcoding.net/software/non-blocking-console-io-is-not-possible/#comment-870">Nemesis Fixx</a>:</p>
<div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">sys</span>
<span class="kn">import</span> <span class="nn">select</span>
<span class="kn">import</span> <span class="nn">tty</span>
<span class="kn">import</span> <span class="nn">termios</span>
<span class="kn">from</span> <span class="nn">threading</span> <span class="kn">import</span> <span class="n">Thread</span>
<span class="n">program_run</span> <span class="o">=</span> <span class="kc">True</span>
<span class="n">input_thread_timeout</span> <span class="o">=</span> <span class="mf">0.005</span> <span class="c1">#seconds</span>
<span class="n">quit_key</span> <span class="o">=</span> <span class="s1">'</span><span class="se">\x1b</span><span class="s1">'</span> <span class="c1"># x1b is ESC</span>
<span class="c1">#check stdin for input...</span>
<span class="k">def</span> <span class="nf">isData</span><span class="p">():</span>
<span class="k">return</span> <span class="n">select</span><span class="o">.</span><span class="n">select</span><span class="p">([</span><span class="n">sys</span><span class="o">.</span><span class="n">stdin</span><span class="p">],</span> <span class="p">[],</span> <span class="p">[],</span> <span class="mi">0</span><span class="p">)</span> <span class="o">==</span> <span class="p">([</span><span class="n">sys</span><span class="o">.</span><span class="n">stdin</span><span class="p">],</span> <span class="p">[],</span> <span class="p">[])</span>
<span class="c1">#check n terminate program on terminal condition,</span>
<span class="c1">#from a separate thread</span>
<span class="k">class</span> <span class="nc">waitOnInput</span><span class="p">(</span><span class="n">Thread</span><span class="p">):</span>
<span class="k">def</span> <span class="nf">run</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="n">old_settings</span> <span class="o">=</span> <span class="n">termios</span><span class="o">.</span><span class="n">tcgetattr</span><span class="p">(</span><span class="n">sys</span><span class="o">.</span><span class="n">stdin</span><span class="p">)</span>
<span class="k">try</span><span class="p">:</span>
<span class="n">tty</span><span class="o">.</span><span class="n">setcbreak</span><span class="p">(</span><span class="n">sys</span><span class="o">.</span><span class="n">stdin</span><span class="o">.</span><span class="n">fileno</span><span class="p">())</span>
<span class="k">global</span> <span class="n">program_run</span>
<span class="n">thread_run</span> <span class="o">=</span> <span class="kc">True</span>
<span class="k">while</span> <span class="n">thread_run</span><span class="p">:</span>
<span class="k">if</span> <span class="n">isData</span><span class="p">():</span>
<span class="n">c</span> <span class="o">=</span> <span class="n">sys</span><span class="o">.</span><span class="n">stdin</span><span class="o">.</span><span class="n">read</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>
<span class="k">if</span> <span class="n">c</span> <span class="o">==</span> <span class="n">quit_key</span><span class="p">:</span>
<span class="k">break</span>
<span class="n">thread_run</span> <span class="o">=</span> <span class="kc">False</span>
<span class="n">program_run</span> <span class="o">=</span> <span class="kc">False</span>
<span class="k">finally</span><span class="p">:</span>
<span class="n">termios</span><span class="o">.</span><span class="n">tcsetattr</span><span class="p">(</span><span class="n">sys</span><span class="o">.</span><span class="n">stdin</span><span class="p">,</span> <span class="n">termios</span><span class="o">.</span><span class="n">TCSADRAIN</span><span class="p">,</span> <span class="n">old_settings</span><span class="p">)</span>
<span class="n">thread_run</span> <span class="o">=</span> <span class="kc">False</span>
<span class="n">t</span> <span class="o">=</span> <span class="n">waitOnInput</span><span class="p">()</span>
<span class="c1">#start work here...</span>
<span class="n">i</span> <span class="o">=</span> <span class="mi">1</span>
<span class="k">while</span> <span class="n">program_run</span> <span class="p">:</span>
<span class="k">if</span> <span class="ow">not</span> <span class="n">t</span><span class="o">.</span><span class="n">is_alive</span><span class="p">():</span>
<span class="n">t</span><span class="o">.</span><span class="n">start</span><span class="p">()</span>
<span class="c1">#test for terminal condition or timeout...</span>
<span class="n">t</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">input_thread_timeout</span><span class="p">)</span>
<span class="k">if</span> <span class="n">t</span><span class="o">.</span><span class="n">is_alive</span><span class="p">():</span>
<span class="c1">#continue work here...</span>
<span class="nb">print</span> <span class="n">i</span>
<span class="n">i</span> <span class="o">+=</span> <span class="mi">1</span>
<span class="k">else</span><span class="p">:</span>
<span class="k">break</span>
</pre></div>
DAA2012-02-07T23:05:00+01:002012-02-07T23:05:00+01:00admintag:berezovskyi.me,2012-02-07:/2012/02/daa/<p><span class="caps">DAA</span> is a PowerISO type of image. To mount it with Daemon Tools,
use <a class="reference external" href="http://aluigi.altervista.org/mytoolz.htm"><span class="caps">DAA</span> 2 <span class="caps">ISO</span></a> tool first</p>
Emacs Tex Mac2012-02-05T19:24:00+01:002012-02-05T19:24:00+01:00admintag:berezovskyi.me,2012-02-05:/2012/02/emacs-tex-mac/<p><a class="reference external" href="http://soundandcomplete.com/2010/05/13/emacs-as-the-ultimate-latex-editor/">http://soundandcomplete.com/2010/05/13/emacs-as-the-ultimate-latex-editor/</a></p>
<p><a class="reference external" href="http://www.gnu.org/software/auctex/screenshots.html">http://www.gnu.org/software/auctex/screenshots.html</a></p>
<p><a class="reference external" href="http://www.fauskes.net/code/dot2tex/">http://www.fauskes.net/code/dot2tex/</a></p>
Apache behind Nginx2012-02-05T03:55:00+01:002012-02-05T03:55:00+01:00admintag:berezovskyi.me,2012-02-05:/2012/02/apache-behind-nginx/<pre class="literal-block">
apt-get update
apt-get upgrade
apt-get install apache2 emacs
apache conf: /etc/apache2/apache2.conf
nginx conf: /etc/nginx/nginx.conf
</pre>
Wiki2012-02-04T18:48:00+01:002012-02-04T18:48:00+01:00Andrew Berezovskyitag:berezovskyi.me,2012-02-04:/2012/02/wiki/<p>Yesterday I created a new blog, <a href="https://lattematica.wordpress.com/">LatteMatica</a> to unveil and tackle difficulties which users of Latex and Mathematica face every day!</p>
<p>So the next idea was to combine all the knowledge in one place, so all paths lead to wikipedia. To create own wiki, you need</p>
<ul>
<li><span class="caps">LAMP</span> server. <a href="https://berezovskiy.org.ua/2011/05/symfony2-wphp5-3-on-ubuntu-11-04-nginx/"><span class="caps">PHP5</span>.3 on Ubuntu ready for Symfony2 installation tutorial</a> may help.</li>
<li><a href="https://www.mediawiki.org/wiki/MediaWiki">MediaWiki</a></li>
<li><a href="https://semantic-mediawiki.org/">Semantic MediaWiki</a></li>
</ul>Make Powershell and Python friends2012-01-28T02:53:00+01:002012-01-28T02:53:00+01:00admintag:berezovskyi.me,2012-01-28:/2012/01/make-powershell-and-python-friends/<p>Problem: when python script is invoked inside powershell shell, cmd
window gets open, output is done inside cmd and then it closes.</p>
<p>Solution: inside %<span class="caps">USER</span>%\WindowsPowershell\profile.ps1</p>
<pre class="literal-block">
function django-admin {python (gcm django-admin.py | resolve-path) $args}
function manage {python (gcm .\manage.py | resolve-path) $args}
</pre>
Markdown image handling in Django2012-01-23T18:06:00+01:002012-01-23T18:06:00+01:00admintag:berezovskyi.me,2012-01-23:/2012/01/markdown-image-handling-in-django/<p>It’s an interesting question: how to deal with images in django admin
which claims to be hardly extensible.</p>
<p>The default package comes with markdown integration, which could be
easily installed by obtaining python-markdown from your favorite package manager.</p>
<p>Next, we should attach images to the record. We’ll do that by embedding
special model of entry-specific image. To do the markdown, we need to
have images’ paths or reference them in some way. The spec says we can
invoke reference by ![][ref_id] and then it’ll be substituted.</p>
<pre class="literal-block">
def get_markdown(self):
# create instance of Markdown class (note capital "M …</pre><p>It’s an interesting question: how to deal with images in django admin
which claims to be hardly extensible.</p>
<p>The default package comes with markdown integration, which could be
easily installed by obtaining python-markdown from your favorite package manager.</p>
<p>Next, we should attach images to the record. We’ll do that by embedding
special model of entry-specific image. To do the markdown, we need to
have images’ paths or reference them in some way. The spec says we can
invoke reference by ![][ref_id] and then it’ll be substituted.</p>
<pre class="literal-block">
def get_markdown(self):
# create instance of Markdown class (note capital "M")
md = markdown.Markdown()
for image in self.chapterimage_set.all():
image_url = settings.MEDIA_URL + image.image.url
# append image reference to Markdown instance
# md.reference[id] = (url, title)
title = image.title
md.references[title.lower()] = (image_url, '')
# parse source text
convert = md.convert(self.body)
refs = md.references
# assert False
return convert
</pre>
<p>Here we’ll notice the <em>.lower()</em> call. At first, I was surprised by
selected action of the method, and after reading the source code on
github, I got it! <em>Assert false</em> is a handy piece of code to fire up
debug panel!</p>
<pre class="literal-block">
class ReferencePattern(LinkPattern):
""" Match to a stored reference and return link element. """
NEWLINE_CLEANUP_RE = re.compile(r'[ ]?\n', re.MULTILINE)
def handleMatch(self, m):
try:
id = m.group(9).lower()
except IndexError:
id = None
if not id:
# if we got something like "[Google][]" or "[Goggle]"
# we'll use "google" as the id
id = m.group(2).lower()
# Clean up linebreaks in id
id = self.NEWLINE_CLEANUP_RE.sub(' ', id)
if not id in self.markdown.references: # ignore undefined refs
return None
href, title = self.markdown.references[id]
text = m.group(2)
return self.makeTag(href, title, text)
def makeTag(self, href, title, text):
el = util.etree.Element('a')
el.set('href', self.sanitize_url(href))
if title:
el.set('title', title)
el.text = text
return el
class ImageReferencePattern(ReferencePattern):
""" Match to a stored reference and return img element. """
def makeTag(self, href, title, text):
el = util.etree.Element("img")
el.set("src", self.sanitize_url(href))
if title:
el.set("title", title)
el.set("alt", text)
return el
</pre>
<p>It’s then used in a new way when invoked in template:</p>
<pre class="literal-block">
{# {{ chapter.body|markdown }}#}
{{ chapter.get_markdown|safe}}
</pre>
Rio movie2012-01-15T03:34:00+01:002012-01-15T03:34:00+01:00Andrew Berezovskyitag:berezovskyi.me,2012-01-15:/2012/01/rio-movie/<p>Your heart will lead you into the fascinating story you’ve never imagined!</p>Курт Кобейн2012-01-12T18:30:00+01:002012-01-12T18:30:00+01:00admintag:berezovskyi.me,2012-01-12:/2012/01/kurt-kobeyn/<p><em>“Во мне больше нет страсти, поэтому помните: лучше сгореть, чем
угаснуть. мир, любовь, сострадание.”</em></p>
<p><em>-Курт Кобейн</em></p>
PyOpenCl on x64 system2012-01-11T22:06:00+01:002012-01-11T22:06:00+01:00admintag:berezovskyi.me,2012-01-11:/2012/01/pyopencl-on-x64-system/<p><span class="caps">UPD</span>: I found unofficial binary builds
here: <a class="reference external" href="http://www.lfd.uci.edu/~gohlke/pythonlibs/#pyopencl">http://www.lfd.uci.edu/~gohlke/pythonlibs/#pyopencl</a>, use x86 builds.</p>
<p>Do not forget to install <strong>pytools</strong>.</p>
<p>I’ve been into some difficulties since i began installing that software,
even with help of
<a class="reference external" href="http://wiki.tiker.net/PyOpenCL/Installation/Windows">http://wiki.tiker.net/PyOpenCL/Installation/Windows</a>.</p>
<p>First, <strong>easy_install won’t work on x64</strong> systems if installed by
executable installer. Instead, use ez_setup.py which will determine the
correct version of the software.</p>
<p>Next, install numpy.</p>
<p>finally, i’ve got a problem with module compilation. Let’s split it into
two problems:</p>
<ol class="arabic simple">
<li>wrong path to vcvarsall.bat (try to add …</li></ol><p><span class="caps">UPD</span>: I found unofficial binary builds
here: <a class="reference external" href="http://www.lfd.uci.edu/~gohlke/pythonlibs/#pyopencl">http://www.lfd.uci.edu/~gohlke/pythonlibs/#pyopencl</a>, use x86 builds.</p>
<p>Do not forget to install <strong>pytools</strong>.</p>
<p>I’ve been into some difficulties since i began installing that software,
even with help of
<a class="reference external" href="http://wiki.tiker.net/PyOpenCL/Installation/Windows">http://wiki.tiker.net/PyOpenCL/Installation/Windows</a>.</p>
<p>First, <strong>easy_install won’t work on x64</strong> systems if installed by
executable installer. Instead, use ez_setup.py which will determine the
correct version of the software.</p>
<p>Next, install numpy.</p>
<p>finally, i’ve got a problem with module compilation. Let’s split it into
two problems:</p>
<ol class="arabic simple">
<li>wrong path to vcvarsall.bat (try to add `C:\Program Files
(x86)\Microsoft Visual Studio 10.0\<span class="caps">VC</span>` to your path)</li>
<li>wrong c implementation: <strong>you need to get vs2008</strong> (even express will
not suffice)</li>
<li>Installing Visual Studio C++ 2008 Express didn’t provide all the
necessary headers such as windows.h, so grab this too and be ready to
give it 1.2Gb away. Nevertheless, first install fails with weird
reason. Refer to <a class="reference external" href="http://ctrlf5.net/?p=184">http://ctrlf5.net/?p=184</a> for further help.</li>
</ol>
<div><p>My siteconfig:</p>
</p><pre class="literal-block">
BOOST_INC_DIR = []
BOOST_LIB_DIR = []
BOOST_COMPILER = 'gcc43'
BOOST_PYTHON_LIBNAME = ['boost_python']
USE_SHIPPED_BOOST = True
CL_TRACE = False
CL_ENABLE_GL = False
CL_ENABLE_DEVICE_FISSION = True
CL_INC_DIR = [r'C:\Program Files (x86)\AMD APP\include']
CL_LIB_DIR = [r'C:\Program Files (x86)\AMD APP\lib\x86_64']
CL_LIBNAME = ['OpenCL']
CXXFLAGS = ['/EHsc']
LDFLAGS = []
</pre>
</div>Kokowääh2012-01-07T20:57:00+01:002012-01-07T20:57:00+01:00Andrew Berezovskyitag:berezovskyi.me,2012-01-07:/2012/01/kokowaah/<p>Impressive movie if you think about sense of life, productivity, decision making… turns to be that not taking risk is more dangerous than not to take a risk.</p>
<p>Somewhat expected happy-end is just a bit boring, but is setting positive reaction.</p>Firearms laws2012-01-05T19:20:00+01:002012-01-05T19:20:00+01:00Andrew Berezovskyitag:berezovskyi.me,2012-01-05:/2012/01/firearms-laws/<p>In Mexico, crime is rife. And the firearm law is one of the most severe.</p>
<p>Ukraine has lower crime level, somewhat similar gun licensing.</p>
<p>In the <span class="caps">US</span> you are free to buy a weapon and many states would issue a concealed carry permit. That leads to much lower crime rates than in aforementioned countries.</p>
<p>In Switzerland, you may own a full-auto rifle, shoot in all cantons freely. The crime level does nothing to correlate with firearm law.</p>
<p>In the opposite, use of firearms gives assault more protection.</p>Widget problem on Android2012-01-05T19:20:00+01:002012-01-05T19:20:00+01:00Andrew Berezovskyitag:berezovskyi.me,2012-01-05:/2012/01/widget-problem-on-android/<p>If you expect the widget, and it’s missing in the list, move the app to the phone memory.</p>win win 20112012-01-05T18:39:00+01:002012-01-05T18:39:00+01:00Andrew Berezovskyitag:berezovskyi.me,2012-01-05:/2012/01/win-win-2011/<p>so-so film, but i enjoyed it quite a bit. If you look closer, there is no win win everywhere. The reason for that is a trade-off you always have to face.</p>
<p>choose the right end and will be win win.</p>
<p>don’t be doomed.</p>Google Reader2012-01-05T15:40:00+01:002012-01-05T15:40:00+01:00Andrew Berezovskyitag:berezovskyi.me,2012-01-05:/2012/01/google-reader/<p>want some kind of page archiving, maybe somewhat mobile preparation after i star an rss item</p>Производная2011-12-28T13:58:00+01:002011-12-28T13:58:00+01:00admintag:berezovskyi.me,2011-12-28:/2011/12/proizvodnaya/<p>Чебаненко: <em>“Производная от константы равна константе”</em>.</p>
Connect to VPS from clean machine2011-12-06T23:22:00+01:002011-12-06T23:22:00+01:00admintag:berezovskyi.me,2011-12-06:/2011/12/connect-to-vps-from-clean-machine/<ol class="arabic simple">
<li>download putty</li>
<li>generate ssh key pairs on the client</li>
<li>download winSCP</li>
<li>upload public ssh key to the server</li>
<li>open putty key with puttygen</li>
<li>save it to proprietary format</li>
</ol>
<p>Remember to use echo correctly:</p>
<pre class="literal-block">
echo "something" > file
</pre>
<p>means that everything that’s in “file” will be deleted, and “something”
will be written to it (which means that “something” will be right at the
beginning of “file”.</p>
<p>Code:</p>
<div><pre class="literal-block">
echo "something" >> file
</pre>
</div><p>means that “something” will be appended to “file”, so nothing will be
deleted from “file”, and “something will be at the end of “file”.</p>
Kindle Collections2011-11-26T02:08:00+01:002011-11-26T02:08:00+01:00admintag:berezovskyi.me,2011-11-26:/2011/11/kindle-collections/<p><a class="reference external" href="http://www.applied-mathematics.net/tools/kindleCollectionManager.html">http://www.applied-mathematics.net/tools/kindleCollectionManager.html</a></p>
<p>Больше привлекла
<a class="reference external" href="http://www.colegate.net/KindleCollectionManager/screenshots.aspx">http://www.colegate.net/KindleCollectionManager/screenshots.aspx,</a> но
никаких писем из обещанных мне не досталось.</p>
The biggest risk is not to take any risk2011-11-02T10:21:00+01:002011-11-02T10:21:00+01:00admintag:berezovskyi.me,2011-11-02:/2011/11/the-biggest-risk-is-not-to-take-any-risk/<p>Link:</p>
<p><a class="reference external" href="http://www.justin.tv/startupschool#r=-rid-&s=em">Watch live video from Startup School on Justin.tv</a></p>
Installing Ruby & Ruby on Rails on Ubuntu box2011-06-27T01:04:00+02:002011-06-27T01:04:00+02:00admintag:berezovskyi.me,2011-06-27:/2011/06/installing-ruby-ruby-on-rails-on-ubuntu-box/<p>Start by:
<a class="reference external" href="http://itshouldbeuseful.wordpress.com/2011/05/04/setting-up-ubuntu-11-04-for-rails-development/">http://itshouldbeuseful.wordpress.com/2011/05/04/setting-up-ubuntu-11-04-for-rails-development/</a></p>
<p>Dig deeper with:
<a class="reference external" href="http://ryanbigg.com/2010/12/ubuntu-ruby-rvm-rails-and-you/">http://ryanbigg.com/2010/12/ubuntu-ruby-rvm-rails-and-you/</a></p>
<p>If you install rvm as root and fall in bunch of problems, visit:
<a class="reference external" href="http://stackoverflow.com/questions/5253643/cannot-install-rvm-permission-denied-in-usr-local-rvm">http://stackoverflow.com/questions/5253643/cannot-install-rvm-permission-denied-in-usr-local-rvm</a></p>
Nautilus refuses to set some application as default for mimetype?2011-06-21T22:20:00+02:002011-06-21T22:20:00+02:00admintag:berezovskyi.me,2011-06-21:/2011/06/nautilus-refuses-to-set-some-application-as-default-for-mimetype/<p>Navigate to ~/.local/share/applications/ and edit mimeapps.list</p>
Symfony2 w/PHP5.3 on Ubuntu 11.04 / Nginx2011-05-27T16:21:00+02:002011-05-27T16:21:00+02:00admintag:berezovskyi.me,2011-05-27:/2011/05/symfony2-wphp5-3-on-ubuntu-11-04-nginx/<pre class="literal-block">
sudo apt-get install php5
sudo apt-get install php5-suhosin
</pre>
<p><em>Nginx.conf</em>:</p>
<pre class="literal-block">
try_files $uri $uri/ /index.php;
location ~ \.php(/.*)?$ {
fastcgi_split_path_info ^(.+\.php)(.*)$;
fastcgi_pass backend;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www$fastcgi_script_name;
include fastcgi_params;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_intercept_errors on;
fastcgi_ignore_client_abort off;
fastcgi_connect_timeout 60;
fastcgi_send_timeout 180;
fastcgi_read_timeout 180;
fastcgi_buffer_size 128k;
fastcgi_buffers 4 256k;
fastcgi_busy_buffers_size 256k;
fastcgi_temp_file_write_size 256k;
}
#error_page 404 /404.html;
location /web/ {
root /var/www/;
allow all;
}
</pre>
<p>Restart Nginx</p>
<pre class="literal-block">
ps -ax | grep nginx
kill 1021
sudo /etc/init.d/nginx restart
</pre>
<p>Install <span class="caps">PHP</span>-<span class="caps">FPM</span>:</p>
<pre class="literal-block">
sudo apt-get install php5-fpm
sudo /etc/init.d/php5-fpm restart …</pre><pre class="literal-block">
sudo apt-get install php5
sudo apt-get install php5-suhosin
</pre>
<p><em>Nginx.conf</em>:</p>
<pre class="literal-block">
try_files $uri $uri/ /index.php;
location ~ \.php(/.*)?$ {
fastcgi_split_path_info ^(.+\.php)(.*)$;
fastcgi_pass backend;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /var/www$fastcgi_script_name;
include fastcgi_params;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_intercept_errors on;
fastcgi_ignore_client_abort off;
fastcgi_connect_timeout 60;
fastcgi_send_timeout 180;
fastcgi_read_timeout 180;
fastcgi_buffer_size 128k;
fastcgi_buffers 4 256k;
fastcgi_busy_buffers_size 256k;
fastcgi_temp_file_write_size 256k;
}
#error_page 404 /404.html;
location /web/ {
root /var/www/;
allow all;
}
</pre>
<p>Restart Nginx</p>
<pre class="literal-block">
ps -ax | grep nginx
kill 1021
sudo /etc/init.d/nginx restart
</pre>
<p>Install <span class="caps">PHP</span>-<span class="caps">FPM</span>:</p>
<pre class="literal-block">
sudo apt-get install php5-fpm
sudo /etc/init.d/php5-fpm restart
</pre>
<p>Install SqLite:</p>
<pre class="literal-block">
sudo apt-get install php5-sqlite
sudo /etc/init.d/php5-fpm restart
</pre>
<p>Install internationalization tools:</p>
<pre class="literal-block">
sudo apt-get install php5-intl
</pre>
<p><span class="caps">PEAR</span> for <span class="caps">APC</span>:</p>
<pre class="literal-block">
sudo apt-get install php5-intl php-pear
sudo /etc/init.d/php5-fpm restart
sudo pecl install apc
</pre>
<p>Add date.datetime for your zone and turn shorthand tag mode off:</p>
<pre class="literal-block">
sudo vim php.ini
</pre>
<p>You’re done!</p>
<pre class="literal-block">
sudo /etc/init.d/php5-fpm restart
</pre>
Scrapy 0.12 Parsing with python2011-05-24T10:35:00+02:002011-05-24T10:35:00+02:00admintag:berezovskyi.me,2011-05-24:/2011/05/scrapy-0-12-parsing-with-python/<p>Based on Scrapy Tutorial (dead link: doc.scrapy.org/intro/tutorial.html)</p>
<ol class="arabic simple">
<li>Install scrapy and dependencies</li>
</ol>
<pre class="code bash literal-block">
sudo<span class="w"> </span>apt-get<span class="w"> </span>install<span class="w"> </span>python-lxml<span class="w">
</span>sudo<span class="w"> </span>easy_install<span class="w"> </span>-U<span class="w"> </span>Scrapy
</pre>
<ol class="arabic simple" start="2">
<li>Create project</li>
</ol>
<pre class="code bash literal-block">
scrapy<span class="w"> </span>startproject<span class="w"> </span>dmoz
</pre>
<ol class="arabic simple" start="3">
<li>Create item models</li>
</ol>
<pre class="code python literal-block">
<span class="kn">from</span> <span class="nn">scrapy.item</span> <span class="kn">import</span> <span class="n">Item</span><span class="p">,</span> <span class="n">Field</span><span class="w">
</span><span class="k">class</span> <span class="nc">DmozItem</span><span class="p">(</span><span class="n">Item</span><span class="p">):</span><span class="w">
</span> <span class="n">title</span> <span class="o">=</span> <span class="n">Field</span><span class="p">()</span><span class="w">
</span> <span class="n">link</span> <span class="o">=</span> <span class="n">Field</span><span class="p">()</span><span class="w">
</span> <span class="n">desc</span> <span class="o">=</span> <span class="n">Field</span><span class="p">()</span>
</pre>
<ol class="arabic simple" start="4">
<li>Create spiders (in <cite>projname/spiders/</cite>)</li>
</ol>
<pre class="code python literal-block">
<span class="kn">from</span> <span class="nn">scrapy.spider</span> <span class="kn">import</span> <span class="n">BaseSpider</span><span class="w">
</span><span class="kn">from</span> <span class="nn">scrapy.selector</span> <span class="kn">import</span> <span class="n">HtmlXPathSelector</span><span class="w">
</span><span class="kn">from</span> <span class="nn">dmoz.items</span> <span class="kn">import</span> <span class="n">DmozItem</span><span class="w">
</span><span class="k">class</span> <span class="nc">DmozSpider</span><span class="p">(</span><span class="n">BaseSpider</span><span class="p">):</span><span class="w">
</span> <span class="n">name</span> <span class="o">=</span> <span class="s2">"dmoz.org"</span><span class="w">
</span> <span class="n">allowed_domains</span> <span class="o">=</span> <span class="p">[</span><span class="s2">"dmoz.org"</span><span class="p">]</span><span class="w">
</span> <span class="n">start_urls</span> <span class="o">=</span> <span class="p">[</span><span class="w">
</span> <span class="s2">"http://www.dmoz.org/Computers/Programming/Languages/Python/Books/"</span><span class="p">,</span><span class="w">
</span> <span class="s2">"http://www.dmoz.org/Computers/Programming/Languages/Python/Resources/"</span><span class="w">
</span> <span class="p">]</span><span class="w">
</span> <span class="k">def</span> <span class="nf">parse</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">response</span><span class="p">):</span><span class="w">
</span> <span class="n">hxs …</span></pre><p>Based on Scrapy Tutorial (dead link: doc.scrapy.org/intro/tutorial.html)</p>
<ol class="arabic simple">
<li>Install scrapy and dependencies</li>
</ol>
<pre class="code bash literal-block">
sudo<span class="w"> </span>apt-get<span class="w"> </span>install<span class="w"> </span>python-lxml<span class="w">
</span>sudo<span class="w"> </span>easy_install<span class="w"> </span>-U<span class="w"> </span>Scrapy
</pre>
<ol class="arabic simple" start="2">
<li>Create project</li>
</ol>
<pre class="code bash literal-block">
scrapy<span class="w"> </span>startproject<span class="w"> </span>dmoz
</pre>
<ol class="arabic simple" start="3">
<li>Create item models</li>
</ol>
<pre class="code python literal-block">
<span class="kn">from</span> <span class="nn">scrapy.item</span> <span class="kn">import</span> <span class="n">Item</span><span class="p">,</span> <span class="n">Field</span><span class="w">
</span><span class="k">class</span> <span class="nc">DmozItem</span><span class="p">(</span><span class="n">Item</span><span class="p">):</span><span class="w">
</span> <span class="n">title</span> <span class="o">=</span> <span class="n">Field</span><span class="p">()</span><span class="w">
</span> <span class="n">link</span> <span class="o">=</span> <span class="n">Field</span><span class="p">()</span><span class="w">
</span> <span class="n">desc</span> <span class="o">=</span> <span class="n">Field</span><span class="p">()</span>
</pre>
<ol class="arabic simple" start="4">
<li>Create spiders (in <cite>projname/spiders/</cite>)</li>
</ol>
<pre class="code python literal-block">
<span class="kn">from</span> <span class="nn">scrapy.spider</span> <span class="kn">import</span> <span class="n">BaseSpider</span><span class="w">
</span><span class="kn">from</span> <span class="nn">scrapy.selector</span> <span class="kn">import</span> <span class="n">HtmlXPathSelector</span><span class="w">
</span><span class="kn">from</span> <span class="nn">dmoz.items</span> <span class="kn">import</span> <span class="n">DmozItem</span><span class="w">
</span><span class="k">class</span> <span class="nc">DmozSpider</span><span class="p">(</span><span class="n">BaseSpider</span><span class="p">):</span><span class="w">
</span> <span class="n">name</span> <span class="o">=</span> <span class="s2">"dmoz.org"</span><span class="w">
</span> <span class="n">allowed_domains</span> <span class="o">=</span> <span class="p">[</span><span class="s2">"dmoz.org"</span><span class="p">]</span><span class="w">
</span> <span class="n">start_urls</span> <span class="o">=</span> <span class="p">[</span><span class="w">
</span> <span class="s2">"http://www.dmoz.org/Computers/Programming/Languages/Python/Books/"</span><span class="p">,</span><span class="w">
</span> <span class="s2">"http://www.dmoz.org/Computers/Programming/Languages/Python/Resources/"</span><span class="w">
</span> <span class="p">]</span><span class="w">
</span> <span class="k">def</span> <span class="nf">parse</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">response</span><span class="p">):</span><span class="w">
</span> <span class="n">hxs</span> <span class="o">=</span> <span class="n">HtmlXPathSelector</span><span class="p">(</span><span class="n">response</span><span class="p">)</span><span class="w">
</span> <span class="n">sites</span> <span class="o">=</span> <span class="n">hxs</span><span class="o">.</span><span class="n">select</span><span class="p">(</span><span class="s1">'//ul/li'</span><span class="p">)</span><span class="w">
</span> <span class="n">items</span> <span class="o">=</span> <span class="p">[]</span><span class="w">
</span> <span class="k">for</span> <span class="n">site</span> <span class="ow">in</span> <span class="n">sites</span><span class="p">:</span><span class="w">
</span> <span class="n">item</span> <span class="o">=</span> <span class="n">DmozItem</span><span class="p">()</span><span class="w">
</span> <span class="n">item</span><span class="p">[</span><span class="s1">'title'</span><span class="p">]</span> <span class="o">=</span> <span class="n">site</span><span class="o">.</span><span class="n">select</span><span class="p">(</span><span class="s1">'a/text()'</span><span class="p">)</span><span class="o">.</span><span class="n">extract</span><span class="p">()</span><span class="w">
</span> <span class="n">item</span><span class="p">[</span><span class="s1">'link'</span><span class="p">]</span> <span class="o">=</span> <span class="n">site</span><span class="o">.</span><span class="n">select</span><span class="p">(</span><span class="s1">'a/@href'</span><span class="p">)</span><span class="o">.</span><span class="n">extract</span><span class="p">()</span><span class="w">
</span> <span class="n">item</span><span class="p">[</span><span class="s1">'desc'</span><span class="p">]</span> <span class="o">=</span> <span class="n">site</span><span class="o">.</span><span class="n">select</span><span class="p">(</span><span class="s1">'text()'</span><span class="p">)</span><span class="o">.</span><span class="n">extract</span><span class="p">()</span><span class="w">
</span> <span class="n">items</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">item</span><span class="p">)</span><span class="w">
</span> <span class="k">return</span> <span class="n">items</span>
</pre>
<ol class="arabic simple" start="5">
<li>Run spiders</li>
</ol>
<pre class="code bash literal-block">
scrapy<span class="w"> </span>crawl<span class="w"> </span>dmoz.org<span class="w">
</span>scrapy<span class="w"> </span>crawl<span class="w"> </span>dmoz.org<span class="w"> </span>--set<span class="w"> </span><span class="nv">FEED_URI</span><span class="o">=</span>items.json<span class="w"> </span>--set<span class="w"> </span><span class="nv">FEED_FORMAT</span><span class="o">=</span>json<span class="w">
</span>scrapy<span class="w"> </span>crawl<span class="w"> </span>dmoz.org<span class="w"> </span>--set<span class="w"> </span><span class="nv">FEED_URI</span><span class="o">=</span>items.csv<span class="w"> </span>--set<span class="w"> </span><span class="nv">FEED_FORMAT</span><span class="o">=</span>csv
</pre>
BeautifulSoup Parsing2011-05-24T10:07:00+02:002011-05-24T10:07:00+02:00admintag:berezovskyi.me,2011-05-24:/2011/05/beautifulsoup-parsing/<div class="section" id="import-dependencies">
<h3>1. Import dependencies</h3>
<pre class="code python literal-block">
<span class="kn">import</span> <span class="nn">urllib</span><span class="w">
</span><span class="kn">from</span> <span class="nn">BeautifulSoup</span> <span class="kn">import</span> <span class="n">BeautifulSoup</span>
</pre>
</div>
<div class="section" id="settings">
<h3>2. Settings</h3>
<pre class="code python literal-block">
<span class="n">site</span> <span class="o">=</span> <span class="s2">"http://****.in.ua"</span><span class="w">
</span><span class="n">base</span> <span class="o">=</span> <span class="n">site</span> <span class="o">+</span> <span class="s2">"/url/****.html"</span><span class="w">
</span><span class="n">parse_urls</span> <span class="o">=</span> <span class="p">[</span><span class="s2">"?page=1"</span><span class="p">,]</span><span class="w">
</span><span class="n">parsed</span> <span class="o">=</span> <span class="p">[]</span><span class="w">
</span><span class="n">urls</span> <span class="o">=</span> <span class="p">[]</span>
</pre>
</div>
<div class="section" id="prepopulate-urls-bank-with-paging">
<h3>3. prepopulate urls bank with paging</h3>
<pre class="code python literal-block">
<span class="k">def</span> <span class="nf">parser</span><span class="p">(</span><span class="n">fun</span><span class="p">):</span><span class="w">
</span> <span class="n">element</span> <span class="o">=</span> <span class="n">parse_urls</span><span class="o">.</span><span class="n">pop</span><span class="p">()</span><span class="w">
</span> <span class="n">parsed</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">element</span><span class="p">)</span><span class="w">
</span> <span class="n">page</span> <span class="o">=</span> <span class="n">urllib</span><span class="o">.</span><span class="n">urlopen</span><span class="p">(</span><span class="n">base</span> <span class="o">+</span> <span class="n">element</span><span class="p">)</span><span class="w">
</span> <span class="n">soup</span> <span class="o">=</span> <span class="n">BeautifulSoup</span><span class="p">(</span><span class="n">page</span><span class="o">.</span><span class="n">read</span><span class="p">())</span><span class="w">
</span> <span class="k">for</span> <span class="n">topic</span> <span class="ow">in</span> <span class="n">soup</span><span class="o">.</span><span class="n">findAll</span><span class="p">(</span><span class="kc">True</span><span class="p">,</span> <span class="s1">'right_block'</span><span class="p">):</span><span class="w">
</span> <span class="n">urls</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">topic</span><span class="o">.</span><span class="n">p</span><span class="o">.</span><span class="n">a</span><span class="p">[</span><span class="s2">"href"</span><span class="p">])</span><span class="w">
</span> <span class="k">for</span> <span class="n">link</span> <span class="ow">in</span> <span class="n">soup</span><span class="o">.</span><span class="n">find</span><span class="p">(</span><span class="nb">id</span><span class="o">=</span><span class="s2">"page_list"</span><span class="p">)</span><span class="o">.</span><span class="n">findAll</span><span class="p">(</span><span class="s1">'li'</span><span class="p">):</span><span class="w">
</span> <span class="k">if</span> <span class="p">(</span><span class="n">link</span><span class="o">.</span><span class="n">a</span><span class="p">[</span><span class="s2">"href"</span><span class="p">]</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">parse_urls</span> <span class="ow">and</span> <span class="n">link</span><span class="o">.</span><span class="n">a</span><span class="p">[</span><span class="s2">"href"</span><span class="p">]</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">parsed</span><span class="p">):</span><span class="w">
</span> <span class="n">parse_urls</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">link</span><span class="o">.</span><span class="n">a</span><span class="p">[</span><span class="s2">"href"</span><span class="p">])</span><span class="w">
</span><span class="k">while</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">parse_urls</span><span class="p">)</span> <span class="o">!=</span> <span class="mi">0</span><span class="p">):</span><span class="w">
</span> <span class="n">parser</span><span class="p">(</span><span class="n">blog_parse</span><span class="p">)</span>
</pre>
</div>
<div class="section" id="parse">
<h3>4. Parse</h3>
<pre class="code python literal-block">
<span class="n">pages</span> <span class="o">=</span> <span class="p">[]</span><span class="w">
</span><span class="k">for</span> <span class="n">url …</span></pre></div><div class="section" id="import-dependencies">
<h3>1. Import dependencies</h3>
<pre class="code python literal-block">
<span class="kn">import</span> <span class="nn">urllib</span><span class="w">
</span><span class="kn">from</span> <span class="nn">BeautifulSoup</span> <span class="kn">import</span> <span class="n">BeautifulSoup</span>
</pre>
</div>
<div class="section" id="settings">
<h3>2. Settings</h3>
<pre class="code python literal-block">
<span class="n">site</span> <span class="o">=</span> <span class="s2">"http://****.in.ua"</span><span class="w">
</span><span class="n">base</span> <span class="o">=</span> <span class="n">site</span> <span class="o">+</span> <span class="s2">"/url/****.html"</span><span class="w">
</span><span class="n">parse_urls</span> <span class="o">=</span> <span class="p">[</span><span class="s2">"?page=1"</span><span class="p">,]</span><span class="w">
</span><span class="n">parsed</span> <span class="o">=</span> <span class="p">[]</span><span class="w">
</span><span class="n">urls</span> <span class="o">=</span> <span class="p">[]</span>
</pre>
</div>
<div class="section" id="prepopulate-urls-bank-with-paging">
<h3>3. prepopulate urls bank with paging</h3>
<pre class="code python literal-block">
<span class="k">def</span> <span class="nf">parser</span><span class="p">(</span><span class="n">fun</span><span class="p">):</span><span class="w">
</span> <span class="n">element</span> <span class="o">=</span> <span class="n">parse_urls</span><span class="o">.</span><span class="n">pop</span><span class="p">()</span><span class="w">
</span> <span class="n">parsed</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">element</span><span class="p">)</span><span class="w">
</span> <span class="n">page</span> <span class="o">=</span> <span class="n">urllib</span><span class="o">.</span><span class="n">urlopen</span><span class="p">(</span><span class="n">base</span> <span class="o">+</span> <span class="n">element</span><span class="p">)</span><span class="w">
</span> <span class="n">soup</span> <span class="o">=</span> <span class="n">BeautifulSoup</span><span class="p">(</span><span class="n">page</span><span class="o">.</span><span class="n">read</span><span class="p">())</span><span class="w">
</span> <span class="k">for</span> <span class="n">topic</span> <span class="ow">in</span> <span class="n">soup</span><span class="o">.</span><span class="n">findAll</span><span class="p">(</span><span class="kc">True</span><span class="p">,</span> <span class="s1">'right_block'</span><span class="p">):</span><span class="w">
</span> <span class="n">urls</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">topic</span><span class="o">.</span><span class="n">p</span><span class="o">.</span><span class="n">a</span><span class="p">[</span><span class="s2">"href"</span><span class="p">])</span><span class="w">
</span> <span class="k">for</span> <span class="n">link</span> <span class="ow">in</span> <span class="n">soup</span><span class="o">.</span><span class="n">find</span><span class="p">(</span><span class="nb">id</span><span class="o">=</span><span class="s2">"page_list"</span><span class="p">)</span><span class="o">.</span><span class="n">findAll</span><span class="p">(</span><span class="s1">'li'</span><span class="p">):</span><span class="w">
</span> <span class="k">if</span> <span class="p">(</span><span class="n">link</span><span class="o">.</span><span class="n">a</span><span class="p">[</span><span class="s2">"href"</span><span class="p">]</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">parse_urls</span> <span class="ow">and</span> <span class="n">link</span><span class="o">.</span><span class="n">a</span><span class="p">[</span><span class="s2">"href"</span><span class="p">]</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">parsed</span><span class="p">):</span><span class="w">
</span> <span class="n">parse_urls</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">link</span><span class="o">.</span><span class="n">a</span><span class="p">[</span><span class="s2">"href"</span><span class="p">])</span><span class="w">
</span><span class="k">while</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">parse_urls</span><span class="p">)</span> <span class="o">!=</span> <span class="mi">0</span><span class="p">):</span><span class="w">
</span> <span class="n">parser</span><span class="p">(</span><span class="n">blog_parse</span><span class="p">)</span>
</pre>
</div>
<div class="section" id="parse">
<h3>4. Parse</h3>
<pre class="code python literal-block">
<span class="n">pages</span> <span class="o">=</span> <span class="p">[]</span><span class="w">
</span><span class="k">for</span> <span class="n">url</span> <span class="ow">in</span> <span class="n">urls</span><span class="p">:</span><span class="w">
</span> <span class="n">page</span> <span class="o">=</span> <span class="n">urllib</span><span class="o">.</span><span class="n">urlopen</span><span class="p">(</span><span class="n">site</span> <span class="o">+</span> <span class="n">urllib</span><span class="o">.</span><span class="n">quote</span><span class="p">(</span><span class="n">url</span><span class="o">.</span><span class="n">encode</span><span class="p">(</span><span class="s2">"cp1251"</span><span class="p">)))</span><span class="w">
</span> <span class="n">soup</span> <span class="o">=</span> <span class="n">BeautifulSoup</span><span class="p">(</span><span class="n">page</span><span class="o">.</span><span class="n">read</span><span class="p">())</span><span class="w">
</span> <span class="nb">print</span> <span class="n">url</span><span class="w">
</span> <span class="n">a</span> <span class="o">=</span> <span class="n">parse_item</span><span class="p">(</span><span class="n">soup</span><span class="p">)</span><span class="w">
</span> <span class="n">pages</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">a</span><span class="p">)</span>
</pre>
</div>
<div class="section" id="populate-django-db-orm">
<h3>5. Populate Django <span class="caps">DB</span> <span class="caps">ORM</span></h3>
<pre class="code python literal-block">
<span class="k">def</span> <span class="nf">parse_item</span><span class="p">(</span><span class="n">soup</span><span class="p">):</span><span class="w">
</span> <span class="n">header</span> <span class="o">=</span> <span class="n">soup</span><span class="o">.</span><span class="n">find</span><span class="p">(</span><span class="s2">"div"</span><span class="p">,</span> <span class="nb">id</span><span class="o">=</span><span class="s2">"avtor"</span><span class="p">)</span><span class="o">.</span><span class="n">findAll</span><span class="p">(</span><span class="s2">"span"</span><span class="p">)</span><span class="w">
</span> <span class="p">(</span><span class="n">name</span><span class="p">,</span> <span class="n">surname</span><span class="p">)</span> <span class="o">=</span> <span class="n">header</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">string</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s2">","</span><span class="p">)[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s2">" "</span><span class="p">)</span><span class="w">
</span> <span class="p">(</span><span class="nb">id</span><span class="p">,</span> <span class="n">new</span><span class="p">)</span> <span class="o">=</span> <span class="n">Author</span><span class="o">.</span><span class="n">objects</span><span class="o">.</span><span class="n">get_or_create</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="n">name</span><span class="p">,</span> <span class="n">surname</span><span class="o">=</span><span class="n">surname</span><span class="p">)</span><span class="w">
</span> <span class="n">a</span> <span class="o">=</span> <span class="n">Article</span><span class="p">()</span><span class="w">
</span> <span class="n">a</span><span class="o">.</span><span class="n">author</span> <span class="o">=</span> <span class="nb">id</span><span class="w">
</span> <span class="n">a</span><span class="o">.</span><span class="n">title</span> <span class="o">=</span> <span class="n">soup</span><span class="o">.</span><span class="n">find</span><span class="p">(</span><span class="s2">"div"</span><span class="p">,</span> <span class="nb">id</span><span class="o">=</span><span class="s2">"view"</span><span class="p">)</span><span class="o">.</span><span class="n">h1</span><span class="o">.</span><span class="n">string</span><span class="w">
</span> <span class="p">(</span><span class="n">day</span><span class="p">,</span> <span class="n">month</span><span class="p">,</span> <span class="n">year</span><span class="p">)</span> <span class="o">=</span> <span class="n">re</span><span class="o">.</span><span class="n">findall</span><span class="p">(</span><span class="sa">r</span><span class="s1">'(\d+)\.(\d+)\.(\d+)'</span><span class="p">,</span> <span class="n">header</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">string</span><span class="o">.</span><span class="n">strip</span><span class="p">())[</span><span class="mi">0</span><span class="p">]</span><span class="w">
</span> <span class="n">a</span><span class="o">.</span><span class="n">date</span> <span class="o">=</span> <span class="n">datetime</span><span class="p">(</span><span class="nb">int</span><span class="p">(</span><span class="n">year</span><span class="p">),</span><span class="nb">int</span><span class="p">(</span><span class="n">month</span><span class="p">),</span> <span class="nb">int</span><span class="p">(</span><span class="n">day</span><span class="p">))</span><span class="w">
</span> <span class="n">a</span><span class="o">.</span><span class="n">description</span> <span class="o">=</span> <span class="n">soup</span><span class="o">.</span><span class="n">find</span><span class="p">(</span><span class="s2">"div"</span><span class="p">,</span> <span class="nb">id</span><span class="o">=</span><span class="s2">"view"</span><span class="p">)</span><span class="o">.</span><span class="n">p</span><span class="o">.</span><span class="n">renderContents</span><span class="p">()</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span><span class="w">
</span> <span class="k">for</span> <span class="n">item</span> <span class="ow">in</span> <span class="n">soup</span><span class="o">.</span><span class="n">find</span><span class="p">(</span><span class="s2">"div"</span><span class="p">,</span> <span class="nb">id</span><span class="o">=</span><span class="s2">"view"</span><span class="p">)</span><span class="o">.</span><span class="n">findAll</span><span class="p">(</span><span class="s2">"div"</span><span class="p">):</span><span class="w">
</span> <span class="k">if</span> <span class="p">(</span><span class="s2">"id"</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">item</span><span class="p">)</span> <span class="ow">and</span> <span class="p">(</span><span class="s2">"class"</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">item</span><span class="p">)</span> <span class="ow">and</span> <span class="n">item</span><span class="o">.</span><span class="n">string</span> <span class="o">!=</span> <span class="kc">None</span> <span class="ow">and</span> <span class="n">item</span><span class="o">.</span><span class="n">renderContents</span><span class="p">()</span> <span class="o">!=</span> <span class="kc">None</span> <span class="p">:</span><span class="w">
</span> <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">item</span><span class="o">.</span><span class="n">renderContents</span><span class="p">()</span><span class="o">.</span><span class="n">strip</span><span class="p">())</span> <span class="o">></span> <span class="mi">0</span><span class="p">:</span><span class="w">
</span> <span class="n">a</span><span class="o">.</span><span class="n">body</span> <span class="o">+=</span> <span class="n">item</span><span class="o">.</span><span class="n">renderContents</span><span class="p">()</span><span class="o">.</span><span class="n">strip</span><span class="p">()</span> <span class="o">+</span> <span class="s2">"</span><span class="se">\n</span><span class="s2">"</span><span class="w">
</span> <span class="n">i</span> <span class="o">=</span> <span class="n">randint</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">46364202620</span><span class="p">)</span><span class="w">
</span> <span class="n">m</span> <span class="o">=</span> <span class="n">hashlib</span><span class="o">.</span><span class="n">md5</span><span class="p">()</span><span class="w">
</span> <span class="n">m</span><span class="o">.</span><span class="n">update</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">i</span><span class="p">))</span><span class="w">
</span> <span class="n">urlfile</span> <span class="o">=</span> <span class="n">soup</span><span class="o">.</span><span class="n">find</span><span class="p">(</span><span class="s2">"div"</span><span class="p">,</span> <span class="nb">id</span><span class="o">=</span><span class="s2">"galImg"</span><span class="p">)</span><span class="o">.</span><span class="n">img</span><span class="p">[</span><span class="s2">"src"</span><span class="p">]</span><span class="w">
</span> <span class="n">a</span><span class="o">.</span><span class="n">image</span><span class="o">.</span><span class="n">save</span><span class="p">(</span><span class="n">m</span><span class="o">.</span><span class="n">hexdigest</span><span class="p">()</span><span class="o">+</span><span class="s2">"."</span><span class="o">+</span><span class="n">urlfile</span><span class="o">.</span><span class="n">split</span><span class="p">(</span><span class="s2">"."</span><span class="p">)[</span><span class="o">-</span><span class="mi">1</span><span class="p">],</span> <span class="n">ContentFile</span><span class="p">(</span><span class="n">urllib</span><span class="o">.</span><span class="n">urlopen</span><span class="p">(</span><span class="n">urlfile</span><span class="p">)</span><span class="o">.</span><span class="n">read</span><span class="p">()))</span><span class="w">
</span> <span class="n">a</span><span class="o">.</span><span class="n">save</span><span class="p">()</span>
</pre>
</div>
<div class="section" id="django-models">
<h3>6. Django Models</h3>
<pre class="code python literal-block">
<span class="kn">from</span> <span class="nn">django.db</span> <span class="kn">import</span> <span class="n">models</span><span class="w">
</span><span class="kn">from</span> <span class="nn">django.contrib.auth.models</span> <span class="kn">import</span> <span class="n">User</span><span class="w">
</span><span class="k">class</span> <span class="nc">Author</span><span class="p">(</span><span class="n">models</span><span class="o">.</span><span class="n">Model</span><span class="p">):</span><span class="w">
</span> <span class="n">name</span> <span class="o">=</span> <span class="n">models</span><span class="o">.</span><span class="n">CharField</span><span class="p">(</span><span class="n">max_length</span><span class="o">=</span><span class="mi">100</span><span class="p">)</span><span class="w">
</span> <span class="n">surname</span> <span class="o">=</span> <span class="n">models</span><span class="o">.</span><span class="n">CharField</span><span class="p">(</span><span class="n">max_length</span><span class="o">=</span><span class="mi">100</span><span class="p">)</span><span class="w">
</span> <span class="k">def</span> <span class="nf">articles</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span><span class="w">
</span> <span class="k">return</span> <span class="n">Article</span><span class="o">.</span><span class="n">objects</span><span class="o">.</span><span class="n">filter</span><span class="p">(</span><span class="n">author</span> <span class="o">=</span> <span class="bp">self</span><span class="p">)</span><span class="o">.</span><span class="n">count</span><span class="p">()</span><span class="w">
</span> <span class="k">def</span> <span class="nf">__unicode__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span><span class="w">
</span> <span class="k">return</span> <span class="s2">"</span><span class="si">%s</span><span class="s2"> </span><span class="si">%s</span><span class="s2">"</span> <span class="o">%</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">name</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">surname</span><span class="p">)</span><span class="w">
</span><span class="k">class</span> <span class="nc">Article</span><span class="p">(</span><span class="n">models</span><span class="o">.</span><span class="n">Model</span><span class="p">):</span><span class="w">
</span> <span class="n">title</span> <span class="o">=</span> <span class="n">models</span><span class="o">.</span><span class="n">CharField</span><span class="p">(</span><span class="n">max_length</span><span class="o">=</span><span class="mi">100</span><span class="p">)</span><span class="w">
</span> <span class="n">author</span> <span class="o">=</span> <span class="n">models</span><span class="o">.</span><span class="n">ForeignKey</span><span class="p">(</span><span class="n">Author</span><span class="p">)</span><span class="w">
</span> <span class="n">date</span> <span class="o">=</span> <span class="n">models</span><span class="o">.</span><span class="n">DateField</span><span class="p">()</span><span class="w">
</span> <span class="n">description</span> <span class="o">=</span> <span class="n">models</span><span class="o">.</span><span class="n">TextField</span><span class="p">()</span><span class="w">
</span> <span class="n">body</span> <span class="o">=</span> <span class="n">models</span><span class="o">.</span><span class="n">TextField</span><span class="p">()</span><span class="w">
</span> <span class="n">image</span> <span class="o">=</span> <span class="n">models</span><span class="o">.</span><span class="n">FileField</span><span class="p">(</span><span class="n">upload_to</span><span class="o">=</span><span class="s2">"attachments"</span><span class="p">)</span><span class="w">
</span> <span class="k">def</span> <span class="nf">__unicode__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span><span class="w">
</span> <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">title</span><span class="w">
</span><span class="k">class</span> <span class="nc">UploaderProfile</span><span class="p">(</span><span class="n">models</span><span class="o">.</span><span class="n">Model</span><span class="p">):</span><span class="w">
</span> <span class="n">uploads</span> <span class="o">=</span> <span class="n">models</span><span class="o">.</span><span class="n">IntegerField</span><span class="p">()</span><span class="w">
</span> <span class="n">user</span> <span class="o">=</span> <span class="n">models</span><span class="o">.</span><span class="n">OneToOneField</span><span class="p">(</span><span class="n">User</span><span class="p">)</span><span class="w">
</span> <span class="k">def</span> <span class="nf">__unicode__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span><span class="w">
</span> <span class="k">return</span> <span class="s2">"</span><span class="si">%s</span><span class="s2"> (</span><span class="si">%d</span><span class="s2"> files uploaded)"</span> <span class="o">%</span> <span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">user</span><span class="o">.</span><span class="n">username</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">uploads</span><span class="p">)</span>
</pre>
</div>
Installing MongoDB 1.8.1 on Ubuntu 11.04 and PyMongo2011-05-24T06:08:00+02:002011-05-24T06:08:00+02:00admintag:berezovskyi.me,2011-05-24:/2011/05/installing-mongodb-1-8-1-on-ubuntu-11-04-and-pymongo/<p>Install everything you need:</p>
<pre class="code bash literal-block">
sudo<span class="w"> </span>apt-key<span class="w"> </span>adv<span class="w"> </span>--keyserver<span class="w"> </span>keyserver.ubuntu.com<span class="w"> </span>--recv<span class="w"> </span>7F0CEB10<span class="w">
</span>sudo<span class="w"> </span>nano<span class="w"> </span>/etc/apt/sources.list
</pre>
<p>Next, add a line to sources.list:</p>
<ul class="simple">
<li>on Ubuntu</li>
</ul>
<pre class="code literal-block">
deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen
</pre>
<ul class="simple">
<li>on Debian</li>
</ul>
<pre class="code literal-block">
deb http://downloads-distro.mongodb.org/repo/debian-sysvinit dist 10gen
</pre>
<pre class="code bash literal-block">
sudo<span class="w"> </span>apt-get<span class="w"> </span>update<span class="w">
</span>sudo<span class="w"> </span>apt-get<span class="w"> </span>install<span class="w"> </span>mongodb-10gen<span class="w">
</span>sudo<span class="w"> </span>apt-get<span class="w"> </span>install<span class="w"> </span>python-setuptools<span class="w">
</span>sudo<span class="w"> </span>easy_install<span class="w"> </span>pymongo
</pre>
<p>Next, test the connection:</p>
<pre class="code python literal-block">
<span class="kn">from</span> <span class="nn">pymongo.connection</span> <span class="kn">import</span> <span class="n">Connection</span><span class="w">
</span><span class="kn">from</span> <span class="nn">pymongo</span> <span class="kn">import</span> <span class="n">ASCENDING</span><span class="w">
</span><span class="n">connection</span> <span class="o">=</span> <span class="n">Connection</span><span class="p">(</span><span class="s2">"localhost"</span><span class="p">,</span> <span class="mi">27017</span><span class="p">)</span><span class="w">
</span><span class="n">db</span> <span class="o">=</span> <span class="n">connection</span><span class="o">.</span><span class="n">test</span><span class="w">
</span><span class="n">db</span><span class="o">.</span><span class="n">my_collection</span><span class="o">.</span><span class="n">save</span><span class="p">({</span><span class="s2">"x"</span><span class="p">:</span> <span class="mi">10</span><span class="p">})</span><span class="w">
</span><span class="n">db</span><span class="o">.</span><span class="n">my_collection</span><span class="o">.</span><span class="n">save</span><span class="p">({</span><span class="s2">"x"</span><span class="p">:</span> <span class="mi">10</span><span class="p">,</span> <span class="s2">"y"</span><span class="p">:</span> <span class="s2">"good"</span><span class="p">})</span><span class="w">
</span><span class="k">for</span> <span class="n">item</span> <span class="ow">in</span> <span class="n">db</span><span class="o">.</span><span class="n">my_collection</span><span class="o">.</span><span class="n">find …</span></pre><p>Install everything you need:</p>
<pre class="code bash literal-block">
sudo<span class="w"> </span>apt-key<span class="w"> </span>adv<span class="w"> </span>--keyserver<span class="w"> </span>keyserver.ubuntu.com<span class="w"> </span>--recv<span class="w"> </span>7F0CEB10<span class="w">
</span>sudo<span class="w"> </span>nano<span class="w"> </span>/etc/apt/sources.list
</pre>
<p>Next, add a line to sources.list:</p>
<ul class="simple">
<li>on Ubuntu</li>
</ul>
<pre class="code literal-block">
deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen
</pre>
<ul class="simple">
<li>on Debian</li>
</ul>
<pre class="code literal-block">
deb http://downloads-distro.mongodb.org/repo/debian-sysvinit dist 10gen
</pre>
<pre class="code bash literal-block">
sudo<span class="w"> </span>apt-get<span class="w"> </span>update<span class="w">
</span>sudo<span class="w"> </span>apt-get<span class="w"> </span>install<span class="w"> </span>mongodb-10gen<span class="w">
</span>sudo<span class="w"> </span>apt-get<span class="w"> </span>install<span class="w"> </span>python-setuptools<span class="w">
</span>sudo<span class="w"> </span>easy_install<span class="w"> </span>pymongo
</pre>
<p>Next, test the connection:</p>
<pre class="code python literal-block">
<span class="kn">from</span> <span class="nn">pymongo.connection</span> <span class="kn">import</span> <span class="n">Connection</span><span class="w">
</span><span class="kn">from</span> <span class="nn">pymongo</span> <span class="kn">import</span> <span class="n">ASCENDING</span><span class="w">
</span><span class="n">connection</span> <span class="o">=</span> <span class="n">Connection</span><span class="p">(</span><span class="s2">"localhost"</span><span class="p">,</span> <span class="mi">27017</span><span class="p">)</span><span class="w">
</span><span class="n">db</span> <span class="o">=</span> <span class="n">connection</span><span class="o">.</span><span class="n">test</span><span class="w">
</span><span class="n">db</span><span class="o">.</span><span class="n">my_collection</span><span class="o">.</span><span class="n">save</span><span class="p">({</span><span class="s2">"x"</span><span class="p">:</span> <span class="mi">10</span><span class="p">})</span><span class="w">
</span><span class="n">db</span><span class="o">.</span><span class="n">my_collection</span><span class="o">.</span><span class="n">save</span><span class="p">({</span><span class="s2">"x"</span><span class="p">:</span> <span class="mi">10</span><span class="p">,</span> <span class="s2">"y"</span><span class="p">:</span> <span class="s2">"good"</span><span class="p">})</span><span class="w">
</span><span class="k">for</span> <span class="n">item</span> <span class="ow">in</span> <span class="n">db</span><span class="o">.</span><span class="n">my_collection</span><span class="o">.</span><span class="n">find</span><span class="p">()</span><span class="o">.</span><span class="n">sort</span><span class="p">(</span><span class="s2">"x"</span><span class="p">,</span> <span class="n">ASCENDING</span><span class="p">):</span><span class="w">
</span> <span class="nb">print</span> <span class="n">item</span><span class="p">[</span><span class="s2">"x"</span><span class="p">]</span><span class="w">
</span><span class="n">x</span> <span class="o">=</span> <span class="n">db</span><span class="o">.</span><span class="n">my_collection</span><span class="o">.</span><span class="n">find_one</span><span class="p">({</span><span class="s2">"y"</span><span class="p">:</span><span class="s2">"good"</span><span class="p">})</span><span class="w">
</span><span class="nb">print</span> <span class="n">x</span>
</pre>
Ruby on Rails 3 installation on Debian 6 Squeeze2011-04-05T22:18:00+02:002011-04-05T22:18:00+02:00admintag:berezovskyi.me,2011-04-05:/2011/04/ruby-on-rails-3-installation-on-debian-6-squeeze/<pre class="code bash literal-block">
apt-get<span class="w"> </span>install<span class="w"> </span>libsqlite3-dev<span class="w"> </span>curl<span class="w"> </span>git<span class="w"> </span>build-essential<span class="w"> </span>zlib1g-dev<span class="w"> </span>libssl-dev<span class="w">
</span>bash<span class="w"> </span><<<span class="w"> </span><span class="o">(</span><span class="w"> </span>curl<span class="w"> </span>http://rvm.beginrescueend.com/releases/rvm-install-head<span class="w"> </span><span class="o">)</span><span class="w">
</span><span class="k">if</span><span class="w"> </span><span class="o">[[</span><span class="w"> </span>-s<span class="w"> </span><span class="s2">"</span><span class="nv">$HOME</span><span class="s2">/.rvm/scripts/rvm"</span><span class="w"> </span><span class="o">]]</span><span class="w"> </span><span class="p">;</span><span class="w"> </span><span class="k">then</span><span class="w"> </span><span class="nb">source</span><span class="w"> </span><span class="s2">"</span><span class="nv">$HOME</span><span class="s2">/.rvm/scripts/rvm"</span><span class="w"> </span><span class="p">;</span><span class="w"> </span><span class="k">fi</span><span class="w">
</span>rvm<span class="w"> </span>install<span class="w"> </span><span class="m">1</span>.9.2<span class="w">
</span>rvm<span class="w"> </span>--default<span class="w"> </span>ruby-1.9.2<span class="w">
</span>gem<span class="w"> </span>install<span class="w"> </span>rails<span class="w">
</span>rails<span class="w"> </span>new<span class="w"> </span>testapp
</pre>
<p>в <em>$<span class="caps">HOME</span>/.profile</em></p>
<pre class="code bash literal-block">
<span class="nb">export</span><span class="w"> </span><span class="nv">PATH</span><span class="o">=</span><span class="nv">$PATH</span>:/var/lib/gems/1.8/bin
</pre>
<p>comment out sqlite deps in <cite>Gemfile</cite></p>
<p>then run rails server: <cite>rails s</cite></p>
<p><strong><span class="caps">UPD</span> 02.03.2012</strong> obsolete replacement:</p>
<pre class="code literal-block">
Package libreadline5-dev is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is …</pre><pre class="code bash literal-block">
apt-get<span class="w"> </span>install<span class="w"> </span>libsqlite3-dev<span class="w"> </span>curl<span class="w"> </span>git<span class="w"> </span>build-essential<span class="w"> </span>zlib1g-dev<span class="w"> </span>libssl-dev<span class="w">
</span>bash<span class="w"> </span><<<span class="w"> </span><span class="o">(</span><span class="w"> </span>curl<span class="w"> </span>http://rvm.beginrescueend.com/releases/rvm-install-head<span class="w"> </span><span class="o">)</span><span class="w">
</span><span class="k">if</span><span class="w"> </span><span class="o">[[</span><span class="w"> </span>-s<span class="w"> </span><span class="s2">"</span><span class="nv">$HOME</span><span class="s2">/.rvm/scripts/rvm"</span><span class="w"> </span><span class="o">]]</span><span class="w"> </span><span class="p">;</span><span class="w"> </span><span class="k">then</span><span class="w"> </span><span class="nb">source</span><span class="w"> </span><span class="s2">"</span><span class="nv">$HOME</span><span class="s2">/.rvm/scripts/rvm"</span><span class="w"> </span><span class="p">;</span><span class="w"> </span><span class="k">fi</span><span class="w">
</span>rvm<span class="w"> </span>install<span class="w"> </span><span class="m">1</span>.9.2<span class="w">
</span>rvm<span class="w"> </span>--default<span class="w"> </span>ruby-1.9.2<span class="w">
</span>gem<span class="w"> </span>install<span class="w"> </span>rails<span class="w">
</span>rails<span class="w"> </span>new<span class="w"> </span>testapp
</pre>
<p>в <em>$<span class="caps">HOME</span>/.profile</em></p>
<pre class="code bash literal-block">
<span class="nb">export</span><span class="w"> </span><span class="nv">PATH</span><span class="o">=</span><span class="nv">$PATH</span>:/var/lib/gems/1.8/bin
</pre>
<p>comment out sqlite deps in <cite>Gemfile</cite></p>
<p>then run rails server: <cite>rails s</cite></p>
<p><strong><span class="caps">UPD</span> 02.03.2012</strong> obsolete replacement:</p>
<pre class="code literal-block">
Package libreadline5-dev is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source
However the following packages replace it:
libreadline-gplv2-dev lib64readline-gplv2-dev
</pre>
<p>Important note for Ubuntu:</p>
<p><a class="reference external" href="https://rvm.beginrescueend.com/integration/gnome-terminal/">https://rvm.beginrescueend.com/integration/gnome-terminal/</a></p>
<pre class="code bash literal-block">
gem<span class="w"> </span>install<span class="w"> </span>therubyracer
</pre>
<pre class="code bash literal-block">
apt-get<span class="w"> </span>install<span class="w"> </span>libsqlite3-dev
</pre>
April Fools Prank on Squid2011-04-02T08:37:00+02:002011-04-02T08:37:00+02:00admintag:berezovskyi.me,2011-04-02:/2011/04/april-fools-prank-on-squid/<p><a class="reference external" href="https://help.ubuntu.com/community/Upside-Down-TernetHowTo">https://help.ubuntu.com/community/Upside-Down-TernetHowTo</a></p>
SSH passwordless login2011-03-19T09:22:00+01:002011-03-19T09:22:00+01:00admintag:berezovskyi.me,2011-03-19:/2011/03/ssh-passwordless-login/<p>On your machine</p>
<pre class="code bash literal-block">
<span class="nb">local</span><span class="w"> </span>$<span class="w"> </span>ssh-keygen<span class="w"> </span>-t<span class="w"> </span>rsa
</pre>
<p>do not enter any keys, just hit <cite>Enter</cite> <cite>Enter</cite>. Next,</p>
<pre class="code bash literal-block">
<span class="nb">local</span><span class="w"> </span>$<span class="w"> </span>scp<span class="w"> </span>~/.ssh/id_rsa.pub<span class="w">
</span>root@ipaddress:/root/.ssh/authorized_keys<span class="w">
</span><span class="nb">local</span><span class="w"> </span>$<span class="w"> </span>rm<span class="w"> </span>~/.ssh/id_rsa.pub
</pre>
<pre class="code bash literal-block">
<span class="nb">local</span><span class="w"> </span>$<span class="w"> </span>ssh<span class="w"> </span>root@ipaddress
</pre>
<p>that should guide you directly to the command prompt</p>
<p><strong><span class="caps">UPD</span> 20.04.2014:</strong> There is a great Linux program <cite>ssh-copy-id</cite> that does exactly everything mentioned above, but in one line instead!</p>
Django nginx Debian2011-03-18T21:54:00+01:002011-03-18T21:54:00+01:00admintag:berezovskyi.me,2011-03-18:/2011/03/django-nginx-debian/<dl class="docutils">
<dt>How to make a simple install of django onto small Debian-6 <span class="caps">VPS</span>.</dt>
<dd>I’ll stick with flup, which enables python to serve fastcgi and some</dd>
<dt>other protocols.</dt>
<dd>I use it in conjunction with nginx, which in turn is used save memory.</dd>
</dl>
<p>Literature:</p>
<dl class="docutils">
<dt><a class="reference external" href="http://library.linode.com/using-linux/administration-basics#system_diagnostics">http://library.linode.com/using-linux/administration-basics#system_diagnostics</a></dt>
<dd><a class="reference external" href="http://docs.djangoproject.com/en/dev/howto/deployment/fastcgi/">http://docs.djangoproject.com/en/dev/howto/deployment/fastcgi/</a></dd>
</dl>
<p><a class="reference external" href="http://www.mindinmotion.ru/post/django-postgresql-nginx-on-debian-server">http://www.mindinmotion.ru/post/django-postgresql-nginx-on-debian-server</a></p>
<div class="section" id="upgrade-the-system">
<h3>1 upgrade the system</h3>
<pre class="code bash literal-block">
apt-get<span class="w"> </span>upgrade
</pre>
</div>
<div class="section" id="install-required-dependencies">
<h3>2 install required dependencies</h3>
<pre class="code bash literal-block">
apt-get<span class="w"> </span>install<span class="w"> </span>nginx-light<span class="w"> </span>postgresql<span class="w"> </span>python-django<span class="w"> </span>python-psycopg2<span class="w"> </span>python-flup<span class="w"> </span>python-imaging
</pre>
</div>
<div class="section" id="configure-nginx">
<h3>3 configure nginx</h3>
<p>you may want to use emacs, vim, or nano. in case of last - you should …</p></div><dl class="docutils">
<dt>How to make a simple install of django onto small Debian-6 <span class="caps">VPS</span>.</dt>
<dd>I’ll stick with flup, which enables python to serve fastcgi and some</dd>
<dt>other protocols.</dt>
<dd>I use it in conjunction with nginx, which in turn is used save memory.</dd>
</dl>
<p>Literature:</p>
<dl class="docutils">
<dt><a class="reference external" href="http://library.linode.com/using-linux/administration-basics#system_diagnostics">http://library.linode.com/using-linux/administration-basics#system_diagnostics</a></dt>
<dd><a class="reference external" href="http://docs.djangoproject.com/en/dev/howto/deployment/fastcgi/">http://docs.djangoproject.com/en/dev/howto/deployment/fastcgi/</a></dd>
</dl>
<p><a class="reference external" href="http://www.mindinmotion.ru/post/django-postgresql-nginx-on-debian-server">http://www.mindinmotion.ru/post/django-postgresql-nginx-on-debian-server</a></p>
<div class="section" id="upgrade-the-system">
<h3>1 upgrade the system</h3>
<pre class="code bash literal-block">
apt-get<span class="w"> </span>upgrade
</pre>
</div>
<div class="section" id="install-required-dependencies">
<h3>2 install required dependencies</h3>
<pre class="code bash literal-block">
apt-get<span class="w"> </span>install<span class="w"> </span>nginx-light<span class="w"> </span>postgresql<span class="w"> </span>python-django<span class="w"> </span>python-psycopg2<span class="w"> </span>python-flup<span class="w"> </span>python-imaging
</pre>
</div>
<div class="section" id="configure-nginx">
<h3>3 configure nginx</h3>
<p>you may want to use emacs, vim, or nano. in case of last - you should read how to <a class="reference external" href="http://berezovskiy.me/2011/03/nano-configuration/">configure nano better</a>.</p>
<pre class="code literal-block">
server {
server_name report.loc; location / {
root /var/www/siteyour/www;
fastcgi_pass 127.0.0.1:3434;
include /usr/local/nginx/fastcgi.conf;
}
location /media {
alias /var/www/siteyour/www/uploads;
}
location /admin-media {
alias /usr/share/pyshared/django/contrib/admin/media;
}
}
//here you should notice the difference between nginx alias and root
// while testing, you may remove default entry and add a directive `listen 80` right
// after the opening server brace
</pre>
<p>and fastcgi.conf</p>
<pre class="code literal-block">
fastcgi_param PATH_INFO $fastcgi_script_name;
fastcgi_param REQUEST_METHOD $request_method;
fastcgi_param QUERY_STRING $query_string;
fastcgi_param CONTENT_TYPE $content_type;
fastcgi_param CONTENT_LENGTH $content_length;
fastcgi_pass_header Authorization;
fastcgi_intercept_errors off;
</pre>
</div>
<div class="section" id="postgres">
<h3>4 postgres</h3>
<pre class="code bash literal-block">
su<span class="w"> </span>postgres<span class="w">
</span>createdb<span class="w"> </span>yoursite<span class="w">
</span>createuser<span class="w"> </span>youruser<span class="w">
</span>nano<span class="w"> </span>/etc/postgresql/9.0/main/pg_hba.conf
</pre>
<p>modify one of the last lines to use `trust` instead of `ident`-based authentication</p>
<pre class="code bash literal-block">
/etc/init.d/postgresql<span class="w"> </span>restart
</pre>
</div>
<div class="section" id="troubles">
<h3>6 troubles</h3>
<p>you may issue a 403 error on your static files. that’s not getting
fixed with chmod 0777 ./*. You just have to</p>
<pre class="code bash literal-block">
groupadd<span class="w"> </span>site<span class="w">
</span>useradd<span class="w"> </span>-g<span class="w"> </span>site<span class="w"> </span>site<span class="w">
</span>chown<span class="w"> </span>site<span class="w"> </span>/path/to/yoursitedir
</pre>
<p>and change the first line of nginx.conf to</p>
<pre class="code literal-block">
user site site;
</pre>
</div>
<div class="section" id="run-python">
<h3>7 run python</h3>
<pre class="code bash literal-block">
manage.py<span class="w"> </span>runfcgi<span class="w"> </span><span class="nv">method</span><span class="o">=</span>threaded<span class="w"> </span><span class="nv">host</span><span class="o">=</span><span class="m">127</span>.0.0.1<span class="w"> </span><span class="nv">port</span><span class="o">=</span><span class="m">3434</span>
</pre>
</div>
<div class="section" id="restart-nginx">
<h3>8 restart nginx</h3>
<pre class="code bash literal-block">
/etc/init.d/nginx<span class="w"> </span>restart
</pre>
</div>
<div class="section" id="copy-your-files">
<h3>*9 copy your files</h3>
<pre class="code bash literal-block">
scp<span class="w"> </span>-r<span class="w"> </span>yorsitedir<span class="w"> </span>login@addr:path
</pre>
<p>this will create yourdir inside the path on the addr host</p>
<p>That’s it! Comment if you experience any troubles!</p>
<dl class="docutils">
<dt>** few more links on nginx:</dt>
<dd><a class="reference external" href="http://greenmice.info/ru/node/115">http://greenmice.info/ru/node/115</a>
<a class="reference external" href="http://greenmice.info/ru/node/116">http://greenmice.info/ru/node/116</a></dd>
</dl>
</div>
nano configuration2011-03-18T21:00:00+01:002011-03-18T21:00:00+01:00admintag:berezovskyi.me,2011-03-18:/2011/03/nano-configuration/<p>in ~/.nanorc you may add</p>
<pre class="literal-block">
set tabsize 3
set autoindent
</pre>
<p>if you want to simplify config files editing</p>
<p><span class="caps">P.S.</span> be careful with python and tabs:</p>
<ul class="simple">
<li><a class="reference external" href="http://www.secnetix.de/olli/Python/block_indentation.hawk">http://www.secnetix.de/olli/Python/block_indentation.hawk</a></li>
<li><a class="reference external" href="http://codeghar.wordpress.com/2008/11/18/python-tabs-or-spaces/">http://codeghar.wordpress.com/2008/11/18/python-tabs-or-spaces/</a></li>
<li><a class="reference external" href="http://www.cs.caltech.edu/courses/cs11/material/python/misc/python_style_guide.html">http://www.cs.caltech.edu/courses/cs11/material/python/misc/python_style_guide.html</a></li>
<li><a class="reference external" href="http://www.python.org/dev/peps/pep-0008/">http://www.python.org/dev/peps/pep-0008/</a></li>
<li><a class="reference external" href="http://pthree.org/2007/01/31/python-and-the-horrendous-tab-character/">http://pthree.org/2007/01/31/python-and-the-horrendous-tab-character/</a></li>
</ul>
How to capitalize a word in C#2011-03-10T13:44:00+01:002011-03-10T13:44:00+01:00admintag:berezovskyi.me,2011-03-10:/2011/03/how-to-capitalize-a-word-in-c/<p>This can be easily done via <cite>TextInfo</cite> class:</p>
<pre class="code csharp literal-block">
<span class="n">name</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">CultureInfo</span><span class="p">.</span><span class="n">CurrentCulture</span><span class="p">.</span><span class="n">TextInfo</span><span class="p">.</span><span class="n">ToTitleCase</span><span class="p">(</span><span class="n">name</span><span class="p">));</span>
</pre>
<p>Additionally, <span class="caps">LINQ</span> can greatly help iterating over a collection:</p>
<pre class="code csharp literal-block">
<span class="n">lst</span><span class="p">.</span><span class="n">ForEach</span><span class="p">(</span><span class="n">ci</span><span class="w"> </span><span class="o">=></span><span class="w"> </span><span class="n">ci</span><span class="p">.</span><span class="n">Name</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">CultureInfo</span><span class="p">.</span><span class="n">CurrentCulture</span><span class="p">.</span><span class="n">TextInfo</span><span class="p">.</span><span class="n">ToTitleCase</span><span class="p">(</span><span class="n">ci</span><span class="p">.</span><span class="n">Name</span><span class="p">));</span>
</pre>
Windows Server 2008 configuration2011-02-25T18:45:00+01:002011-02-25T18:45:00+01:00admintag:berezovskyi.me,2011-02-25:/2011/02/windows-server-2008-configuration/<p>You may want to disable auto-start of both <em>Initial Configuration</em> and
<em>Server manager</em> for some time, and then - to reapply them again.
The first one is extremely useful in case of desktop system env.</p>
<p>Open registry at <cite><span class="caps">HKLM</span>\Software\Microsoft\ServerManager</cite> and change the value
of <cite>DoNotOpenServerManagerAtLogon</cite> key from <cite>0</cite> to <cite>1</cite>.</p>
<p>To enable <em>Initial configuration</em>, run <cite>oobe</cite>.</p>
Having Mono on Ubuntu2011-02-21T19:25:00+01:002011-02-21T19:25:00+01:00admintag:berezovskyi.me,2011-02-21:/2011/02/having-mono-on-ubuntu/<p>Here is it, with .Net 3.5 support, awaiting 4.0, to be included in 2.10 built.</p>
<p>Oh, yes, try to use <a class="reference external" href="http://badgerports.org/">http://badgerports.org</a> for mono.</p>
<div class="figure">
<img alt="Mono with Anonymous + Linq + Debug" src="https://berezovskyi.me/static/2011/MonoDevelop.png" />
<p class="caption">Mono with Anonymous + Linq + Debugs</p>
</div>
SQLite in Java2011-02-21T18:27:00+01:002011-02-21T18:27:00+01:00admintag:berezovskyi.me,2011-02-21:/2011/02/sqlite-in-java/<p>Small and portable databases are great in sense of reliability,
portability and ease of use once created.</p>
<p>As many people use java, I’ve tried to investigate how easy is to create
a simple java&sqlite application. After the stackOverflow)) it took just
few minutes:</p>
<p>1. <a class="reference external" href="http://www.zentus.com/sqlitejdbc/">http://www.zentus.com/sqlitejdbc/</a> this jdbc driver has the sqlite
embedded for any platform already - great choice for everyone except enterprise.</p>
<ol class="arabic simple" start="2">
<li>Source is here - with some addions:</li>
</ol>
<pre class="code java literal-block">
<span class="kn">import</span><span class="w"> </span><span class="nn">java.sql.*</span><span class="p">;</span><span class="w">
</span><span class="kd">public</span><span class="w"> </span><span class="kd">class</span> <span class="nc">Main</span><span class="w"> </span><span class="p">{</span><span class="w">
</span><span class="cm">/**
* @param args
* @throws Exception
*/</span><span class="w">
</span><span class="kd">public</span><span class="w"> </span><span class="kd">static</span><span class="w"> </span><span class="kt">void</span><span class="w"> </span><span class="nf">main</span><span class="p">(</span><span class="n">String</span><span class="o">[]</span><span class="w"> </span><span class="n">args</span><span class="p">)</span><span class="w"> </span><span class="kd">throws</span><span class="w"> </span><span class="n">Exception</span><span class="w"> </span><span class="p">{</span><span class="w">
</span><span class="n">Class</span><span class="p">.</span><span class="na">forName</span><span class="p">(</span><span class="s">"org.sqlite.JDBC"</span><span class="p">);</span><span class="w">
</span><span class="n">Connection</span><span class="w"> </span><span class="n">conn</span><span class="w"> </span><span class="o">=</span><span class="w">
</span><span class="n">DriverManager …</span></pre><p>Small and portable databases are great in sense of reliability,
portability and ease of use once created.</p>
<p>As many people use java, I’ve tried to investigate how easy is to create
a simple java&sqlite application. After the stackOverflow)) it took just
few minutes:</p>
<p>1. <a class="reference external" href="http://www.zentus.com/sqlitejdbc/">http://www.zentus.com/sqlitejdbc/</a> this jdbc driver has the sqlite
embedded for any platform already - great choice for everyone except enterprise.</p>
<ol class="arabic simple" start="2">
<li>Source is here - with some addions:</li>
</ol>
<pre class="code java literal-block">
<span class="kn">import</span><span class="w"> </span><span class="nn">java.sql.*</span><span class="p">;</span><span class="w">
</span><span class="kd">public</span><span class="w"> </span><span class="kd">class</span> <span class="nc">Main</span><span class="w"> </span><span class="p">{</span><span class="w">
</span><span class="cm">/**
* @param args
* @throws Exception
*/</span><span class="w">
</span><span class="kd">public</span><span class="w"> </span><span class="kd">static</span><span class="w"> </span><span class="kt">void</span><span class="w"> </span><span class="nf">main</span><span class="p">(</span><span class="n">String</span><span class="o">[]</span><span class="w"> </span><span class="n">args</span><span class="p">)</span><span class="w"> </span><span class="kd">throws</span><span class="w"> </span><span class="n">Exception</span><span class="w"> </span><span class="p">{</span><span class="w">
</span><span class="n">Class</span><span class="p">.</span><span class="na">forName</span><span class="p">(</span><span class="s">"org.sqlite.JDBC"</span><span class="p">);</span><span class="w">
</span><span class="n">Connection</span><span class="w"> </span><span class="n">conn</span><span class="w"> </span><span class="o">=</span><span class="w">
</span><span class="n">DriverManager</span><span class="p">.</span><span class="na">getConnection</span><span class="p">(</span><span class="s">"jdbc:sqlite:sqliteBase.db"</span><span class="p">);</span><span class="w">
</span><span class="n">Statement</span><span class="w"> </span><span class="n">stat</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">conn</span><span class="p">.</span><span class="na">createStatement</span><span class="p">();</span><span class="w">
</span><span class="c1">//stat.executeUpdate("drop table if exists people;");</span><span class="w">
</span><span class="k">try</span><span class="w"> </span><span class="p">{</span><span class="w">
</span><span class="n">stat</span><span class="p">.</span><span class="na">executeUpdate</span><span class="p">(</span><span class="s">"create table people (name, occupation);"</span><span class="p">);</span><span class="w">
</span><span class="n">PreparedStatement</span><span class="w"> </span><span class="n">prep</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">conn</span><span class="p">.</span><span class="na">prepareStatement</span><span class="p">(</span><span class="w">
</span><span class="s">"insert into people values (?, ?);"</span><span class="p">);</span><span class="w">
</span><span class="n">prep</span><span class="p">.</span><span class="na">setString</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="s">"Gandhi"</span><span class="p">);</span><span class="w">
</span><span class="n">prep</span><span class="p">.</span><span class="na">setString</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span><span class="w"> </span><span class="s">"politics"</span><span class="p">);</span><span class="w">
</span><span class="n">prep</span><span class="p">.</span><span class="na">addBatch</span><span class="p">();</span><span class="w">
</span><span class="n">prep</span><span class="p">.</span><span class="na">setString</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="s">"Turing"</span><span class="p">);</span><span class="w">
</span><span class="n">prep</span><span class="p">.</span><span class="na">setString</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span><span class="w"> </span><span class="s">"computers"</span><span class="p">);</span><span class="w">
</span><span class="n">prep</span><span class="p">.</span><span class="na">addBatch</span><span class="p">();</span><span class="w">
</span><span class="n">prep</span><span class="p">.</span><span class="na">setString</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span><span class="w"> </span><span class="s">"Wittgenstein"</span><span class="p">);</span><span class="w">
</span><span class="n">prep</span><span class="p">.</span><span class="na">setString</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span><span class="w"> </span><span class="s">"smartypants"</span><span class="p">);</span><span class="w">
</span><span class="n">prep</span><span class="p">.</span><span class="na">addBatch</span><span class="p">();</span><span class="w">
</span><span class="n">conn</span><span class="p">.</span><span class="na">setAutoCommit</span><span class="p">(</span><span class="kc">false</span><span class="p">);</span><span class="w">
</span><span class="n">prep</span><span class="p">.</span><span class="na">executeBatch</span><span class="p">();</span><span class="w">
</span><span class="n">conn</span><span class="p">.</span><span class="na">setAutoCommit</span><span class="p">(</span><span class="kc">true</span><span class="p">);</span><span class="w">
</span><span class="p">}</span><span class="w"> </span><span class="k">catch</span><span class="w"> </span><span class="p">(</span><span class="n">Exception</span><span class="w"> </span><span class="n">e</span><span class="p">)</span><span class="w"> </span><span class="p">{</span><span class="w">
</span><span class="c1">// table already created</span><span class="w">
</span><span class="c1">//TODO: handle that better</span><span class="w">
</span><span class="p">}</span><span class="w">
</span><span class="n">ResultSet</span><span class="w"> </span><span class="n">rs</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">stat</span><span class="p">.</span><span class="na">executeQuery</span><span class="p">(</span><span class="s">"select * from people where occupation like \"poli%\";"</span><span class="p">);</span><span class="w">
</span><span class="k">while</span><span class="w"> </span><span class="p">(</span><span class="n">rs</span><span class="p">.</span><span class="na">next</span><span class="p">())</span><span class="w"> </span><span class="p">{</span><span class="w">
</span><span class="n">System</span><span class="p">.</span><span class="na">out</span><span class="p">.</span><span class="na">print</span><span class="p">(</span><span class="s">"name = "</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="n">rs</span><span class="p">.</span><span class="na">getString</span><span class="p">(</span><span class="s">"name"</span><span class="p">));</span><span class="w">
</span><span class="n">System</span><span class="p">.</span><span class="na">out</span><span class="p">.</span><span class="na">println</span><span class="p">(</span><span class="s">";\tjob = "</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="n">rs</span><span class="p">.</span><span class="na">getString</span><span class="p">(</span><span class="s">"occupation"</span><span class="p">));</span><span class="w">
</span><span class="p">}</span><span class="w">
</span><span class="n">rs</span><span class="p">.</span><span class="na">close</span><span class="p">();</span><span class="w">
</span><span class="n">conn</span><span class="p">.</span><span class="na">close</span><span class="p">();</span><span class="w">
</span><span class="p">}</span><span class="w">
</span><span class="p">}</span>
</pre>
<p>To see what are you doing, use this plugin:
<a class="reference external" href="https://addons.mozilla.org/en-US/firefox/addon/sqlite-manager/">https://addons.mozilla.org/en-<span class="caps">US</span>/firefox/addon/sqlite-manager/</a></p>
<p>Good luck!</p>
MSI Installer couldn’t start x642011-02-15T07:12:00+01:002011-02-15T07:12:00+01:00admintag:berezovskyi.me,2011-02-15:/2011/02/msi-installer-couldnt-start-x64/<p>Hi there,</p>
<p>For the past month, I have been trying to install the 64bit edition of
Itunes onto my mom’s new computer. She has Vista Home premium 64bit
edition.
Everytime we tried to install itunes we would receive this error:</p>
<p><span class="dquo">“</span>The Windows installer service could not be accessed. This can occur if
you are running windows in safe mode, or if windows installer is not
correctly installed. Contact your support personnel for assistance”</p>
<p>Actually, everytime we tried to install any 64bit program we would
receive this same error. I searched high and low and tried countless
solutions.
Unregistering and …</p><p>Hi there,</p>
<p>For the past month, I have been trying to install the 64bit edition of
Itunes onto my mom’s new computer. She has Vista Home premium 64bit
edition.
Everytime we tried to install itunes we would receive this error:</p>
<p><span class="dquo">“</span>The Windows installer service could not be accessed. This can occur if
you are running windows in safe mode, or if windows installer is not
correctly installed. Contact your support personnel for assistance”</p>
<p>Actually, everytime we tried to install any 64bit program we would
receive this same error. I searched high and low and tried countless
solutions.
Unregistering and reregistering the installer service, stopping and
restarting, using the Windows installer cleanup utility, etc…none of
these things helped.</p>
<p>Today I came across a blog “Think#Knowledge Blog” that <span class="caps">SOLVED</span> my problem.</p>
<p>This is the solution that worked for me:</p>
<p>Go to this registry key:</p>
<p><cite>HKEY_LOCAL_MACHINE\<span class="caps">SYSTEM</span>\CurrentControlSet\Services\MSIServer</cite></p>
<p>Look for</p>
<p><cite><span class="caps">WOW64</span></cite> and it’s value.
Is it <cite>0x00000001 (1)</cite> ?</p>
<p>This value tells Windows Installer only to deal with 32-bit installers
and to return you an error whenever you try to install something that is
64-bit. To fix it, just set the value to 0. So you will see in your editor:</p>
<p><cite><span class="caps">WOW64</span> REG_DWORD 0x00000000 (0)</cite></p>
<p>After changing the value to zero, restart your Windows Installer Service
by using services.msc or reboot.</p>
<p>This simple solution of changing the 1 to a 0 allowed me to finally
install Itunes on Vista 64.</p>
<p>I hope this helps someone else who is having the same problem as this
solution took me over a month to find.</p>
Network discovery on a Windows Server 2008 R22011-01-29T21:28:00+01:002011-01-29T21:28:00+01:00admintag:berezovskyi.me,2011-01-29:/2011/01/network-discovery-on-a-windows-server-2008-r2/<p>In order to enable the Network Discovery on a domain make sure the
following services are enabled and running:</p>
<ol class="arabic simple">
<li><span class="caps">DNS</span> Client</li>
<li>Function Discovery Resource Publication</li>
<li><span class="caps">SSDP</span> Discovery</li>
<li>UPnP Discovery</li>
</ol>
<p>What is network discovery?
<a class="reference external" href="http://windows.microsoft.com/en-US/windows7/What-is-network-discovery">http://windows.microsoft.com/en-<span class="caps">US</span>/windows7/What-is-network-discovery</a></p>
<p>Network discovery requires that the <span class="caps">DNS</span> Client, Function Discovery
Resource Publication, <span class="caps">SSDP</span> Discovery, and UPnP Device Host services are
started, that network discovery is allowed to communicate through
Windows Firewall, and that other firewalls are not interfering with
network discovery. If some but not all of these are true, the network
discovery state will be shown as Custom [Microsoft …</p><p>In order to enable the Network Discovery on a domain make sure the
following services are enabled and running:</p>
<ol class="arabic simple">
<li><span class="caps">DNS</span> Client</li>
<li>Function Discovery Resource Publication</li>
<li><span class="caps">SSDP</span> Discovery</li>
<li>UPnP Discovery</li>
</ol>
<p>What is network discovery?
<a class="reference external" href="http://windows.microsoft.com/en-US/windows7/What-is-network-discovery">http://windows.microsoft.com/en-<span class="caps">US</span>/windows7/What-is-network-discovery</a></p>
<p>Network discovery requires that the <span class="caps">DNS</span> Client, Function Discovery
Resource Publication, <span class="caps">SSDP</span> Discovery, and UPnP Device Host services are
started, that network discovery is allowed to communicate through
Windows Firewall, and that other firewalls are not interfering with
network discovery. If some but not all of these are true, the network
discovery state will be shown as Custom [Microsoft]</p>