<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
  <title type="text">ForeverYoung's blog</title>
  <id>/atom/?lang=en</id>
  <updated>2013-07-24T21:44:19Z</updated>
  <link href="/?lang=en" />
  <link href="http://blog.f-y.name/atom/?lang=en" rel="self" />
  <author>
    <name>Anton Novosyolov</name>
  </author>
  <subtitle type="text">Linux, programming, etc.</subtitle>
  <generator>blohg</generator>
  <entry>
    <title type="text">Speeding up films and podcasts, improved</title>
    <id>/post/stretch-improved/?lang=en</id>
    <updated>2013-07-24T21:44:19Z</updated>
    <published>2013-07-24T21:44:19Z</published>
    <link href="http://blog.f-y.name/post/stretch-improved/?lang=en" />
    <author>
      <name>Anton Novosyolov</name>
      <email>anton.novosyolov@gmail.com</email>
    </author>
    <summary type="html">&lt;!-- tags: bash,linux --&gt;
&lt;p&gt;Improved version of &lt;a class=&quot;reference external&quot; href=&quot;/post/stretch-linux/?lang=en&quot;&gt;speedup script&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Fancy coloring, progress in percents, command line options, default speedup rate is taken from a file &amp;quot;SPEEDUP&amp;quot;, handling Ctrl-C.&lt;/p&gt;
</summary>
    <content type="html">&lt;!-- tags: bash,linux --&gt;
&lt;p&gt;Improved version of &lt;a class=&quot;reference external&quot; href=&quot;/post/stretch-linux/?lang=en&quot;&gt;speedup script&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Fancy coloring, progress in percents, command line options, default speedup rate is taken from a file &amp;quot;SPEEDUP&amp;quot;, handling Ctrl-C.&lt;/p&gt;
&lt;!-- read_more --&gt;
&lt;p&gt;mp3-acceleration script:&lt;/p&gt;

&lt;pre class=&quot;brush: bash&quot;&gt;
#!/bin/bash
dir=`dirname $(realpath $0)`
DEFAULT_SPEEDUP=`cat $dir/SPEEDUP 2&gt; /dev/null`
DEFAULT_SPEEDUP=${DEFAULT_SPEEDUP:-+45}

speedup=${1:-${DEFAULT_SPEEDUP}}
echo &quot;Using tempo change ${speedup}%&quot;
mkdir /tmp/result 2&gt;/dev/null

trap interrupt INT

function interrupt() {
    echo -e &quot;\nDeleting unfinished $name&quot;
    rm &quot;result/$name&quot; 2&gt; /dev/null
    exit 1
}

count=`ls original/*.mp3 2&gt;/dev/null | wc -l`
if [ ! $count -gt 0 ]; then
    echo &quot;No input files&quot;
    exit 0
fi

