<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">

  <title><![CDATA[RarestBlog]]></title>
  <link href="http://rarestblog.com/atom.xml" rel="self"/>
  <link href="http://rarestblog.com/"/>
  <updated>2015-01-11T12:05:28-05:00</updated>
  <id>http://rarestblog.com/</id>
  <author>
    <name><![CDATA[Slava Vishnyakov]]></name>
    <email><![CDATA[bomboze@gmail.com]]></email>
  </author>
  <generator uri="http://octopress.org/">Octopress</generator>

  
  <entry>
    <title type="html"><![CDATA[Rails serialize JSON with symbolize_names]]></title>
    <link href="http://rarestblog.com/blog/2014/12/19/rails-serialize-json-with-symbolize_names/"/>
    <updated>2014-12-19T08:04:00-05:00</updated>
    <id>http://rarestblog.com/blog/2014/12/19/rails-serialize-json-with-symbolize_names</id>
    <content type="html"><![CDATA[<p>Haven&#8217;t found a better solution</p>

<pre><code>class Something &lt; ActiveRecord::Base
  class JsonSymbolized
    def self.load(string)
      JSON.parse(string, symbolize_names: true)
    end

    def self.dump(object)
      object.to_json
    end
  end

  serialize :field, JsonSymbolized
end
</code></pre>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Install Bootstrap 3 (and Font Awesome) on Rails]]></title>
    <link href="http://rarestblog.com/blog/2014/12/18/install-bootstrap-3-on-rails/"/>
    <updated>2014-12-18T15:38:00-05:00</updated>
    <id>http://rarestblog.com/blog/2014/12/18/install-bootstrap-3-on-rails</id>
    <content type="html"><![CDATA[<p>After a few hours of fighting with Glyphicons in <code>twitter-bootstrap-rails</code> gem,
it&#8217;s just easier to install Bootstrap by hand..</p>

<pre><code>wget http://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/js/bootstrap.min.js  -O app/assets/javascripts/bootstrap.min.js
wget http://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css  -O app/assets/stylesheets/bootstrap.min.css

mkdir public/fonts
wget http://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/fonts/glyphicons-halflings-regular.eot -O public/fonts/glyphicons-halflings-regular.eot
wget http://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/fonts/glyphicons-halflings-regular.svg -O public/fonts/glyphicons-halflings-regular.svg
wget http://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/fonts/glyphicons-halflings-regular.ttf -O public/fonts/glyphicons-halflings-regular.ttf
wget http://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/fonts/glyphicons-halflings-regular.woff -O public/fonts/glyphicons-halflings-regular.woff
</code></pre>

<p>Also Font Awesome:</p>

<pre><code>wget https://maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css -O app/assets/stylesheets/font-awesome.min.css
wget https://maxcdn.bootstrapcdn.com/font-awesome/4.2.0/fonts/fontawesome-webfont.eot -O public/fonts/fontawesome-webfont.eot
wget https://maxcdn.bootstrapcdn.com/font-awesome/4.2.0/fonts/fontawesome-webfont.woff -O public/fonts/fontawesome-webfont.woff
wget https://maxcdn.bootstrapcdn.com/font-awesome/4.2.0/fonts/fontawesome-webfont.ttf -O public/fonts/fontawesome-webfont.ttf
wget https://maxcdn.bootstrapcdn.com/font-awesome/4.2.0/fonts/fontawesome-webfont.svg -O public/fonts/fontawesome-webfont.svg
</code></pre>

<p>And bootstrap 3 Theme:</p>

<pre><code>wget http://getbootstrap.com/dist/css/bootstrap-theme.min.css -O app/assets/stylesheets/z-bootstrap-theme.min.css
</code></pre>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Installing golang-1.3 on Linux x86_64]]></title>
    <link href="http://rarestblog.com/blog/2014/12/01/installing-golang-1-3-on-linux-x86_64/"/>
    <updated>2014-12-01T07:32:00-05:00</updated>
    <id>http://rarestblog.com/blog/2014/12/01/installing-golang-1-3-on-linux-x86_64</id>
    <content type="html"><![CDATA[<p>After this restart the shell (re-login to ssh)</p>

<pre><code>wget https://storage.googleapis.com/golang/go1.3.3.linux-amd64.tar.gz
tar -C /usr/local -xzf go1.3.3.linux-amd64.tar.gz
echo 'export PATH=$PATH:/usr/local/go/bin' &gt;&gt; /etc/profile
</code></pre>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[What are the chances that two random IDs are the same]]></title>
    <link href="http://rarestblog.com/blog/2014/11/28/what-are-the-chances-that-two-random-ids-are-the-same/"/>
    <updated>2014-11-28T07:59:00-05:00</updated>
    <id>http://rarestblog.com/blog/2014/11/28/what-are-the-chances-that-two-random-ids-are-the-same</id>
    <content type="html"><![CDATA[<p>Today, there was a discussion that we should use random IDs for some value.
The maximum count is 100 million variations.
Every day we generate about 3000 of those things.</p>

<p>Given that our developers told me that it&#8217;s practically impossible that
two items have the same ID in the same day&#8230; because&#8230; 100 million!
&#8230;.and Probability Theory! :)</p>

<p>It&#8217;s interesting that not many know of Birthday paradox. It says that
when there are 23 people in the room, there is 50% chance that two of them
have the same birthday. Not 180, just 23!</p>

<p>I&#8217;ve found a neat calculator
online and within a minute there was a result.</p>

<p>When you have 3000 random selections per day from field of 100 million numbers -
you have 4% chance that in any given day you will have duplicate.</p>

<p>In a week you have 88% chance! Think about it. 3000 random picks per day from 100 million and 88% chance!</p>

<p>Within 10 days you have 99% chance.</p>

<p>Mind-blowing, no? :)</p>

<p><a href="https://lazycackle.com/Probability_of_repeated_event_online_calculator__birthday_problem_.html">
<img src="http://rarestblog.com/assets/images/ff5b94e6b841b1b1c22e34a86e94af76.png" alt="image" />
</a></p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Developing SaltStack with Vagrant]]></title>
    <link href="http://rarestblog.com/blog/2014/11/20/developing-saltstack-with-vagrant/"/>
    <updated>2014-11-20T16:21:00-05:00</updated>
    <id>http://rarestblog.com/blog/2014/11/20/developing-saltstack-with-vagrant</id>
    <content type="html"><![CDATA[<p>This is probably the fastest way to develop and test your SaltStack States.</p>

<p>0) Install Vagrant (via Googling)</p>

<p>1) Create <code>./srv/salt</code> dir and <code>./srv/pillar</code> dirs</p>

