RarestBlog

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? :)

image

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
    FULLY FUNDED

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

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

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

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

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
    }
  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()

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!

Yabla

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

image

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.

Mini Habits

Following the advise in the ”Mini Habits” book, I will try to make a new habit of writing to the blog.

Actually, “Mini Habits” 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’s more easy to do it than to figure out why should you not do it.

So for the blog posts at first the task was to “Write a blog post”, but that seems like a lot almost always, so eventually the task got to be “Write a 1-line blog post”.

Well, that’s quite easy. And it gets you started. And when you start doing something it’s harder to stop rather than continue, so you almost always exceed your original microscopic plan by far.

Also, ”Habit bull” is really a great app for Android to keep you on track with your new mini-habits.

Install CoreOS on Hetzner

1) Boot into Rescue

2) If you have previously installed RAID, disable it:

mdadm -S /dev/md0
mdadm -S /dev/md1
mdadm -S /dev/md2

3) Clean up partition table:

dd if=/dev/zero of=/dev/sda bs=100M count=1

4) Install CoreOS

cd /tmp

cat >cloud-config.yaml << '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

5) Reboot

6) You can now do ssh core@your-server.com