Minitest with Kaminari

While converting my tests from FactoryGirl.create to FactoryGirl.build_stubbed, I ran into trouble with Kaminari. Here’s how I fixed it.


Kaminari functions by adding .page() (and some other methods) at the end of your ActiveRecord call chain. A typical example of paginating via Kaminari is as follows:

class UsersController < ApplicationController
  def active_users
    @users =[:page])

This is a problem when you’re trying to stub out the return of the AR call to return an array. Here’s a corresponding test that would fail:

require 'test_helper'

describe UsersController, "#active_users" do
  test "success" do
    users = FactoryGirl.build_list :user, 3
    get :search, term: "admin_user"
    assert_response :success

Because users is just a regular array here, and Kaminari tries to call .page() on the array, it would fail with a NoMethodError: undefined method `page’ for # because Array#page isn’t defined.

Trying to stub out .page() by users.stubs(page: users) would give you ActionView::Template::Error: undefined method `model_name’ for #. And so on, as long as you’re using Kaminari-specific methods.

The solution

The solution is pretty simple (but took me 2+ hours to research). Call Kaminari.paginate_array on the FactoryGirl.build_list.

users = Kaminari.paginate_array FactoryGirl.build_list :user, 3

From the documentation:

Kaminari::paginate_array method converts your Array object into a paginatable Array that accepts page method.

For now, I’m putting the Kaminari.paginate_array inside the test, but long term, it makes sense to put it in the controller code. This way, even if we change to return an array, no other code would break. Then again, that’s why we have tests, right?

Protein Bar Attempt #2

After almost 2 weeks, my protein bars attempt #1 are finally done so I mixed up a new batch with the following recipe:

  • 300g Quaker Oats Quick Cook Oatmeal
  • 3 scoops Optimum Nutrition Double Chocolate Flavor
  • 340g Ludy’s Sweet and Creamy Peanut Butter
  • 250ml Surebuy Coconut Cream

This batch turned out better than last time. The consistency is closer to what I want.  For now, this will be my go to recipe. I’ll probably play around with using a different brand of peanut butter and/or oatmeal.

Where there was smoke (Me and my friends’ fire survival story)

As some of you probably already know, there was a fire at Prince David Condo, a building in front of Ateneo Friday afternoon.

What most of you probably did not know, my friends and I was there. We were at the top most floor, right below the roof deck.

Photo lifted from
Photo lifted from

Thankfully, we all survived.

Here’s our story, from my POV.

Continue reading “Where there was smoke (Me and my friends’ fire survival story)”

High Protein Vegetables Tuna Recipe

I’ve been cleaning up my diet lately. One of the hardest things that I’m constantly facing is getting more vegetables in my diet. Next to that is getting my daily protein needs.

I discovered a hack (sort of) that addresses both, doesn’t take much time and is financially viable for my budget. The secret is canned vegetables and canned tuna. It’s not ideal, I know, but it’s better than nothing.

Here’s one of my favorite combinations (that I just had literally minutes ago): Continue reading “High Protein Vegetables Tuna Recipe”

Homemade No-bake Protein Bar Notes

I followed this homemade no-bake protein bar recipe. Here are my notes on it.

  • I used the following brands:
    • Coconut cream: Surebuy
    • Whey Protein: Optimum Nutrition, Double Chocolate Flavor
    • Peanut Butter: Ludy’s
    • Oatmeal: Quaker Oats Quick Cook Oatmeal
  • I only had 200g of oatmeal so, initially, I halved the recipe.
  • It looks like the oatmeal absorbs too much of the “wet” ingredients that 200g of it warranted the full recipe.

The modified recipe is as follows:

  • 200g Quaker Oats Quick Cook Oatmeal
  • 76g or 2.5 scoops Optimum Nutrition Double Chocolate Flavor
  • 1 tbsp Honey
  • 340g Ludy’s Sweet and Creamy Peanut Butter
  • 250ml Surebuy Coconut Cream

I’ll know for sure how it would taste like tomorrow when the bars freeze over, but the ones that stuck to my hands while I was mixing it would suggest that it should be good.