<p>2) Create <code>Vagrantfile</code> file:</p>

<!--more-->


<p>Simple: CentOS master and minion on same machine</p>

<pre><code>Vagrant.configure(2) do |config|
    config.vm.define "master" do |node|

        node.vm.box = 'chef/centos-6.5'
        node.vm.box_url = 'http://developer.nrel.gov/downloads/vagrant-boxes/CentOS-6.4-i386-v20131103.box'

        node.vm.synced_folder "srv/", "/srv", type: "nfs"
        node.vm.hostname = 'salt-master.local'

        script = '
            rpm -Uvh http://ftp.linux.ncsu.edu/pub/epel/6/i386/epel-release-6-8.noarch.rpm
            yum install -y salt-master salt-minion
            echo "192.168.50.2 salt" &gt;&gt; /etc/hosts
            service salt-master start
            service salt-minion start
            sleep 5
            salt-key -y -a salt-master.local
        '

        node.vm.provision "shell", inline: script

        node.vm.network "private_network", ip: "192.168.50.2"

        node.vm.provider "virtualbox" do |v|
            v.name = 'salt-master'
            v.memory = 4096
            v.cpus = 4
        end
    end


end
</code></pre>

<p>Or more complex - uses <code>Ubuntu 14.04</code> for <code>minon</code> and <code>CentOS 6.4</code> for <code>master</code>:</p>

