Rails Serialize JSON With Symbolize_names

Haven’t found a better solution

class Something < ActiveRecord::Base
  class JsonSymbolized
    def self.load(string)
      JSON.parse(string, symbolize_names: true)

    def self.dump(object)

  serialize :field, JsonSymbolized

Install Bootstrap 3 (and Font Awesome) on Rails

After a few hours of fighting with Glyphicons in twitter-bootstrap-rails gem, it’s just easier to install Bootstrap by hand..

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

Also Font Awesome:

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

And bootstrap 3 Theme:

wget http://getbootstrap.com/dist/css/bootstrap-theme.min.css -O app/assets/stylesheets/z-bootstrap-theme.min.css

Installing golang-1.3 on Linux X86_64

After this restart the shell (re-login to ssh)

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' >> /etc/profile

What Are the Chances That Two Random IDs Are the Same

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.

Given that our developers told me that it’s practically impossible that two items have the same ID in the same day… because… 100 million! ….and Probability Theory! :)

It’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!

I’ve found a neat calculator online and within a minute there was a result.

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.

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

Within 10 days you have 99% chance.

Mind-blowing, no? :)


Developing SaltStack With Vagrant

This is probably the fastest way to develop and test your SaltStack States.

0) Install Vagrant (via Googling)

1) Create ./srv/salt dir and ./srv/pillar dirs

2) Create Vagrantfile file:

BitCoin, Future and Crowd Financed Government

Today I thought about the way we pay taxes and BitCoin. The first thought was: let’s assume my employer starts to accept BitCoin and pay me salary in BitCoin. But then government has a problem - it can’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’s continue the thought.

Let’s imagine the taxes paying instead as a Crowd-funded State.

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

And then you have something like:

  • Local hospital
    €10 000 000

  • Payment for teachers in your state
    €3 200 000 of €5 000 000 collected

  • Payment for doctors in neighbour poor state
    €499 999 of €500 000 collected

  • War with neighbouring country
    €0 of €100 000 000 collected

  • Big Bank Bailout
    €0 of €700 000 000 000 collected

Obviously the prices are in € or in $ or any other state-issued money :) But that doesn’t mean that they can’t accept BitCoin for that.

And then you are free to distribute your funds as you see fit. Then all those programs that people don’t agree with - won’t get funding.

Now that’s some nice future that I want to live in! :)

It will probably be the first time I’d be happy to pay my taxes.

Grucrawler - Simple Crawler for Ruby

Released a generic Redis-based crawler for Ruby today. Very alpha. Use at your own risk.

Has throttling, concurrency and some limits, but that’s about it.

An example to parse a lot of Italian websites:

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

  def on_init(crawler)
    @crawler = crawler

  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; }

  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'


  def debug(message)
    #puts message.blue

  def log_info(message)
    puts message.yellow

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

c = GruCrawler.new(ItalianCrawler.new)
# c.reset() # deletes all memory of all events - useful for restarting crawl

API might change in future, so

gem install grucrawler --version '0.0.5'

for the example below to work.

Here, grucrawler

Why? I’ve got tired of my attempts to get to understand all the complex stuff that goes into configuring all other crawlers. Too complex. I’ve wanted something dead simple.

Have fun!

When You Try Something New and Fail

Today I realized something that probably many people realized before.

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’s not good and stop.

That’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’t give up and then I’ve became good at it.

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

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

Don’t give up too easy!


If you want to learn a language - go see Yabla (Spanish, French, German, Italian, Chinese).


I’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’s new!) and even slow it down.

Then there is “flashcards” 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.

Probably the most useful thing I’ve tried for languages.