Now I’ve had a couple of bars, I can comment on the taste and texture.

I was satisfied with the taste. Peanut butter with some hint of coco. I couldn’t separate the chocolate flavor at all.

The texture was okay, though I’d like to improve more on it. It turns out that 200g of oatmeal wasn’t enough to accommodate the rest of the wet ingredients. I’ll probably bump it up to 300g, but definitely not 400g. I’ll play around with other “fillings” such as almonds, granola, etc.

Based on the rate of consumption, I guess one batch would last me a week and a half. The ingredients costed me, maximum Php 250, not counting the protein powder. Not bad.

Fair programmer market value

I sometimes get asked “As a programmer, how much is my per hour rate?” or in another form “What’s my market value?”

The simple answer to this is that your market value is whatever price you agree to get paid for. That sounds like very passive so I’ll rephrase it.

Some people would say I'm overpaid, but I'm not. I'm paid exactly what the market will bear, which means I'm paid what I'm worth. - s2e04
Some people would say I’m overpaid, but I’m not. I’m paid exactly what the market will bear, which means I’m paid what I’m worth. – s2e04

Anything’s value, according to a market, is the highest price someone is willing to buy it at and the lowest price someone is willing to sell it at. It’s what we call the market clearance.

Your value is whatever price you agree to sell yourself at. If your price is above market clearance, then you might be overpriced. If your price is below the market clearance, then you are underpriced.

I would argue that on a personal level, the market clearance should not matter much on fields where there are massive demand and not enough supply (e.g. programmers). The market can usually bear the price.

Then the matter of market value becomes agreeing upon a price and that increasing your market value is simply agreeing to a price higher than your current.

Setting a higher price is simple, but not easy. What makes it so hard to ask for more?

Of cats and cups

Everything in this world is a duality. It’s both something and nothing, ethical and unethical, rational and irrational, good and bad.

The secret to happiness and success is by realizing that the world is both black and white and that humans interpret which shade of gray it is.

The cup is both alive and dead and the cat half-empty and half-full.

It’s not just money.

I don’t really want to post this because I believe that people do not deserve to hear about other people’s drama but I think it’s just gotten really unbearable for me. So, bear with me.

It’s been more than half a year now and I’m near broke again. This is the 5th time this year, I think. I don’t know, I’ve lost count.

Continue reading “It’s not just money.”

9 Things to keep in mind when making a decision

I’ve had the ‘privilege’ to make some difficult decisions in my life (with more to come). Some of them were decisions that brought me a lot of opportunities. Some of them were mistakes that I just have to live with. Regardless, I don’t have a lot of regrets.

Here are some of the things I try to keep in mind when I make a decision:

  1. Good data does not guarantee a good decision.
  2. You will always have incomplete information.
  3. Always take into account opportunity cost.
  4. A true binary option decision is rare. Look for a third option.
  5. Not deciding is a decision in itself. At least acknowledge that you’re deciding to not decide.
  6. You make the best decision based on all available information that you have and then face the consequences, good or bad.
  7. Good or bad is in the eye of the beholder.
  8. No decision is really final. Even supreme court decisions can be overturned.
  9. You are human. You’ll make mistakes. Don’t beat yourself too much.

Mac OS X: How to change your network settings based on Wifi SSID

Ever since I’ve seen Mac OS’s Location profiles (I think it was 2007), I’ve been wondering why the hell GNU/Linux didn’t have something like that. It was really convenient.

About a year after (maybe), Ubuntu switched to using NetworkManager which had something better: network profiles tied to the wifi network. Now I’m on Mac, I’ve been wondering why doesn’t Mac do that?

Good thing that the Internet fixes this.

I found this script through this SuperUser question.

Install it via Terminal by:

cd ~
git clone
cd wifi-location-changer
cp locationchanger /usr/local/bin
cp LocationChanger.plist ~/Library/LaunchAgents/
launchctl load ~/Library/LaunchAgents/LocationChanger.plist

If you don’t have git, you can copy the scripts below and save them in the paths provided with respective filenames:
Continue reading “Mac OS X: How to change your network settings based on Wifi SSID”