<pre><code>Vagrant.configure(2) do |config|

    config.vm.define "master" do |node|

        node.vm.box = 'centos-6.4'
        node.vm.box_url = 'http://developer.nrel.gov/downloads/vagrant-boxes/CentOS-6.4-i386-v20131103.box'

        node.vm.network "private_network", ip: "192.168.50.5"

        script = '
            rpm -Uvh http://ftp.linux.ncsu.edu/pub/epel/6/i386/epel-release-6-8.noarch.rpm
            yum install -y salt-master
            service salt-master start
        '

        node.vm.provision "shell", inline: script

        node.vm.provider "virtualbox" do |v|
            v.name = 'salt-master'
            v.memory = 2048
            v.cpus = 4
        end
    end

    config.vm.define "minion" do |node|

        node.vm.box = 'ubuntu-14.04'
        node.vm.box_url = 'https://cloud-images.ubuntu.com/vagrant/trusty/current/trusty-server-cloudimg-amd64-vagrant-disk1.box'

        node.vm.network "private_network", ip: "192.168.50.10"

        script = '
            apt-get update
            apt-get -y install python-software-properties
            yes | add-apt-repository ppa:saltstack/salt
            apt-get -y --force-yes install salt-minion
            echo "master: 192.168.50.5" &gt; /etc/salt/minion
            echo "id: minion" &gt;&gt; /etc/salt/minion
            service salt-minion restart
        '

        node.vm.provision "shell", inline: script

        node.vm.provider "virtualbox" do |v|
            v.name = 'salt-minion'
            v.memory = 4096
            v.cpus = 4
        end
    end


end
</code></pre>

<p>3) Run <code>vagrant ssh master</code></p>

<p>4) run <code>salt-key -A</code></p>

<p>5) <code>salt-call state.highstate</code></p>

