Posts

Showing posts from 2015

Subscribing to your VK friends Instagram

Image
Story So I decided to create an Instagram account. There you can do 2 things: post photos and watch photos of others. While I do not have an answer for you what to post (you may photograph your food or big abs in a mirror), I do have one on whom to follow. Probably if you are Russian like me you have a VK account and chances are your friends have linked Instagram on their pages. I have 300+ friends so you can see why programmer in me decided to automate this process. Technical There isn't much to it, we need a headless browser and a pretty straightforward Ruby script. Code can be found on Github, just open my vk_to_instagram repository.

High Performance Browser Networking - Book Review

Image
I will try to make it concise and give my personal opinion. Author: Ilya Grigorik, a Web performance engineer at Google Pages: 408 Published: September 2013 Amazon rating: 4.6/5 My rating: 4.1/5 This piece of writing has many levels to it. Ilya goes over all the building blocks which play part in Web performance. He briefly describes work mechanisms for each block and then based on acquired knowledge shows how to squeeze as much as possible out of it. The fact that Ilya goes all the way from TCP / Mobile network work principles to Javascript API is both an upside and a downside. Many Web developers don't care about such level of detail and are only worried about steps they can do at the top of the stack, not server side TCP tweaks and peculiarities of different Mobile networks. Nevertheless, if you are like me and you prefer deeper knowledge I advise you to read the whole book. If what interests you is only the top of the stack and you have few coins

Seamless ActiveRecord Model extension

Image
The Problem What if you have one very bloated model, like User, that has a ton of fields you use only once or twice in your whole application and yet paying price for it every time you fetch / create a new one. In this case what you want is to move some of these fields to another model (e.g. profile or user details). The Solution First step is to generate another model, let's name it UserProfile and link it to User model. You would also have to run a migration that adds UserProfile to all existing users. Now what you can do is to write something like: Now, of course, we could stop there, but why miss all the fun? What we want to do instead is: So how do we do that? Performance When I measured how speed and memory footprint correspond to number of columns I found that both increase roughly linear as number of columns grows. Precautions When mass-assigning attributes from controller while using CanCan gem (tested in Rails 3.2), e.g. (User.new(params[:user])), CanCan

Parsing HTML generated outside of Angular

Image
It often happens that you have to work on some old project using jQuery. But in modern Web Development jQuery just doesn't cut it. So you write new features in Angular. But sometimes you have to modify existing code. It's not a problem as long as HTML is static, but if it's generated on server side Rails+jQuery style, then Angular won't know anything about it when it arrives to a browser. So we have make Angular parse this HTML. I remember a long time ago when I first encountered that problem I googled quite a lot but came up empty handed. So I had to find a way myself. Recently my colleagues stumbled on the same problem so I decided to share this little piece of code on the internets. Well... That's pretty much it. You shouldn't try running your angular app again. It's going to create a separate application. Also I want to share an interesting gotcha. If you inline your angular templates with <script type="text/ng-template" id="the