a very awesome tech blog

The official blog of super awesome full stack web developer

Code complexity and small objects

19 Jun 2015

When you have bunch of stuffs in your room, how do you organize things so that it is easy to find something when you need them? One way can be putting them into different chest drawers and boxes, then label them properly. This is easier than putting all the stuffs in one big box then try to find the ...

Using Google Docs as embeddable PDF reader

1 Jun 2015

I think it's still undocumented but Google Docs provides a very good embeddable PDF reader for any online PDF. You don't even have to upload the document to Google Docs to use this. ```html <iframe src"https://docs.google.com/gview?urlhttps://www.trustedtherapies.com/general_questions_for_my_doc ...

Vertical align of an element in CSS

28 Apr 2015

Vertically aligning elements in CSS is always a headache to me. Found a good solution from a blog. http://zerosixthree.se/verticalalignanythingwithjust3linesofcss/ The gist is: ```css .parentelement { webkittransformstyle: preserve3d; moztransformstyle: preserve3d; transformstyle: ...

Stubbing in tests with MiniTest

12 Apr 2015

```ruby def test_link_to_nav_for_active_links stub :controller_name, 'discussions' do active_link_html link_to_nav name: 'Forum', url: discussions_path inactive_link_html link_to_nav name: 'Webinars', url: webinars_path assert_equal active_link_html, ...

Using EXTRACT FROM timestamp to group results in Rails + PostgreSQL

12 Apr 2015

I had a table called `answers` and it has `created_at` timestamp column among others. How can I get all the records from the table grouped by week number of the year? The first idea that came to my mind was to use `group_by` method of Ruby. To do that I would have to run a query like this: ``` ...

Little tip for writing functional tests in MiniTest with MonBan

21 Feb 2015

If you have an app using [MonBan](https://github.com/halogenandtoast/monban) you might be using helpers like `current_user` in view layer. How do you write functional test for it? I ran into this error when I tried. ```ruby ActionView::Template::Error: undefined method `user' for nil:NilClass ...

Minimum and maximum values in Ruby array

8 Feb 2015

Ruby provides convenient methods to find a minimum or a maximum value in an array. ```ruby numbers [23, 20, 35, 3, 8] > [23, 20, 35, 3, 8] numbers.min > 3 numbers.max > 35 numbers.minmax > [3, 35] ``` Good stuffs! ref: http://www.rubydoc.org/core2.2.0/Enumerable.html ...