<p>Your <code>minion</code> is <code>192.168.50.10</code>
Your <code>master</code> is <code>192.168.50.5</code></p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[BitCoin, Future and Crowd financed government]]></title>
    <link href="http://rarestblog.com/blog/2014/11/20/bitcoin-future-and-crowd-financed-government/"/>
    <updated>2014-11-20T09:10:00-05:00</updated>
    <id>http://rarestblog.com/blog/2014/11/20/bitcoin-future-and-crowd-financed-government</id>
    <content type="html"><![CDATA[<p>Today I thought about the way we pay taxes and BitCoin.
The first thought was: let&#8217;s assume my employer starts to accept BitCoin
and pay me salary in BitCoin. But then government has a problem -
it can&#8217;t really track all the BitCoin transactions, it has to mostly trust
company (and me) to tell it how much have I made. Of course there can be
regulations which make it more clear, but let&#8217;s continue the thought.</p>

<p>Let&#8217;s imagine the taxes paying instead as a Crowd-funded State.</p>

<p>So, basically, State says that you have to spend 40% of your income on Govt.
programs.</p>

<p>And then you have something like:</p>

<ul>
<li>Local hospital<br><code>€10 000 000</code> <br>FULLY FUNDED<br><br></li>
<li>Payment for teachers in your state<br><code>€3 200 000</code> of <code>€5 000 000</code> collected <br><img src="http://rarestblog.com/assets/images/a28b6b8a3c08247c9c132aea23fd8453.png" alt="image" /><br><br></li>
<li>Payment for doctors in neighbour poor state<br><code>€499 999</code> of <code>€500 000</code> collected <br><img src="http://rarestblog.com/assets/images/a28b6b8a3c08247c9c132aea23fd8453.png" alt="image" /><br><br></li>
<li>War with neighbouring country<br><code>€0</code> of <code>€100 000 000</code> collected <br><img src="http://rarestblog.com/assets/images/a28b6b8a3c08247c9c132aea23fd8453.png" alt="image" /><br><br></li>
<li>Big Bank Bailout<br><code>€0</code> of <code>€700 000 000 000</code> collected <br><img src="http://rarestblog.com/assets/images/a28b6b8a3c08247c9c132aea23fd8453.png" alt="image" /><br><br></li>
</ul>


<p>Obviously the prices are in € or in $ or any other state-issued money :)
But that doesn&#8217;t mean that they can&#8217;t accept BitCoin for that.</p>

<p>And then you are free to distribute your funds as you see fit. Then all those
programs that people don&#8217;t agree with - won&#8217;t get funding.</p>

<p>Now that&#8217;s some nice future that I want to live in! :)</p>

<p>It will probably be the first time I&#8217;d be happy to pay my taxes.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[grucrawler - simple crawler for Ruby]]></title>
    <link href="http://rarestblog.com/blog/2014/11/18/grucrawler-simple-crawler-for-ruby/"/>
    <updated>2014-11-18T18:33:00-05:00</updated>
    <id>http://rarestblog.com/blog/2014/11/18/grucrawler-simple-crawler-for-ruby</id>
    <content type="html"><![CDATA[<p>Released a generic Redis-based crawler for Ruby today. Very alpha. Use at your own risk.</p>

<p>Has throttling, concurrency and some limits, but that&#8217;s about it.</p>

<p>An example to parse a lot of Italian websites:</p>

<pre><code>require 'grucrawler'
require 'colorize'

class ItalianCrawler
  def options
    {
        visit_urls_only_once: true,
        follow_redirects: true,
        concurrency: 5,
        domain_wait: 20, # seconds between visits to the same domain
        max_page_size: 10000000
    }
  end

  def on_init(crawler)
    @crawler = crawler
  end

  def on_page_received(typhoeus_response, nokogiri_html)
    puts "GOT #{typhoeus_response.effective_url.green}"

    # typhoeus_response.body
    # typhoeus_response.request.url
    # typhoeus_response.effective_url
    # nokogiri_html.css('a').each |a| { puts a.text; }
  end

  def follow_link(target_url, typhoeus_response, nokogiri_html)
    return false if target_url.match(/\.(jpg|png|js|css|pdf|exe|dmg|zip|doc|rtf|rar|swf|bmp|swf|mp3|wav|mp4|mpg|flv|wma)$/)

    return true if target_url.include? '.it'

    false
  end

  def debug(message)
    #puts message.blue
  end

  def log_info(message)
    puts message.yellow
  end

  def log_error(typhoeus_response, exception)
    puts exception.to_s.red
  end
end

c = GruCrawler.new(ItalianCrawler.new)
# c.reset() # deletes all memory of all events - useful for restarting crawl
c.add_url('http://www.oneworlditaliano.com/english/italian/news-in-italian.htm')
c.run()
</code></pre>

<p>API might change in future, so</p>

<pre><code>gem install grucrawler --version '0.0.5'
</code></pre>

<p>for the example below to work.</p>

<p>Here, <a href="https://github.com/slava-vishnyakov/grucrawler">grucrawler</a></p>

<p>Why? I&#8217;ve got tired of my attempts to get to understand all the complex stuff
that goes into configuring all other crawlers. Too complex.
I&#8217;ve wanted something dead simple.</p>

<p>Have fun!</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Let's encrypt - free SSL for everybody in Summer 2015]]></title>
    <link href="http://rarestblog.com/blog/2014/11/18/let-s-encrypt-free-ssl-for-everybody-in-summer-2015/"/>
    <updated>2014-11-18T11:53:00-05:00</updated>
    <id>http://rarestblog.com/blog/2014/11/18/let-s-encrypt-free-ssl-for-everybody-in-summer-2015</id>
    <content type="html"><![CDATA[<p>An initiave to bring https (SSL) to every server in a few clicks.
Every developer would agree that issiing and installing certificate is hard
and long (even if you know how), but in Summer 2015 it&#8217;s going to be
free and fast (less than a minute).</p>

<p>Awesome!</p>

<p><a href="https://letsencrypt.org/">Let&#8217;s encrypt initiative</a></p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[When you try something new and fail]]></title>
    <link href="http://rarestblog.com/blog/2014/11/17/when-you-try-something-new-and-fail/"/>
    <updated>2014-11-17T10:32:00-05:00</updated>
    <id>http://rarestblog.com/blog/2014/11/17/when-you-try-something-new-and-fail</id>
    <content type="html"><![CDATA[<p>Today I realized something that probably many people realized before.</p>

<p>We give up too easy. Especially when you are doing something new and try it
for a few times and you see that it fails, you think that it&#8217;s not good and stop.</p>

<p>That&#8217;s the mistake. When I remember anything that I do well - it took me
considerable amount of time to get good at it, considerable amount of failures
went into that. But I didn&#8217;t give up and then I&#8217;ve became good at it.</p>

<p>Yet in many other cases I try something and I give up quite soon, when I should
have continued.</p>

<p>We need to make habits of what we want to get good at. Only the daily routine
can make you good at something.</p>

<p>Don&#8217;t give up too easy!</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Yabla]]></title>
    <link href="http://rarestblog.com/blog/2014/11/15/yabla/"/>
    <updated>2014-11-15T07:21:00-05:00</updated>
    <id>http://rarestblog.com/blog/2014/11/15/yabla</id>
    <content type="html"><![CDATA[<p>If you want to learn a language - go see <a href="https://www.yabla.com/">Yabla</a>
(Spanish, French, German, Italian, Chinese).</p>

<p><img src="http://rarestblog.com/assets/images/417e719ef64ca1fd78f89318b7a83396.png" alt="image" /></p>

<p>I&#8217;m learning German and the biggest problem so far is understanding what natives
say (especially in movies, when they speak real fast). Yabla is awesome -
it shows you the video with subtitles (nothing new here), and you can loop
single phrase (that&#8217;s new!) and even slow it down.</p>

<p>Then there is &#8220;flashcards&#8221; feature. When you watch a video - you can click
on unknown word and you see the translation, but in the background Yabla adds
it to your Flashcards and you can review them later.</p>

<p>Probably the most useful thing I&#8217;ve tried for languages.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Mini Habits]]></title>
    <link href="http://rarestblog.com/blog/2014/11/13/mini-habits/"/>
    <updated>2014-11-13T17:45:00-05:00</updated>
    <id>http://rarestblog.com/blog/2014/11/13/mini-habits</id>
    <content type="html"><![CDATA[<p>Following the advise in the
&#8221;<a href="http://www.amazon.com/Mini-Habits-Smaller-Bigger-Results-ebook/dp/B00HGKNBDK">Mini Habits</a>&#8221;
book, I will try to make a new habit of writing to the blog.</p>

<p>Actually, &#8220;Mini Habits&#8221; got me a great idea that if you can do something regularly
you should cut it in half and in half and in half until the task is so small
that it&#8217;s more easy to do it than to figure out why should you not do it.</p>

<p>So for the blog posts at first the task was to &#8220;Write a blog post&#8221;, but
that seems like a lot almost always, so eventually the task got to be &#8220;Write a
1-line blog post&#8221;.</p>

<p>Well, that&#8217;s quite easy. And it gets you started. And when you start doing something
it&#8217;s harder to stop rather than continue, so you almost always exceed your
original microscopic plan by far.</p>

<p>Also, &#8221;<a href="http://www.habitbull.com/">Habit bull</a>&#8221; is really a great app
for Android to keep you on track with your new mini-habits.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Install CoreOS on Hetzner]]></title>
    <link href="http://rarestblog.com/blog/2014/08/21/install-coreos-on-hetzner/"/>
    <updated>2014-08-21T08:01:00-04:00</updated>
    <id>http://rarestblog.com/blog/2014/08/21/install-coreos-on-hetzner</id>
    <content type="html"><![CDATA[<p>1) Boot into Rescue</p>

<p>2) If you have previously installed RAID, disable it:</p>

<pre><code>mdadm -S /dev/md0
mdadm -S /dev/md1
mdadm -S /dev/md2
</code></pre>

<p>3) Clean up partition table:</p>

<pre><code>dd if=/dev/zero of=/dev/sda bs=100M count=1
</code></pre>

<p>4) Install CoreOS</p>

<pre><code>cd /tmp

cat &gt;cloud-config.yaml &lt;&lt; 'EOF'
#cloud-config

hostname: coreos1

ssh_authorized_keys:
  - ssh-rsa AAAAB3....
EOF

wget https://raw.githubusercontent.com/coreos/init/master/bin/coreos-install
chmod +x coreos-install
./coreos-install -d /dev/sda -C stable -c cloud-config.yaml
</code></pre>

<p>5) Reboot</p>

<p>6) You can now do <code>ssh core@your-server.com</code></p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Simple golang http server and proxy]]></title>
    <link href="http://rarestblog.com/blog/2013/12/01/simple-golang-http-server-and-proxy/"/>
    <updated>2013-12-01T07:34:00-05:00</updated>
    <id>http://rarestblog.com/blog/2013/12/01/simple-golang-http-server-and-proxy</id>
    <content type="html"><![CDATA[<p>This is a simple golang HTTP server and proxy to test high-load setups</p>

<pre><code>    package main

    import (
        "fmt"
        "io/ioutil"
        "net"
        "net/http"
        "time"
    )

    func handler(w http.ResponseWriter, r *http.Request) {
        fmt.Fprintf(w, "Hi!")
    }

    func handler_proxy(w http.ResponseWriter, r *http.Request) {
        tr := &amp;http.Transport{
            MaxIdleConnsPerHost: 250,
            Dial: func(netw, addr string) (net.Conn, error) {
                timeout := time.Duration(10000) * time.Millisecond
                c, err := net.DialTimeout(netw, addr, timeout)
                if err != nil {
                    return nil, err
                }
                // also set time limit on reading
                c.SetDeadline(time.Now().Add(timeout))
                return c, nil
            }}

        // spawn an idle conn trimmer
        go func(t *http.Transport) {
            // prunes every 5 minutes. this is just a guess at an
            // initial value. very busy workers may want to lower this...
            for {
                time.Sleep(10 * time.Second)
                t.CloseIdleConnections()
            }
        }(tr)

        // build/compile regex
        client := &amp;http.Client{Transport: tr}

        resp, err := client.Get("http://127.0.0.1:8080/")

        if err != nil {
            fmt.Fprintf(w, "Cannot connect %v", err)
            return
        }

        defer resp.Body.Close()
        body, err := ioutil.ReadAll(resp.Body)

        w.Write(body)
    }

    func main() {
        http.HandleFunc("/", handler)
        http.HandleFunc("/proxy", handler_proxy)
        http.ListenAndServe(":8080", nil)
    }
</code></pre>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Linux High Load HTTP server configs]]></title>
    <link href="http://rarestblog.com/blog/2013/12/01/linux-high-load-http-server-configs/"/>
    <updated>2013-12-01T07:29:00-05:00</updated>
    <id>http://rarestblog.com/blog/2013/12/01/linux-high-load-http-server-configs</id>
    <content type="html"><![CDATA[<p>Just some useful configs to test for high-load HTTP server Linux machines:</p>

<pre><code>sysctl -w net.core.rmem_max=67108864
sysctl -w net.core.wmem_max=67108864
sysctl -w net.ipv4.tcp_rmem=4096 87380 33554432
sysctl -w net.ipv4.tcp_wmem=4096 65536 33554432
sysctl -w net.core.netdev_max_backlog=30000
sysctl -w net.ipv4.tcp_congestion_control=htcp
sysctl -w net.ipv4.tcp_mtu_probing=1
sysctl -w net.netfilter.nf_conntrack_generic_timeout=120
sysctl -w net.ipv4.ip_local_port_range=1025 65535
sysctl -w net.ipv4.tcp_max_tw_buckets=1048576
sysctl -w net.ipv4.tcp_max_tw_buckets_ub=66144
sysctl -w net.nf_conntrack_max=524288
sysctl -w net.ipv4.tcp_timestamps=1
sysctl -w net.ipv4.tcp_tw_recycle=1

ulimit -n 9999999
echo 9999999 &gt; /proc/sys/fs/nr_open
echo 9999999 &gt; /proc/sys/fs/file-max

/sbin/ifconfig eth0 txqueuelen 100000
</code></pre>

<p>More to try:</p>

<ul>
<li><a href="http://stackoverflow.com/questions/12234050/nginx-high-volume-traffic-load-balancing">http://stackoverflow.com/questions/12234050/nginx-high-volume-traffic-load-balancing</a></li>
<li><a href="http://www.lognormal.com/blog/2012/09/27/linux-tcpip-tuning/">http://www.lognormal.com/blog/2012/09/27/linux-tcpip-tuning/</a></li>
</ul>


<p>Sources:</p>

<ul>
<li><a href="http://fasterdata.es.net/host-tuning/linux/">http://fasterdata.es.net/host-tuning/linux/</a></li>
<li><a href="http://shenfeng.me/how-far-epoll-can-push-concurrent-socket-connection.html">http://shenfeng.me/how-far-epoll-can-push-concurrent-socket-connection.html</a></li>
</ul>

]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Install EPEL 7]]></title>
    <link href="http://rarestblog.com/blog/2013/11/20/install-epel-7/"/>
    <updated>2013-11-20T17:14:00-05:00</updated>
    <id>http://rarestblog.com/blog/2013/11/20/install-epel-7</id>
    <content type="html"><![CDATA[<p>rpm -Uvh https://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-2.noarch.rpm</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Bootstrap 3 / Angular boilerplate]]></title>
    <link href="http://rarestblog.com/blog/2013/11/13/bootstrap-3-angular-boilerplate/"/>
    <updated>2013-11-13T19:13:00-05:00</updated>
    <id>http://rarestblog.com/blog/2013/11/13/bootstrap-3-angular-boilerplate</id>
    <content type="html"><![CDATA[<p>Just for my own reference..</p>

<h3>Bootstrap 3 with old theme</h3>

<pre><code>&lt;link rel="stylesheet" type="text/css" href="http://rarestblog.com//maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css"&gt;
&lt;script type="text/javascript" src="http://rarestblog.com//maxcdn.bootstrapcdn.com/bootstrap/3.3.1/js/bootstrap.min.js"&gt;&lt;/script&gt;
&lt;link rel="stylesheet" type="text/css" href="http://getbootstrap.com/dist/css/bootstrap-theme.min.css"&gt;
</code></pre>

<h3>Angular 1.2</h3>

<pre><code>&lt;script type="text/javascript" src="http://rarestblog.com//cdnjs.cloudflare.com/ajax/libs/angular.js/1.2.1/angular.js"&gt;&lt;/script&gt;

&lt;script type="text/javascript"&gt;
    var app = angular.module('app', []);

    app.controller('MainCtrl', function ($scope) {
      $scope.var1 = '123';
    });
&lt;/script&gt;

&lt;div ng-app="app" class="ng-scope"&gt;
    &lt;div ng-controller="MainCtrl" class="ng-scope"&gt;
        &lt;div class="ng-binding"&gt;{{ var1 }}&lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;
</code></pre>

<h3>JSFiddle</h3>

<p>http://jsfiddle.net/993gt1Lc/</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[FollowUpThen]]></title>
    <link href="http://rarestblog.com/blog/2013/08/03/followupthen/"/>
    <updated>2013-08-03T13:26:00-04:00</updated>
    <id>http://rarestblog.com/blog/2013/08/03/followupthen</id>
    <content type="html"><![CDATA[<p>Wanted to recommend a great software that I use daily.</p>

<p>Create an email and send it to</p>

<pre><code>tomorrow@fut.io
</code></pre>

<p>This e-mail will return to you tomorrow, at which point you would be able to
defer it for any amount of time or be done with it.</p>

<p>The service is called FollowUpThen and it&#8217;s awesome!</p>

<p>Some things to try: <code>tomorrow8am@fut.io</code>, <code>nextmonday@fut.io</code>, <code>every3days@fut.io</code>,
<code>5d@fut.io</code> (in 5 days).</p>

<p><a href="http://www.followupthen.com/">Try it! - http://www.followupthen.com/</a></p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Gerar PHP]]></title>
    <link href="http://rarestblog.com/blog/2013/07/27/gerar-php/"/>
    <updated>2013-07-27T16:37:00-04:00</updated>
    <id>http://rarestblog.com/blog/2013/07/27/gerar-php</id>
    <content type="html"><![CDATA[<p>Today I started experimenting with something - PHP-based configuration management
(think Chef/Puppet).</p>

<p>Basically I though something like this should be possible:</p>

<pre><code>Package::named("php5-cli mysql-server git imagemagick")
    -&gt;shouldBeInstalled();

Service::named('apache2')
    -&gt;shouldBeInstalled()
    -&gt;shouldBeRunning()
    -&gt;shouldBeRunningAtReboots();


File::named('/var/www/index.html')-&gt;write("Bender is great!");

Http::request('http://localhost/')
    -&gt;onSuccess(function($request, $response) {
        Console::log('My new code is "' . $response-&gt;getBody() . '"');
    })
    -&gt;run();

User::named('root')
    -&gt;shouldHaveSshKey()
    -&gt;mailPublicKeyOnce('user@super-server.com');

User::named('alex')
    -&gt;shouldBePresent()
    -&gt;haveSshKeyFrom('files/alex.ssh')
    -&gt;shouldBeInGroup('sudo')
    -&gt;shouldHaveNoPasswordSudoFor('/usr/sbin/service')
    -&gt;shouldHaveSudoFor('/bin/vi');
</code></pre>

<p>I thought that since PHP has PHPStorm, which has a great auto-completion -
it should be much easier to write PHP scripts than Puppet/Chef scripts.
Also you have a complete language to help you refactor the code.</p>

<p>And that&#8217;s what I actually implemented. It&#8217;s still a work in progress,
but check it out if you want to.</p>

<p><a href="https://github.com/slava-vishnyakov/gerar-php">Git repository</a></p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Interesting eBook: Hype-free Principles for Software Developers by Jason Gorman]]></title>
    <link href="http://rarestblog.com/blog/2013/07/27/interesting-ebook-hype-free-principles-for-software-developers-by-jason-gorman/"/>
    <updated>2013-07-27T16:36:00-04:00</updated>
    <id>http://rarestblog.com/blog/2013/07/27/interesting-ebook-hype-free-principles-for-software-developers-by-jason-gorman</id>
    <content type="html"><![CDATA[<ol>
<li>Software Should Have Testable Goals</li>
<li>Close Customer Involvement Is Key</li>
<li>Software Development Is A Learning Process</li>
<li>Do The Important Stuff First</li>
<li>Communicating Is The Principal Activity</li>
<li>Prevention Is (Usually) Cheaper Than Cure</li>
<li>Software That Can&#8217;t Be Put To Use Has No Value</li>
<li>Interfaces Are For Communicating</li>
<li>Automate The Donkey Work
10.Grow Complex Software Using The Simplest Parts
11.To Learn, We Must Be Open To Change</li>
</ol>


<p><a href="http://codemanship.co.uk/backtobasics.pdf">Check it out</a></p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Simplest way to have virtual machines on production: OpenVZ]]></title>
    <link href="http://rarestblog.com/blog/2013/07/09/simplest-way-to-have-virtual-machines-on-production-openvz/"/>
    <updated>2013-07-09T08:18:00-04:00</updated>
    <id>http://rarestblog.com/blog/2013/07/09/simplest-way-to-have-virtual-machines-on-production-openvz</id>
    <content type="html"><![CDATA[<p><strong>Update</strong>: things have changed and now &#8220;Docker + Fig&#8221; is much better and easier way.</p>

<h2>Installing</h2>

<p>Start with CentOS 6 as root:</p>

<pre><code>wget -P /etc/yum.repos.d/ http://ftp.openvz.org/openvz.repo
rpm --import http://ftp.openvz.org/RPM-GPG-Key-OpenVZ
yum install vzkernel

echo "
# On Hardware Node we generally need
# packet forwarding enabled and proxy arp disabled
net.ipv4.ip_forward = 1
net.ipv6.conf.default.forwarding = 1
net.ipv6.conf.all.forwarding = 1
net.ipv4.conf.default.proxy_arp = 0

# Enables source route verification
net.ipv4.conf.all.rp_filter = 1

# Enables the magic-sysrq key
kernel.sysrq = 1

# We do not want all our interfaces to send redirects
net.ipv4.conf.default.send_redirects = 1
net.ipv4.conf.all.send_redirects = 0
" &gt;&gt; /etc/sysctl.conf

echo "SELINUX=disabled" &gt; /etc/sysconfig/selinux

yum install vzctl vzquota ploop

reboot
</code></pre>

<p>Download template</p>

<pre><code>cd /vz/template/cache/ &amp;&amp; wget http://download.openvz.org/template/precreated/ubuntu-12.04-x86_64.tar.gz
</code></pre>

<!--more-->


<h2>Creating and running container</h2>

<p>Create container (101 is container ID, must be > 100).</p>

<pre><code>vzctl create 101 --ostemplate ubuntu-12.04-x86_64
vzctl set 101 --ipadd 192.168.2.101 --save
vzctl set 101 --nameserver 8.8.8.8 --save
vzctl start 101
vzctl stop 101
</code></pre>

<p>Some more useful commands:</p>

<pre><code>vzctl set 103 --onboot yes --save
vzctl set 103 --hostname host.example.com --save
vzctl set 103 --userpasswd root:passw0rd
</code></pre>

<p>For some reason it&#8217;s better to give IPs like 192.168 than 10.x (couldn&#8217;t get
containers to ping)</p>

<p>Something useful (on hardware node):</p>

<pre><code>vzctl enter 101
vzctl exec 101 "ls"
ls /vz/private/101/
</code></pre>

<h2>Internet access from container</h2>

<pre><code>IP=$(/sbin/ip -o -4 addr list eth0 | awk '{print $4}' | cut -d/ -f1)
iptables -t nat -A POSTROUTING -s 192.168.2.0/24 -o eth0 -j SNAT --to $IP
</code></pre>

<h2>Expose container port to outside</h2>

<pre><code>OUTER_PORT=11111
INNER_HOST=192.168.2.1
INNER_PORT=80

IP=$(/sbin/ip -o -4 addr list eth0 | awk '{print $4}' | cut -d/ -f1)
iptables -t nat -A PREROUTING -p tcp -d $IP --dport $OUTER_PORT \
         -i eth0 -j DNAT --to-destination $INNER_HOST:$INNER_PORT 
</code></pre>

<h2>iptables save</h2>

<pre><code>/etc/init.d/iptables save
chkconfig --level 53 iptables on
</code></pre>

<p>For more help:</p>

<ul>
<li>http://openvz.org/Quick_installation</li>
<li>http://openvz.org/Basic_operations_in_OpenVZ_environment</li>
<li>http://openvz.org/Using_NAT_for_container_with_private_IPs</li>
</ul>

]]></content>
  </entry>
  
</feed>
