awesomeprogrammer.com

Sharing ideas

Solving problems

Gathering solutions

Exchanging thoughts

Ruby On Rails

PHP

Postgres

Debian & Ubuntu
jQuery & CSS

Power to the Masses

You can’t deny docker hype isn’t going anywhere any time soon. For a software that is barely 3 years (!) old it have already made quite impressive impact in the widely known IT ecosystem.

I was fiddling with docker around a year ago for the first time and I wasn’t impressed (I won’t deny I’m mostly a consumer of open source world) – things did break, setup was awkward and tooling immature. But that changed. Oh boy it changed.

With software like rancher that basically allows you to setup containers via web ui (or it’s rancher-compose that consumes docker-compose /v1 atm/ config) you can spin enterprise-quality software within minutes – and it just works. Crazy how far it got within such short period of time.

It truly blows mind my mind that you can setup sentry or your own CI with just few clicks. And I guess that is were all the hype lies – as a independent developer, given the right configuration, docker gives you power to single-handed developer & ship to production piece of code with all necessary dependencies (obviously there might be existing architecture limitation involved, but that’s a different story).

Sure there are some security-related concerns to be taken into an account (I recommend checking best practices), but overall I think times are bright.

Put Some Go in Your Ruby So You Don’t Rust

Lately I have been looking for some solid alternatives to Ruby, and I must admit up-front – Rails spoiled me, badly.

I was hungry for some performance boosts, and let’s face it – dynamically typed languages can get you until some point.

I played with few popular modern languages (manually dealing with memory management? No thank you sir) and tried to hook them into Rails application.

How to Alter Big Postgres Table

Lately I had to migrate pretty fat (300GB+ data and 150GB+ of index data) postgres table – application grew, we had to get rid of one pretty big column that was redundant now, change main composite index, change one column type etc. etc. The problem was – do it without significant amount of downtime.

You can google up tons of solutions, but let me walk through approach I chose – hopefully you will find it somewhat useful.

Getting the Best of Your Rails Continuous Integration

You’re using CI? Great! You are not? It’s perfect time to start ;–).

Continuous integration (along with continuous deployment) is pretty simple and pretty awesome idea. Can basic setup where you simply run tests, and assuming tests passed whole thing gets deployed into production server(s) be done better?

Lately I gave some thought to the whole deployment process in our company. The whole development process in fact. I think todays web development got soooo complicated when compared what it was few years ago. The scale is just much bigger, everything is bigger, you operate on much more data, you use smarter tools that allows you to do more with less, but at the same time the amount of moving parts is higher and it seems easier to break.

That’s why you automate. Here are some tools that we added to out CI pipeline few weeks ago:

  • bundler-audit – to keep you informed about vulnerable gems used in your app. There is also interesting project/github repo called leaky-gems

  • erb-linter – assuming you don’t have 100% feature/view spec coverage it might be a good idea to simply check your erb files for possible typos

  • slim-lint – same thing for slim, even integrates with rubocop nicely

Speaking of rubocop – setting custom instance of hound worked great for us (with keeping coding style consistent and catching little things like unused arguments and such).

Those small additions can make your live a little bit better ;).

Graceful Unauthorized Pdf Redirect With Devise (Custom Failure App)

Let’s say your users are trying to access some pdf files that you’re serving inline with wicked_pdf or any other gem of you choice that is a wrapper for wkhtmltopdf. But they have to sign in first.

What happens when you use devise and you hit pdf url as unauthorized user? By default your app will respond with 401 Unauthorized which will get converted into invalid pdf file and this kinda not what you want. Probably ;).

Migrating From MacOS to Ubuntu

Reasoning

I’m not a huge fan of Apple products, been using mostly linux during my professional career (d’oh). I can appreciate the overall hardware build quality (well – at least when it lasts), easy of use (it just works) and all that jazz, but after working on MBA for two years I decided to look around for new machine that would serve me for another few years (hopefully).

WAN DHCP Mystery on Tomato Software

Lately I’ve been messing with my home network – long story short I ended up buying new router because my old Buffalo WZR-HP-G300NH was starting to having problems with wifi signal strength out of the blue. So I ended up with NetGear N300 v2 running Tomato by Shibby and a smaller one TP-LINK WR710N for the other room. And here is the kicker – none of routers was able to obtain IP address on WAN port via DHCP (after cloning mac address of wan port, as mac was filtered by my Internet provided).

I tried different configurations, different firmwares, but it seems like only my Buffalo (running OpenWRT) was working fine. After wasting hours and reading many forums I decided to check default udhcpc settings on OpenWRT very next morning and there I had epiphany – Tomato used different configuration, and to be exact two options were missing:

  • -t 0Send up to N discover packets
  • -CDon’t send MAC as client identifier

My solution:

  • go to Settings –> Advanced –> DHCP Client (WAN)
  • In DHCPC Options simply add -t 0 -C, click save and enjoy obtained IP address. I’m guessing this is required by some routers on the other end (didn’t bothered to dig deeper into this)

I hope this tip will save some time for some lost souls like me ;).

How I Failed to Create Vagrant-based Ruby on Rails Environment

Did you ever tried to solve a problem of unified development environment? It’s hard. I mean – seriously. ‘It works on my machine’ – how many times did you heard that?

So you have Vagrant or Docker or maybe some other brand-new-solution. With Vagrant you basically build a whole VM environment, with Docker it’s another story (assuming you’re running linux).

Personally I prefer using Vagrant, because with Docker – well, you still need Vagrant to run it on mac/windows. Of course you can be a hipster, and run ubuntu using docker on your CoreOs within Vagrant on MacOs (comment I read somewhere on the Internet that pretty sums it up). And that may have it’s pros that’s I’m refusing to see.

Extracting Form Objects in Practice

Did you get to the point where your model is over 1k lines longs and moreover stuffed with various concerns? If so – maybe it’s time to think about extracting so called form models (Ruby/Rails community always have fancy names for most simple things :p).

What is a form model? It’s simply a Ruby class (d’oh) that encapsulates logic related to a single operation. Dead simple example that comes to mind is some kind of a sign up process that exists in almost every web application.

Vagrant Setup for Multiple Subdomains Application (Dev Box)

Problem

Build a vagrant development environment that will serve an rails application that works on multiple subdomains. Moreover that application consists of multiple smaller apps that all are running with a single domain.

  • example.dev –> Application #1
  • app.example.dev –> Application #2
  • <any other subdomain>.example.dev –> Application #3

Let’s assume we’re using .dev domains, because we’re used to pow. Meaning those routing should work within vagrant machine and same subdomains should work exactly same way on our local machine.