a very awesome tech blog

The official blog of super awesome full stack web developer

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 ...