i=1
for f in original/*.mp3; do
    name=`basename &quot;$f&quot;`
    if [ ! -f &quot;result/$name&quot; ]; then
        printf &quot;\E[32m%3.0f%%\E[0m Processing %s&quot; &quot;$(($i*100/$count)).&quot; &quot;$name&quot;
        lame --quiet --decode &quot;$f&quot; - | soundstretch stdin stdout -tempo=$speedup -speech 2&gt;/dev/null | lame --quiet -m a -cbr -b 64 --resample 24  - &quot;result/$name&quot;
        echo -e &quot;\E[32m Done\E[0m&quot;
    else
        printf &quot;\E[32m%3.0f%%\E[0m Skipping %s\n&quot; &quot;$(($i*100/$count))&quot; &quot;$name&quot;
    fi
    i=$((i+1))
done
&lt;/pre&gt;

&lt;p&gt;mp4-sound-extraction and acceleration script:&lt;/p&gt;

&lt;pre class=&quot;brush: bash&quot;&gt;
#!/bin/bash
dir=`dirname $(realpath $0)`
DEFAULT_SPEEDUP=`cat $dir/SPEEDUP 2&gt; /dev/null`
DEFAULT_SPEEDUP=${DEFAULT_SPEEDUP:-+45}

DEFAULT_SOURCE=original

trap interrupt INT

function interrupt() {
    echo -e &quot;\nDeleting unfinished $name.mp3&quot;
    rm &quot;result/$name.mp3&quot; 2&gt; /dev/null
    rm /tmp/temp.wav 2&gt; /dev/null
    rm /tmp/temp.mp4a 2&gt; /dev/null
    exit 1
}

original=$1
if [ ! -d &quot;$original&quot; ]; then
    speedup=${original:-${DEFAULT_SPEEDUP}}
    original=${2:-$DEFAULT_SOURCE}
else
    speedup=${2:-${DEFAULT_SPEEDUP}}
fi

if [ &quot;$speedup&quot; == &quot;0&quot; ]; then
    echo &quot;Only extracting&quot;
else
    echo &quot;Using tempo change ${speedup}%&quot;
fi
echo &quot;Using source directory ${original}&quot;

mkdir /tmp/result 2&gt;/dev/null

count=`ls $original/*.mp4 2&gt;/dev/null | wc -l`
if [ ! $count -gt 0 ]; then
    echo &quot;No input files&quot;
    exit 0
fi

i=1
for f in $original/*.mp4; do
    name=`basename &quot;$f&quot; .mp4`
    if [ ! -f &quot;result/$name.mp3&quot; ]; then
        printf &quot;\E[32m%3.0f%%\E[0m Processing %s. \E[32mExtracting...\E[0m&quot; &quot;$(($i*100/$count))&quot; &quot;$name.mp4&quot;
        mplayer &quot;$f&quot; -dumpaudio -dumpfile /tmp/temp.mp4a &gt; /dev/null 2&gt;&amp;1
        faad /tmp/temp.mp4a &gt; /dev/null 2&gt;&amp;1
        if [ &quot;$speedup&quot; == &quot;0&quot; ]; then
            lame --quiet -m a -cbr -b 64 --resample 24 /tmp/temp.wav &quot;result/${name}.mp3&quot;
            echo -e &quot;\b\b\b\b\b\b\b\b\b\b\b\b\bExtracting. \E[32mDone\E[0m&quot;
        else
            echo -en &quot;\b\b\b\b\b\b\b\b\b\b\b\b\bExtracting. \E[32mSpeeding up...\E[0m&quot;
            soundstretch /tmp/temp.wav stdout -tempo=$speedup -speech 2&gt;/dev/null | lame --quiet -m a -cbr -b 64 --resample 24  - &quot;result/${name}.mp3&quot;
            echo -e &quot;\b\b\b\b\b\b\b\b\b\b\b\b\b\bSpeeding up. \E[32mDone\E[0m&quot;
        fi
        rm /tmp/temp.wav 2&gt; /dev/null
        rm /tmp/temp.mp4a 2&gt; /dev/null
    else
        printf &quot;\E[32m%3.0f%%\E[0m Skipping %s\n&quot; &quot;$(($i*100/$count))&quot; &quot;$name.mp4&quot;
    fi
    i=$((i+1))
done
&lt;/pre&gt;

&lt;script type=&quot;text/javascript&quot; src=&quot;http://alexgorbatchev.com/pub/sh/current/scripts/shCore.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushBash.js&quot;&gt;&lt;/script&gt;
&lt;link type=&quot;text/css&quot; rel=&quot;stylesheet&quot; href=&quot;http://alexgorbatchev.com/pub/sh/current/styles/shCoreDefault.css&quot;/&gt;
&lt;script type=&quot;text/javascript&quot;&gt;SyntaxHighlighter.defaults.toolbar=false; SyntaxHighlighter.all();&lt;/script&gt;</content>
  </entry>
  <entry>
    <title type="text">Copy podcasts back after speeding up</title>
    <id>/post/stretch-copy/?lang=en</id>
    <updated>2013-07-08T06:10:31Z</updated>
    <published>2013-07-08T06:10:31Z</published>
    <link href="http://blog.f-y.name/post/stretch-copy/?lang=en" />
    <author>
      <name>Anton Novosyolov</name>
      <email>anton.novosyolov@gmail.com</email>
    </author>
    <summary type="html">&lt;!-- tags: bash,linux --&gt;
&lt;p&gt;Script for moving processed podcasts back to player:&lt;/p&gt;
</summary>
    <content type="html">&lt;!-- tags: bash,linux --&gt;
&lt;p&gt;Script for moving processed podcasts back to player:&lt;/p&gt;
&lt;!-- read_more --&gt;

&lt;pre class=&quot;brush: bash&quot;&gt;
#!/bin/bash
for f in result/*; do
    base=`basename &quot;$f&quot;`
    if [ -L &quot;original/$base&quot; ]; then
        orig=`readlink -f &quot;original/$base&quot;`
        echo &quot;Moving $base&quot;
        mv &quot;$f&quot; &quot;$orig&quot;
        rm &quot;original/$base&quot;
    else
        echo -e &quot;\E[33mSkipping $base, no original file or not a symlink\E[0m&quot;
    fi
done
&lt;/pre&gt;

&lt;p&gt;&lt;strong&gt;UPD&lt;/strong&gt;: Added checking for existance of original file and it's a symlink. Added progress display.&lt;/p&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;http://alexgorbatchev.com/pub/sh/current/scripts/shCore.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushBash.js&quot;&gt;&lt;/script&gt;
&lt;link type=&quot;text/css&quot; rel=&quot;stylesheet&quot; href=&quot;http://alexgorbatchev.com/pub/sh/current/styles/shCoreDefault.css&quot;/&gt;
&lt;script type=&quot;text/javascript&quot;&gt;SyntaxHighlighter.defaults.toolbar=false; SyntaxHighlighter.all();&lt;/script&gt;</content>
  </entry>
  <entry>
    <title type="text">Speeding up films and podcasts (Linux)</title>
    <id>/post/stretch-linux/?lang=en</id>
    <updated>2013-06-14T21:22:42Z</updated>
    <published>2013-06-14T21:22:42Z</published>
    <link href="http://blog.f-y.name/post/stretch-linux/?lang=en" />
    <author>
      <name>Anton Novosyolov</name>
      <email>anton.novosyolov@gmail.com</email>
    </author>
    <summary type="html">&lt;!-- tags: bash,linux --&gt;
&lt;p&gt;Here is version of my &lt;a class=&quot;reference external&quot; href=&quot;/post/stretch/?lang=en&quot;&gt;speedup script&lt;/a&gt; for linux:&lt;/p&gt;
</summary>
    <content type="html">&lt;!-- tags: bash,linux --&gt;
&lt;p&gt;Here is version of my &lt;a class=&quot;reference external&quot; href=&quot;/post/stretch/?lang=en&quot;&gt;speedup script&lt;/a&gt; for linux:&lt;/p&gt;
&lt;!-- read_more --&gt;
&lt;p&gt;mp3-acceleration script:&lt;/p&gt;

&lt;pre class=&quot;brush: bash&quot;&gt;
mkdir /tmp/result
for f in original/*.mp3; do
    name=`basename &quot;$f&quot;`
    lame --quiet --decode &quot;$f&quot; - | soundstretch stdin stdout -tempo=+45 -speech | lame --quiet -m a -cbr -b 64 --resample 24  - &quot;result/$name&quot;
done
&lt;/pre&gt;

&lt;p&gt;mp4-sound-extraction and acceleration script:&lt;/p&gt;

&lt;pre class=&quot;brush: bash&quot;&gt;
mkdir /tmp/result
for f in original_flash/*.mp4; do
    name=`basename &quot;$f&quot; .mp4`
    mplayer &quot;$f&quot; -dumpaudio -dumpfile /tmp/temp.mp4a
    faad /tmp/temp.mp4a
    soundstretch /tmp/temp.wav stdout -tempo=+45 -speech | lame --quiet -m a -cbr -b 64 --resample 24  - &quot;result/${name}.mp3&quot;
    rm /tmp/temp.wav
    rm /tmp/temp.mp4a
done
&lt;/pre&gt;

&lt;p&gt;For SSD life prolongation, I use /tmp in-memory disk for temporary and result files.
I place softlinks to original mp3 files into 'original' directory, and 'original_flash' is a link to the usual place of mp4 files.&lt;/p&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;http://alexgorbatchev.com/pub/sh/current/scripts/shCore.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushBash.js&quot;&gt;&lt;/script&gt;
&lt;link type=&quot;text/css&quot; rel=&quot;stylesheet&quot; href=&quot;http://alexgorbatchev.com/pub/sh/current/styles/shCoreDefault.css&quot;/&gt;
&lt;script type=&quot;text/javascript&quot;&gt;SyntaxHighlighter.defaults.toolbar=false; SyntaxHighlighter.all();&lt;/script&gt;</content>
  </entry>
  <entry>
    <title type="text">Useful cli remote control for N900 KMplayer</title>
    <id>/post/mplayer-remote/?lang=en</id>
    <updated>2012-09-18T18:04:12Z</updated>
    <published>2012-09-18T18:04:12Z</published>
    <link href="http://blog.f-y.name/post/mplayer-remote/?lang=en" />
    <author>
      <name>Anton Novosyolov</name>
      <email>anton.novosyolov@gmail.com</email>
    </author>
    <summary type="html">&lt;!-- tags:Nokia N900,mplayer --&gt;
&lt;p&gt;Works only if you use mplayer backend.&lt;/p&gt;
</summary>
    <content type="html">&lt;!-- tags:Nokia N900,mplayer --&gt;
&lt;p&gt;Works only if you use mplayer backend.&lt;/p&gt;
&lt;!-- read_more --&gt;
&lt;p&gt;On N900 create script &lt;em&gt;/home/user/.bin/mplayer-control.sh&lt;/em&gt;:&lt;/p&gt;

&lt;pre class=&quot;brush: bash&quot;&gt;
#!/bin/bash
if [ &quot;`pidof kmplayer`&quot; == &quot;&quot; ]; then
    exit
fi

out=/proc/`pidof mplayer`/fd/0

echo &quot;Choose:
  p or space or enter: toggle play/pause
  &amp;lt;: seek backward 5 seconds
  &gt;: seek forward 5 seconds
  [: seek backward 30 seconds
  ]: seek forward 30 seconds
  {: seek backward 5 minutes
  }: seek forward 5 minutes
  9: volume down
  0: volume up
  o: toggle osd mode
  v: toggle subtitle visibility
  q: quit this program&quot;
while true; do
    read -n 1 -s  ans
    case $ans in
        &quot;&quot; ) echo &quot;pause&quot; &gt; $out ;;
        &quot; &quot; ) echo &quot;pause&quot; &gt; $out ;;
        &quot;p&quot; ) echo &quot;pause&quot; &gt; $out ;;
        &quot;&amp;lt;&quot; ) echo &quot;seek -5&quot; &gt; $out ;;
        &quot;&gt;&quot; ) echo &quot;seek +5&quot; &gt; $out ;;
        &quot;[&quot; ) echo &quot;seek -30&quot; &gt; $out ;;
        &quot;]&quot; ) echo &quot;seek +30&quot; &gt; $out ;;
        &quot;{&quot; ) echo &quot;seek -300&quot; &gt; $out ;;
        &quot;}&quot; ) echo &quot;seek +300&quot; &gt; $out ;;
        &quot;9&quot; ) echo &quot;volume -1&quot; &gt; $out ;;
        &quot;0&quot; ) echo &quot;volume +2&quot; &gt; $out ;;
        &quot;o&quot; ) echo &quot;osd&quot; &gt; $out ;;
        &quot;v&quot; ) echo &quot;sub_visibility&quot; &gt; $out ;;
        &quot;q&quot; ) exit ;;
    esac
done
&lt;/pre&gt;

&lt;p&gt;On desktop add to &lt;em&gt;.bashrc&lt;/em&gt;:&lt;/p&gt;

&lt;pre class=&quot;brush: bash&quot;&gt;
alias mplco=&quot;ssh n900 /home/user/.bin/mplayer-control.sh&quot;
&lt;/pre&gt;

&lt;script type=&quot;text/javascript&quot; src=&quot;http://alexgorbatchev.com/pub/sh/current/scripts/shCore.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushBash.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPlain.js&quot;&gt;&lt;/script&gt;
&lt;link type=&quot;text/css&quot; rel=&quot;stylesheet&quot; href=&quot;http://alexgorbatchev.com/pub/sh/current/styles/shCoreDefault.css&quot;/&gt;
&lt;script type=&quot;text/javascript&quot;&gt;SyntaxHighlighter.defaults.toolbar=false; SyntaxHighlighter.all();&lt;/script&gt;</content>
  </entry>
  <entry>
    <title type="text">Moving to Nginx and Gunicorn</title>
    <id>/post/nginx-gunicorn/?lang=en</id>
    <updated>2012-02-15T06:18:37Z</updated>
    <published>2012-02-15T06:18:37Z</published>
    <link href="http://blog.f-y.name/post/nginx-gunicorn/?lang=en" />
    <author>
      <name>Anton Novosyolov</name>
      <email>anton.novosyolov@gmail.com</email>
    </author>
    <summary type="html">&lt;!-- tags: nginx,gunicorn,blohg,selectel,cloud,hosting,moving --&gt;
&lt;p&gt;&lt;a class=&quot;reference external&quot; href=&quot;http://translate.google.com/translate?sl=ru&amp;amp;tl=en&amp;amp;js=n&amp;amp;prev=_t&amp;amp;hl=ru&amp;amp;ie=UTF-8&amp;amp;layout=2&amp;amp;eotf=1&amp;amp;u=http%3A%2F%2Fselectel.ru%2Fnews%2Fresumption-and-updating-of-cloud-server-service%2F&amp;amp;act=url&quot;&gt;Selectel resumed cloud server service selectel&lt;/a&gt;,
so I decided to create new server in new server pool and also move from lighttpd to nginx.&lt;/p&gt;
</summary>
    <content type="html">&lt;!-- tags: nginx,gunicorn,blohg,selectel,cloud,hosting,moving --&gt;
&lt;p&gt;&lt;a class=&quot;reference external&quot; href=&quot;http://translate.google.com/translate?sl=ru&amp;amp;tl=en&amp;amp;js=n&amp;amp;prev=_t&amp;amp;hl=ru&amp;amp;ie=UTF-8&amp;amp;layout=2&amp;amp;eotf=1&amp;amp;u=http%3A%2F%2Fselectel.ru%2Fnews%2Fresumption-and-updating-of-cloud-server-service%2F&amp;amp;act=url&quot;&gt;Selectel resumed cloud server service selectel&lt;/a&gt;,
so I decided to create new server in new server pool and also move from lighttpd to nginx.&lt;/p&gt;
&lt;!-- read_more --&gt;
&lt;p&gt;Server is running on Debian Squeeze Mini.&lt;/p&gt;
&lt;div class=&quot;section&quot; id=&quot;installation&quot;&gt;
&lt;h3&gt;Installation&lt;/h3&gt;
&lt;p&gt;Nginx is installed from squeeze-backports repository.&lt;/p&gt;
&lt;p&gt;From root:&lt;/p&gt;

&lt;pre class=&quot;brush: bash&quot;&gt;
echo &quot;# squeeze-backports&quot; &gt;&gt; /etc/apt/sources.list
echo &quot;deb http://backports.debian.org/debian-backports squeeze-backports main&quot; &gt;&gt; /etc/apt/sources.list
apt-get update
apt-get -t squeeze-backports install nginx
&lt;/pre&gt;

&lt;p&gt;For controlling server processes install &lt;a class=&quot;reference external&quot; href=&quot;http://supervisord.org&quot;&gt;supervisord&lt;/a&gt;:&lt;/p&gt;

&lt;pre class=&quot;brush: bash&quot;&gt;
apt-get install supervisor
&lt;/pre&gt;

&lt;p&gt;Install virtualenv and mercurial:&lt;/p&gt;

&lt;pre class=&quot;brush: bash&quot;&gt;
apt-get install virtualenv
apt-get install mercurial
&lt;/pre&gt;

&lt;/div&gt;
&lt;div class=&quot;section&quot; id=&quot;creating-user-and-setting-up-virtualenv&quot;&gt;
&lt;h3&gt;Creating user and setting up virtualenv&lt;/h3&gt;

&lt;pre class=&quot;brush: bash&quot;&gt;
useradd -m -s /bin/bash blog
su blog
&lt;/pre&gt;

&lt;p&gt;From blog user:&lt;/p&gt;

&lt;pre class=&quot;brush: bash&quot;&gt;
cd ~
virtualenv env
cd env
. bin/activate
&lt;/pre&gt;

&lt;p&gt;Under env:&lt;/p&gt;

&lt;pre class=&quot;brush: bash&quot;&gt;
easy_install pip
pip install gunicorn
&lt;/pre&gt;

&lt;/div&gt;
&lt;div class=&quot;section&quot; id=&quot;install-blohg&quot;&gt;
&lt;h3&gt;Install blohg&lt;/h3&gt;
&lt;p&gt;I use customized version, so I get it from my &lt;a class=&quot;reference external&quot; href=&quot;https://bitbucket.org/ForeverYoung/blohg&quot;&gt;repository&lt;/a&gt; (under env):&lt;/p&gt;

&lt;pre class=&quot;brush: bash&quot;&gt;
cd ~
hg clone https://bitbucket.org/ForeverYoung/blohg
cd blohg
python setup.py install
&lt;/pre&gt;

&lt;p&gt;If there is an error while installing, install gcc and python-dev (under root):&lt;/p&gt;

&lt;pre class=&quot;brush: bash&quot;&gt;
apt-get install gcc
apt-get install python-dev
&lt;/pre&gt;

&lt;p&gt;For stock version (under env):&lt;/p&gt;

&lt;pre class=&quot;brush: bash&quot;&gt;
pip install blohg
&lt;/pre&gt;

&lt;/div&gt;
&lt;div class=&quot;section&quot; id=&quot;configuring-gunicorn&quot;&gt;
&lt;h3&gt;Configuring gunicorn&lt;/h3&gt;
&lt;p&gt;Create &lt;em&gt;blog_app.py&lt;/em&gt; in &lt;em&gt;~blog&lt;/em&gt;:&lt;/p&gt;

&lt;pre class=&quot;brush: python&quot;&gt;
#!/usr/bin/python
from blohg import create_app

app = create_app(&quot;/home/blog/blog&quot;)
&lt;/pre&gt;

&lt;p&gt;Clone your blog to server (as &lt;a class=&quot;reference external&quot; href=&quot;http://docs.blohg.org/deploy/#using-a-wsgi-app&quot;&gt;here&lt;/a&gt;):&lt;/p&gt;

&lt;pre class=&quot;brush: bash&quot;&gt;
hg clone my_blohg ssh://blog@yourdomain.tld/home/blog/blog/
&lt;/pre&gt;

&lt;p&gt;Create &lt;em&gt;gunicorn.conf.py&lt;/em&gt; in &lt;em&gt;~blog&lt;/em&gt;:&lt;/p&gt;

&lt;pre class=&quot;brush: python&quot;&gt;
import multiprocessing

workers = multiprocessing.cpu_count() * 2 + 1

bind = &quot;unix:/home/blog/blog.socket&quot;
pidfile = &quot;/home/blog/blog.pid&quot;
logfile = &quot;/home/blog/logs/gunicorn.log&quot;
loglevel = &quot;info&quot;
proc_name = &quot;blog&quot;
user = &quot;www-data&quot;
group = &quot;www-data&quot;
&lt;/pre&gt;

&lt;/div&gt;
&lt;div class=&quot;section&quot; id=&quot;configuring-supervisor&quot;&gt;
&lt;h3&gt;Configuring supervisor&lt;/h3&gt;
&lt;p&gt;Create &lt;em&gt;/etc/supervisor/conf.d/blog.conf&lt;/em&gt;:&lt;/p&gt;

&lt;pre class=&quot;brush: plain&quot;&gt;
[program:blog]
command = /home/blog/env/bin/gunicorn blog_app:app -c /home/blog/gunicorn.conf.py
directory = /home/blog/
autostart = true
autorestart = true
redirect_stderr = true
daemon = false
debug = false
logfile = /home/blog/logs/supervisor.log
loglevel = &quot;info&quot;
user = &quot;www-data&quot;
&lt;/pre&gt;

&lt;p&gt;Start supervisor:&lt;/p&gt;

&lt;pre class=&quot;brush: bash&quot;&gt;
/etc/init.d/supervisor start
&lt;/pre&gt;

&lt;/div&gt;
&lt;div class=&quot;section&quot; id=&quot;configuring-nginx&quot;&gt;
&lt;h3&gt;Configuring nginx&lt;/h3&gt;
&lt;p&gt;Create &lt;em&gt;/etc/nginx/sites-available/blog&lt;/em&gt;:&lt;/p&gt;

&lt;pre class=&quot;brush: plain&quot;&gt;
server {
        listen 80;

        server_name yourdomain.tld;
        access_log /home/blog/logs/nginx_access.log;
        error_log /home/blog/logs/nginx_error.log;

        location / {
            proxy_pass http://unix:/home/blog/blog.socket;
            include proxy_params;
        }
}
&lt;/pre&gt;

&lt;p&gt;Create link in &lt;em&gt;sites-enabled&lt;/em&gt;:&lt;/p&gt;

&lt;pre class=&quot;brush: bash&quot;&gt;
cd /etc/nginx/sites-enabled
ln -s ../sites-available/blog blog
&lt;/pre&gt;

&lt;p&gt;Start nginx:&lt;/p&gt;

&lt;pre class=&quot;brush: bash&quot;&gt;
/etc/init.d/nginx start
&lt;/pre&gt;

&lt;p&gt;&lt;em&gt;That's all!&lt;/em&gt;&lt;/p&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;http://alexgorbatchev.com/pub/sh/current/scripts/shCore.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPlain.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushBash.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPython.js&quot;&gt;&lt;/script&gt;
&lt;link type=&quot;text/css&quot; rel=&quot;stylesheet&quot; href=&quot;http://alexgorbatchev.com/pub/sh/current/styles/shCoreDefault.css&quot;/&gt;
&lt;script type=&quot;text/javascript&quot;&gt;SyntaxHighlighter.defaults.toolbar=false; SyntaxHighlighter.all();&lt;/script&gt;&lt;/div&gt;
</content>
  </entry>
  <entry>
    <title type="text">Link shortening on hotkey</title>
    <id>/post/link-shortener/?lang=en</id>
    <updated>2011-08-12T10:45:00Z</updated>
    <published>2011-08-12T10:45:00Z</published>
    <link href="http://blog.f-y.name/post/link-shortener/?lang=en" />
    <author>
      <name>Anton Novosyolov</name>
      <email>anton.novosyolov@gmail.com</email>
    </author>
    <summary type="html">&lt;!-- date: 1313145900 --&gt;
&lt;!-- tags: Nokia N900 --&gt;
&lt;p&gt;Install &lt;a class=&quot;reference external&quot; href=&quot;http://maemo.org/packages/view/keyboard-shortcuts/&quot;&gt;keyboard-shortcuts&lt;/a&gt;. Also install CSSU, so as to get keyboard-shortcuts work.&lt;/p&gt;
&lt;p&gt;Tune &lt;tt class=&quot;docutils literal&quot;&gt;&lt;span class=&quot;pre&quot;&gt;/apps/osso/hildon-desktop/key-actions/dbus_shortcuts_use_fn&lt;/span&gt;&lt;/tt&gt;
to press &lt;tt class=&quot;docutils literal&quot;&gt;&lt;span class=&quot;pre&quot;&gt;Ctrl-Fn-&amp;lt;letter&amp;gt;&lt;/span&gt;&lt;/tt&gt; instead of &lt;tt class=&quot;docutils literal&quot;&gt;&lt;span class=&quot;pre&quot;&gt;Ctrl-Shift-&amp;lt;letter&amp;gt;&lt;/span&gt;&lt;/tt&gt; (if you prefer).&lt;/p&gt;
&lt;p&gt;&lt;em&gt;/home/user/.bin/clck.py&lt;/em&gt;:&lt;/p&gt;

&lt;pre class=&quot;brush: python&quot;&gt;
#!/usr/bin/python
import os
import pygtk
pygtk.require('2.0')
import gtk

clipboard = gtk.clipboard_get()
text = clipboard.wait_for_text()

import urllib2
fetcher = urllib2.urlopen('http://clck.ru/--?url=' + text)
text = fetcher.read()

os.system(&quot;phone-control --notify 'Link is shortened'&quot;)

clipboard.set_text(text)
clipboard.store()
&lt;/pre&gt;

&lt;p&gt;Edit &lt;em&gt;/usr/bin/keyboard-shortcuts&lt;/em&gt;:&lt;/p&gt;

&lt;pre class=&quot;brush: bash&quot;&gt;
if key == 'c': # or another letter
    os.system(&quot;su user -c 'run-standalone.sh /home/user/.bin/clck.py'&quot;)
&lt;/pre&gt;

&lt;script type=&quot;text/javascript&quot; src=&quot;http://alexgorbatchev.com/pub/sh/current/scripts/shCore.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPython.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushBash.js&quot;&gt;&lt;/script&gt;
&lt;link type=&quot;text/css&quot; rel=&quot;stylesheet&quot; href=&quot;http://alexgorbatchev.com/pub/sh/current/styles/shCoreDefault.css&quot;/&gt;
&lt;script type=&quot;text/javascript&quot;&gt;SyntaxHighlighter.defaults.toolbar=false; SyntaxHighlighter.all();&lt;/script&gt;</summary>
    <content type="html">&lt;!-- date: 1313145900 --&gt;
&lt;!-- tags: Nokia N900 --&gt;
&lt;p&gt;Install &lt;a class=&quot;reference external&quot; href=&quot;http://maemo.org/packages/view/keyboard-shortcuts/&quot;&gt;keyboard-shortcuts&lt;/a&gt;. Also install CSSU, so as to get keyboard-shortcuts work.&lt;/p&gt;
&lt;p&gt;Tune &lt;tt class=&quot;docutils literal&quot;&gt;&lt;span class=&quot;pre&quot;&gt;/apps/osso/hildon-desktop/key-actions/dbus_shortcuts_use_fn&lt;/span&gt;&lt;/tt&gt;
to press &lt;tt class=&quot;docutils literal&quot;&gt;&lt;span class=&quot;pre&quot;&gt;Ctrl-Fn-&amp;lt;letter&amp;gt;&lt;/span&gt;&lt;/tt&gt; instead of &lt;tt class=&quot;docutils literal&quot;&gt;&lt;span class=&quot;pre&quot;&gt;Ctrl-Shift-&amp;lt;letter&amp;gt;&lt;/span&gt;&lt;/tt&gt; (if you prefer).&lt;/p&gt;
&lt;p&gt;&lt;em&gt;/home/user/.bin/clck.py&lt;/em&gt;:&lt;/p&gt;

&lt;pre class=&quot;brush: python&quot;&gt;
#!/usr/bin/python
import os
import pygtk
pygtk.require('2.0')
import gtk

clipboard = gtk.clipboard_get()
text = clipboard.wait_for_text()

import urllib2
fetcher = urllib2.urlopen('http://clck.ru/--?url=' + text)
text = fetcher.read()

os.system(&quot;phone-control --notify 'Link is shortened'&quot;)

clipboard.set_text(text)
clipboard.store()
&lt;/pre&gt;

&lt;p&gt;Edit &lt;em&gt;/usr/bin/keyboard-shortcuts&lt;/em&gt;:&lt;/p&gt;

&lt;pre class=&quot;brush: bash&quot;&gt;
if key == 'c': # or another letter
    os.system(&quot;su user -c 'run-standalone.sh /home/user/.bin/clck.py'&quot;)
&lt;/pre&gt;

&lt;script type=&quot;text/javascript&quot; src=&quot;http://alexgorbatchev.com/pub/sh/current/scripts/shCore.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPython.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushBash.js&quot;&gt;&lt;/script&gt;
&lt;link type=&quot;text/css&quot; rel=&quot;stylesheet&quot; href=&quot;http://alexgorbatchev.com/pub/sh/current/styles/shCoreDefault.css&quot;/&gt;
&lt;script type=&quot;text/javascript&quot;&gt;SyntaxHighlighter.defaults.toolbar=false; SyntaxHighlighter.all();&lt;/script&gt;</content>
  </entry>
  <entry>
    <title type="text">Out-call-vibro variant, using dbus-scripts</title>
    <id>/post/out-call-vibro/?lang=en</id>
    <updated>2011-08-12T10:25:10Z</updated>
    <published>2011-08-12T10:25:10Z</published>
    <link href="http://blog.f-y.name/post/out-call-vibro/?lang=en" />
    <author>
      <name>Anton Novosyolov</name>
      <email>anton.novosyolov@gmail.com</email>
    </author>
    <summary type="html">&lt;!-- date: 1313144710 --&gt;
&lt;!-- tags: Nokia N900 --&gt;
&lt;p&gt;After installing enhanced-busybox, &lt;a class=&quot;reference external&quot; href=&quot;http://maemo.org/packages/view/out-call-vibro/&quot;&gt;out-call-vibro&lt;/a&gt; refused to work.
I had rewritten it using &lt;a class=&quot;reference external&quot; href=&quot;http://wiki.maemo.org/DbusScripts&quot;&gt;dbus-scripts&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;/etc/dbus-scripts.d/out-call-vibro.dbus&lt;/em&gt;:&lt;/p&gt;

&lt;pre class=&quot;brush: plain&quot;&gt;
/home/user/.bin/out-call-vibro.sh * * org.freedesktop.Telepathy.Channel.Interface.Group MembersChanged *
&lt;/pre&gt;

&lt;p&gt;&lt;em&gt;/home/user/.bin/out-call-vibro.sh&lt;/em&gt;:&lt;/p&gt;

&lt;pre class=&quot;brush: bash&quot;&gt;
#!/bin/sh
if [[ &quot;$5&quot; == &quot;Call answered&quot; ]]; then
    if [ `cat /sys/devices/platform/gpio-switch/proximity/state` = &quot;open&quot; ]; then
        echo 150 &gt; /sys/class/leds/twl4030:vibrator/brightness
        gsleep 0.5
        echo 0 &gt; /sys/class/leds/twl4030:vibrator/brightness
    fi
fi
&lt;/pre&gt;

&lt;script type=&quot;text/javascript&quot; src=&quot;http://alexgorbatchev.com/pub/sh/current/scripts/shCore.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPlain.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushBash.js&quot;&gt;&lt;/script&gt;
&lt;link type=&quot;text/css&quot; rel=&quot;stylesheet&quot; href=&quot;http://alexgorbatchev.com/pub/sh/current/styles/shCoreDefault.css&quot;/&gt;
&lt;script type=&quot;text/javascript&quot;&gt;SyntaxHighlighter.defaults.toolbar=false; SyntaxHighlighter.all();&lt;/script&gt;</summary>
    <content type="html">&lt;!-- date: 1313144710 --&gt;
&lt;!-- tags: Nokia N900 --&gt;
&lt;p&gt;After installing enhanced-busybox, &lt;a class=&quot;reference external&quot; href=&quot;http://maemo.org/packages/view/out-call-vibro/&quot;&gt;out-call-vibro&lt;/a&gt; refused to work.
I had rewritten it using &lt;a class=&quot;reference external&quot; href=&quot;http://wiki.maemo.org/DbusScripts&quot;&gt;dbus-scripts&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;/etc/dbus-scripts.d/out-call-vibro.dbus&lt;/em&gt;:&lt;/p&gt;

&lt;pre class=&quot;brush: plain&quot;&gt;
/home/user/.bin/out-call-vibro.sh * * org.freedesktop.Telepathy.Channel.Interface.Group MembersChanged *
&lt;/pre&gt;

&lt;p&gt;&lt;em&gt;/home/user/.bin/out-call-vibro.sh&lt;/em&gt;:&lt;/p&gt;

&lt;pre class=&quot;brush: bash&quot;&gt;
#!/bin/sh
if [[ &quot;$5&quot; == &quot;Call answered&quot; ]]; then
    if [ `cat /sys/devices/platform/gpio-switch/proximity/state` = &quot;open&quot; ]; then
        echo 150 &gt; /sys/class/leds/twl4030:vibrator/brightness
        gsleep 0.5
        echo 0 &gt; /sys/class/leds/twl4030:vibrator/brightness
    fi
fi
&lt;/pre&gt;

&lt;script type=&quot;text/javascript&quot; src=&quot;http://alexgorbatchev.com/pub/sh/current/scripts/shCore.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPlain.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushBash.js&quot;&gt;&lt;/script&gt;
&lt;link type=&quot;text/css&quot; rel=&quot;stylesheet&quot; href=&quot;http://alexgorbatchev.com/pub/sh/current/styles/shCoreDefault.css&quot;/&gt;
&lt;script type=&quot;text/javascript&quot;&gt;SyntaxHighlighter.defaults.toolbar=false; SyntaxHighlighter.all();&lt;/script&gt;</content>
  </entry>
  <entry>
    <title type="text">Sending SMS from server</title>
    <id>/post/send-sms/?lang=en</id>
    <updated>2011-08-07T12:59:24Z</updated>
    <published>2011-08-07T12:59:24Z</published>
    <link href="http://blog.f-y.name/post/send-sms/?lang=en" />
    <author>
      <name>Anton Novosyolov</name>
      <email>anton.novosyolov@gmail.com</email>
    </author>
    <summary type="html">&lt;!-- tags: python --&gt;
&lt;p&gt;Several days ago I looked into details of how my selectel server spended money and saw that it spends
about 20 roubles per day (about $0.8) and has 100% CPU load for about 2 last days. I connected to it and saw that some 'sh' proccess is hang. I just killed it.&lt;/p&gt;
&lt;p&gt;So as to react in time to such cases I decided to set up an SMS notification.&lt;/p&gt;
</summary>
    <content type="html">&lt;!-- tags: python --&gt;
&lt;p&gt;Several days ago I looked into details of how my selectel server spended money and saw that it spends
about 20 roubles per day (about $0.8) and has 100% CPU load for about 2 last days. I connected to it and saw that some 'sh' proccess is hang. I just killed it.&lt;/p&gt;
&lt;p&gt;So as to react in time to such cases I decided to set up an SMS notification.&lt;/p&gt;
&lt;!-- read_more --&gt;
&lt;p&gt;I registered on &lt;a class=&quot;reference external&quot; href=&quot;http://smsc.ru&quot;&gt;SMSC.RU&lt;/a&gt;. One SMS costs 0.50 roubles (about $0.02).&lt;/p&gt;
&lt;p&gt;I wrote small script that is watching average load and will notify if it becomes too high.&lt;/p&gt;

&lt;pre class=&quot;brush: python&quot;&gt;
from urllib import urlopen, urlencode
import re

def send_sms(load):
    data = {
        &quot;login&quot;: &quot;&amp;lt;login&gt;&quot;,
        &quot;psw&quot;: &quot;&amp;lt;password&gt;&quot;,
        &quot;phones&quot;: &quot;&amp;lt;phone-number&gt;&quot;,
        &quot;mes&quot;: (u&quot;Server is overloaded %.2f %.2f %.2f&quot; % tuple(loadavg))
    }

    urlopen(&quot;http://smsc.ru/sys/send.php&quot;, urlencode(data))

f = open(&quot;/proc/loadavg&quot;, &quot;r&quot;)
line = f.readline()
f.close()
m = re.search(&quot;^(\d+[.]\d+) (\d+[.]\d+) (\d+[.]\d+)&quot;, line)
loadavg = [float(x) for x in m.groups()]
if loadavg[2] &gt; 0.7:
    send_sms(loadavg)
&lt;/pre&gt;

&lt;script type=&quot;text/javascript&quot; src=&quot;http://alexgorbatchev.com/pub/sh/current/scripts/shCore.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPython.js&quot;&gt;&lt;/script&gt;
&lt;link type=&quot;text/css&quot; rel=&quot;stylesheet&quot; href=&quot;http://alexgorbatchev.com/pub/sh/current/styles/shCoreDefault.css&quot;/&gt;
&lt;script type=&quot;text/javascript&quot;&gt;SyntaxHighlighter.defaults.toolbar=false; SyntaxHighlighter.all();&lt;/script&gt;</content>
  </entry>
  <entry>
    <title type="text">Hosting moved to selectel cloud</title>
    <id>/post/move-to-selectel/?lang=en</id>
    <updated>2011-07-19T09:24:28Z</updated>
    <published>2011-07-19T09:24:28Z</published>
    <link href="http://blog.f-y.name/post/move-to-selectel/?lang=en" />
    <author>
      <name>Anton Novosyolov</name>
      <email>anton.novosyolov@gmail.com</email>
    </author>
    <summary type="html">&lt;!-- tags: hosting,cloud,selectel,moving --&gt;
&lt;p&gt;As my server is gone down suddenly and I don't have a chance to find out what is with it, I decided to move my blog to cloud platform.&lt;/p&gt;
&lt;p&gt;I chose &lt;a class=&quot;reference external&quot; href=&quot;http://selectel.ru&quot;&gt;Selectel&lt;/a&gt; as hosting provider. Prices start from 50 roubles (about $1.85), this is only for keeping virtual machine for month, without running it. For my blog traffic (almost 0 :) ) overall price will be about 70 roubles (about $2.60) per month, it's very cheap I think.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;UPD&lt;/strong&gt;: After month usage, actual price is about 44 roubles (about $1.57).&lt;/p&gt;
</summary>
    <content type="html">&lt;!-- tags: hosting,cloud,selectel,moving --&gt;
&lt;p&gt;As my server is gone down suddenly and I don't have a chance to find out what is with it, I decided to move my blog to cloud platform.&lt;/p&gt;
&lt;p&gt;I chose &lt;a class=&quot;reference external&quot; href=&quot;http://selectel.ru&quot;&gt;Selectel&lt;/a&gt; as hosting provider. Prices start from 50 roubles (about $1.85), this is only for keeping virtual machine for month, without running it. For my blog traffic (almost 0 :) ) overall price will be about 70 roubles (about $2.60) per month, it's very cheap I think.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;UPD&lt;/strong&gt;: After month usage, actual price is about 44 roubles (about $1.57).&lt;/p&gt;
</content>
  </entry>
  <entry>
    <title type="text">Unlocked volume buttons while screen is locked</title>
    <id>/post/volume-unlocked/?lang=en</id>
    <updated>2011-07-18T12:30:01Z</updated>
    <published>2011-07-18T12:30:01Z</published>
    <link href="http://blog.f-y.name/post/volume-unlocked/?lang=en" />
    <author>
      <name>Anton Novosyolov</name>
      <email>anton.novosyolov@gmail.com</email>
    </author>
    <summary type="html">&lt;!-- date: 1310992201 --&gt;
&lt;!-- tags: Nokia N900 --&gt;
&lt;p&gt;To unlock volume buttons while the screen is locked, edit &lt;em&gt;/etc/mce/mce.ini&lt;/em&gt;, so as parameter DisableKPImmediately in section [TKLock] equals 2.&lt;/p&gt;

&lt;pre class=&quot;brush: plain&quot;&gt;
# Policy for keypad interrupts
#
# 2 - leave keypad interrupts on even after blanking
#     (used to support pass-through of +/-)
# 1 - disable interrupts immediately
# 0 to wait until display is blanked
DisableKPImmediately=2
&lt;/pre&gt;

&lt;script type=&quot;text/javascript&quot; src=&quot;http://alexgorbatchev.com/pub/sh/current/scripts/shCore.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPlain.js&quot;&gt;&lt;/script&gt;
&lt;link type=&quot;text/css&quot; rel=&quot;stylesheet&quot; href=&quot;http://alexgorbatchev.com/pub/sh/current/styles/shCoreDefault.css&quot;/&gt;
&lt;script type=&quot;text/javascript&quot;&gt;SyntaxHighlighter.defaults.toolbar=false; SyntaxHighlighter.all();&lt;/script&gt;</summary>
    <content type="html">&lt;!-- date: 1310992201 --&gt;
&lt;!-- tags: Nokia N900 --&gt;
&lt;p&gt;To unlock volume buttons while the screen is locked, edit &lt;em&gt;/etc/mce/mce.ini&lt;/em&gt;, so as parameter DisableKPImmediately in section [TKLock] equals 2.&lt;/p&gt;

&lt;pre class=&quot;brush: plain&quot;&gt;
# Policy for keypad interrupts
#
# 2 - leave keypad interrupts on even after blanking
#     (used to support pass-through of +/-)
# 1 - disable interrupts immediately
# 0 to wait until display is blanked
DisableKPImmediately=2
&lt;/pre&gt;

&lt;script type=&quot;text/javascript&quot; src=&quot;http://alexgorbatchev.com/pub/sh/current/scripts/shCore.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPlain.js&quot;&gt;&lt;/script&gt;
&lt;link type=&quot;text/css&quot; rel=&quot;stylesheet&quot; href=&quot;http://alexgorbatchev.com/pub/sh/current/styles/shCoreDefault.css&quot;/&gt;
&lt;script type=&quot;text/javascript&quot;&gt;SyntaxHighlighter.defaults.toolbar=false; SyntaxHighlighter.all();&lt;/script&gt;</content>
  </entry>
</feed>
