awesomeprogrammer.com

Sharing ideas

Solving problems

Gathering solutions

Exchanging thoughts

Ruby On Rails

PHP

Postgres

Debian & Ubuntu
jQuery & CSS

Rails 3.2 to Rails 4.1 Upgrade

Let’s talk about pretty tedious task – upgrading rails, of course it can be interesting experience, but if you have relatively large application to upgrade it can be cumbersome, here are my thoughts after doing through process of switching Rails 3.2 to Rails 4.1.

Why My Code Is So Darn Slow?!

Slow code?

Ruby is very pretty, and unfortunattely it can be very slow. Beautiful syntax and flexebility of this language has its price (well, it’s not so bad compared to other interpreted languages anyway).

Let’s go over few (totally random) things that might cause performance issues.

How to Protect Your Website Against Spammers

Spam

When you’re running community-driven website sooner or later you will have to fight back spammers. There can be different kind of spammers, but the main question here is – how do we stop them from flooding your precious site?

Working Remotely

I must say time flies really fast. It’s been a while since I started my journey with working remotely full time. After moving from Warsaw to Cracow I’m working in Warsaw after all. I’m really happy that remote working (in general) is getting more and more attention (I guess you already read Remote?) and that companies start to see that huge office space isn’t always what makes employees happy ;).

Obviously everything have it pros and cons, but you won’t know if it works for you (no matter if you are a employee or employer) if you don’t try, right? I know some companies are still requires strict on-site presence, I guess sometimes it comes down to very basic thing – trust and (false) feel of control. In the end it’s not for everyone, but with the technology, tools and global Internet access we have nowadays it would be a shame not to give it a shot.

My Gems of 2013

I noticed that I ‘starred’ over 320 gems on rubygems.org. So I decided to do some cleanups there and while I’m at it – share with you few real gems that I like to use. So here it is – my tiny list that I called “My Gems of 2013”, mainly because it sounds catchy; a little bit of marketing didn’t killed anybody yet, I think.

I tried to avoid some, well, really obvious choices (like rspec, mocha, sidekiq, devise, resque, carrierwave, etc. – you get the idea) so maybe you fill find that one precious, very special thing that you will love ;–). Here we go.

Yet Another Chruby User

Few days ago I notice that RVM took over 8GB of my disk space for various gemsets/rubies. RVM in general is a beast (20k lines of shell script, you kidding me?!) and I used it since I started my journey with RoR, it was great (hey, you can support rvm 2.0 if you want/can) but I decided it was time to look for an alternative. It was nice meeting you RVM, but it’s time to move on. So to speak.

Didn’t take much to find a real beauty. Thanks to postmodern I found just the perfect combination: chruby – to easily switch mri/rbx/jruby and ruby-install to install binaries with just one command. And all of this in like ~500 lines of code, total. Go to github, checkout docs and just try it out. You can integrate it with capistrano wit no problem, if you want to keep gemset-like functionality on your dev machine you can always bundle with --path option (./vendor/bundle will work just fine, similar to how —deployment option works).

REST API Client Server With Rails

Few days ago a new project was thrown in my face ;). And it was interesting I must say – extracting some heavy internals of existing application into internal API + external client (app), that could be developed further with some additional features.

First I spend few hours do to some research an just to experiment a little, I found this topic on stackoverflow (d’oh) that was quite useful. Obviously first I though of some MV* Javascript framework at first, AngularJS seemed like a great choice, but after messing with it for a while I concluded I won’t be able to learn it in given time-frame I had (sorry Angular, maybe next time!). I decided to go more ruby (backend) way – my weapon of choice was: Active Resource.

Debricking Buffalo WZR-HP-G300NH (Linux)

If you’re reading this you’re that means you don’t need further introduction to the problem, let go straight to solution then ;).

  • You will need some kind of firmware, apparently you can use official Buffalo firmware, official buffalo PRO (dd-wrt branded) firmware or just regular dd-wrt release. I used the first one – in my case wzrhpg300nh-176 (then you will be able to upgrade as usual, but for now let just get this one working again). Also you will need some kind of switch/another router, so you could connect both your PC and your bricked Buffalo to the same network.

  • Install the enhanced version of TFTP (sudo apt-get install tftp-hpa). Turn off you router. Setup static IP on your PC to of 192.168.11.2 / 255.255.255.0 Gateway: 192.168.11.1.

  • In terminal cd to the directory where you downloaded&unpacked new firmware. Type sudo arp -s 192.168.11.1 02-AA-BB-CC-DD-1A (you can use real MAC address of your router, but fake one should work just fine).

  • Now it’s time for TFTP:

1
2
3
4
5
6
7
tftp 192.168.11.1
tftp> verbose
tftp> binary
tftp> trace
tftp> rexmt 1
tftp> timeout 60
tftp> put wzrhpg300nh-176 # this is the filename of downloaded firmware
  • Power up your router and wait for tftp to do it’s magic. After a while you should start seeing some progress and shortly after it should be transferred to the router.

  • Give it about 6 minutes to boot up. With a little bit of luck your router should be alive again.

More references: 1, 2. Good luck!

Migrating From Resque to Sidekiq

In a company I’m currently working we have been using resque to do some heavy asynchronous work. And well, that’s like obvious choice in Rails world – just go with resque, fork some processes and relax ;). But when you get to a point, when you need few hundred workers and few servers, you start to ask yourself – can’t you do it better?

You probably can. There are some pretty smart folks out there, who were so kindly to share their knowledge. And that’s how you can find sidekiq build on top of celluloid.

Sidekiq uses multi-threading, so you can leverage that even if you use MRI (that have un-famous GIL) – if you have a lot of I/O bound work you can still benefit from this great piece of software (even without need to migrate to JRuby or Rubinius).

API-like Gem for Fetching Data From quakelive.com

It has been a busy time for me lately, but I finally managed to release a small gem, that some of you might find useful.

You can download it from github or rubygems, I attached readme, that should be sufficient enough to start hacking. As you may already know ID Software unfortunately didn’t provided official API, so if you want to get some data from them, your only option is to crawl their site. And that’s what this gem basically is – it’s a small crawler with parser, packed nicely into nice ready-to-use gem.

I currently use it in production on quake.net.pl, and so far it worked really nicely :–).