Photo - Qihuan Piao

Hi I'm Qihuan Piao, I'm a Rails developer and I like to make stuff.

Here I share articles and tips about web development, inpirations and thoughts I get from books and daily life.

I believe that English is a MUST skill for me to become a great engineer, so I’m trying to to write posts in it these days.

Reading Materials For OOCSS, BEM And SMACSS

After all these years of web development I still haven’t found a compelling way to organize and name css, once we all seemed to agree with the semantic naming methodology but as the project grows the magic aura disappears.

Recently my team has started the transition to apply OOCSS, SMACSS and BEM techniques to current project. I tried it a while and really think this is the best way so far to cleanly organize your css(code and files), make it scalable and reusable, with simple intuitive naming methomelodgy.

Recommendations

Here are the reading materials I found pretty easy to follow:

Organizing CSS: OOCSS, SMACSS, and BEM - MattStauffer.co

High level introduction to each terms, with simple example. Read it and you’ll get the big picture.


MindBEMding – getting your head ’round BEM syntax – CSS Wizardry – CSS, OOCSS, front-end architecture, performance and more, by Harry Roberts

Have an excellent guide on when to use BEM and not.


The Pros and Cons of Modular Sass — Planet Argon Blog

Great article on the idea behind modular css in general. And the argument over semantic class names convinced me.

Semantic markup is important in communicating the meaning of a webpage and is only becoming increasingly important; however, class names are for the developer. The exception to this relates to the use of microformats, in which case it is necessary to use specific semantic class names. It’s always important to consider names and what they communicate to you, your team, and future developers, but there is no dogmatic reason to avoid classes like “grid-1” or “pull-left” just because they describe presentation. People have conflated the use of semantic HTML (which relates to optimizing content for assistive technologies, browsers, the multitude of devices, and software that recontextualizes and reframes your content) with avoiding presentational class names for years, and I’m not quite sure why.

Support for BEM modules in Sass 3.3 | Mike Fowler

How to write BEM in Sass.


Full Stack Radio - 1: Matt Stauffer - CSS Semantics

A podcast. You’ll get more out of it if you already some idea and experience about these terms, as in the podcast there’re deep discussions on the very details of daily development.


That’s it. Hope this could help you find your starting point.

CSS

My First Personal Quarterly Off-site

Get Yourself Back In The Busy World

I tend to believe I know what I’m doing, where I’m going, I’m in the control of my life, but that’s not the truth and it’s really easy to derail from the path you committed to go by living with a demanding work and all sorts of unknown encounters.

The most dangerous thought you can have as a creative person is to think you know what you’re doing. - Alan Key

I think I found a good way to organize and regain the control of it.

Review For Yourself

If you work on a corporate company you must be familiar with the annual or quarterly performance review and evaluation, often times it’s mandatory, and it’s officially scheduled in your and your organization’s calendar. Process varies but I always feel that’s not really reflecting myself, that’s only a tiny part of the professional work, why don’t I do it for myself not for anyone else, to tru?

So last Friday I took one day off for this “Personal Quarterly Off-site”, to review my last 90 days of personal and professional life and set goals and plans for next 90 days. The end result was so great, I got way more than I expected, never thought I could get that much out of myself. Besides the basic concept, I’ll also share the process and tips I found that works for me.

What Is Personal Quarterly Off-site

I heard it from the podcast, Greg McKeown the author of the best selling Essentialism: The Disciplined Pursuit of Less, which is one of my favorite, introduced his idea of it.

Every 90 days, you take a day. You evaluate what you’ve been doing during the last 90 days. You have what I call the most important hour of your life, which is when you go through a set of questions. Then you set your (very few) goals for the next 90 days to make sure you’re in alignment with what you really want to do ultimately with your life. This is it.

Strategy 1: Schedule it

This is the first step and perhaps the most important step. I didn’t do it immediately after I heard the idea, even though I felt interesting. I intentionally scheduled it for 1 week later, and told my boss I’m gonna that day off in advance.

Until that day I chose some of my favorite podcasts, book highlights and articles to read related to the topic, by consciously telling myself, that day is coming and I’m gonna do some serious work, I was able to let my brain be prepared subsconciously. It builds up the right mindset in the downtime too. I also shared that schedule to get some peer pressure.

One thing needs to mention, very soon there’s a deadline in my current project, it wasn’t easy to bring it up in this season and I did feel somehow guilty about being absent while others working hard to meet the deadline. But let’s admit there’s no perfect time you could work less, there’s always something that needs you to look at, but only you can be responsible for yourself, in professional and personal. So this time I was bold enough to take the chance.

Strategy 2: Set the Environment Right

How many notifications do you get every single day? It’s so easy to “connect” to something that doesn’t really matter at that time but “disconnect” to something you really want to focus. So strategy No.2 is to turn off your phone. It’s easy to turn on the “Do Not Disturb” mode in iPhone.

Then go to somewhere you’re familiar with, where you won’t be disturbed by new “discoveries”, like the big SALE label in the store, or completely lost that you have to look up your phone to locate yourself. Maybe one of your favorite cafe would be the best at first. I found it’s easy for me to concerntrate and get serious work(thinking) done when I’m in the place where I’m really familiar with. It helps me to build up the routine and get into the “zone” so be conscious about the place would be helpful next time.

Strategy 3: Be a Journalist

The key point is to become a journalist, to ask good questions to yourself that drive you to focus on the essential area of your life, and don’t rush to answer them first.

Often times as an engineer when I hear a concern, issue or trouble I tend to quickly response with a possible solution. But this time I need to shut down that if-then thinking, to allow myself to dig deeper, pause and think more. I think you’ll be surprised too how much you could get just by pausing for a while.

Here are the questions I asked to myself:

  • For the last 90 days, What is the news in your life?
  • What are the top 3 things bothering you the most?
  • Where are you spending your time and resource?
  • What is essential to you?
    • Identify your roles
  • If you have full control of a weekday, what would you do?
  • What is your main focus and goal for the next 90 days? List 3.
  • What are the top 3 things you know for sure those are gonna improve you, make you grow, but you aren’t doing? What’s holding you back?

I had some blur images but I definitely didn’t prepare all questions, most of them were improvised at the time, or should I say I plant the idea 1 week ago and had exactly what I expected.

Strategy 4: Set A Timer

I set a timer for 2 hours before I started writing the first question. When I finished I was right on time and I felt that’s the right amount of time needed.

It’s not a competition, it’s not more you write/ask/answer the more you gain. The process and experience is sharable but the end result is not, it’s for yourself, so don’t try to get more done during the process. Remember the “Less But Better” principle.

Strategy 5 Digital-less

I did this with a real pen and notebook. Even though I turned on “Do Not Disturb” on my phone, and I did bring an iPad with me, I still like the feeling of writing on physical paper.

It’s easy to get distracted on digital devices. For me I always care about the styling, spelling and using the right tool, which really doesn’t matter that much.

Plus the physical note has a limitation, you can’t write endlessly on one page, which conversely set a boundary to keep you on the right course. I brought a B5 size kinda small notebook in which I tend to answer each question within 1 page, that limitation forces me to describe more precisely and not to bring up everything. Compare to that digital note is border-less and “cheap”, even though it shows Page 1 and Page 2, navigation is so “effortless” that it won’t occur to you that you have written “too much”.

Strategy 6: Reschedule It for the next time

After I finished it I felt much better, I’ve dumped lots of concerns and worries, set only few goals for the next 90 days, moved some of the actionable items to OmniFocus(my GTD/TODO app). The next thing I did was to schedule the next Personal Quarterly Off-site on my calendar, to reinforce the benefits of Strategy 1 and be more aware the importance of having such kind of self retrospective day.

Final Thoughts

Although whole thinking and writing process only took 2 hours to finish, I still think utilizing that whole day to build up the mindset, to allow yourself to pause, to wander is critical for creativity. If you feel like you’ve got lots of tasks done but not moving towards your goal, maybe it’s time to do something good for yourself.

Notes on Making Peace with an Unexpected Life

Sharing some takeaways of my favorite podcast, SEASON 3, EPISODE 9: MAKING PEACE WITH AN UNEXPECTED LIFE, hope this would help me and others to feel a bit better in the unexpected, unknown life.

Sometimes you have to make room for what’s unexpected because there’s a miracle there. - MICHELE CUSHATT

Gratitude

My favorit part starts from 9:52.

There have been quite a few ups and downs and twists and turns. Well, gratitude in many ways is my lifeline, because when you’re in a position where you’ve lost so much, where every time you turn around you’re losing something else, it can be very easy to focus on all that’s gone. I mean, it’s like you just look around and see carnage everywhere you look. You see all of these different things you’ve lost, things you will never get back, and there’s so much grief that’s a part of that.

The only way to push through grief really is to eventually come to some place where you see what you still have left. So I can either focus on all that I’ve lost or start to identify and recognize what I still have.

That’s not easily done. So I don’t want it to sound trite. I mean, that’s work. That’s serious work, but part of my surgery meant I lost some function of speech. I lost some function of eating ability. I lost my ignorance, being able to naively live, thinking that cancer wouldn’t happen to me, that it only happens to other people. I lost all of those things, which were huge things to grieve. They were massive.

Or I could focus on the fact that, gosh, I have two legs that can go outside and go for a walk, and I have a family. How many people don’t have a family to support them through things like this? I live in the United States, where I have access to great healthcare. How many people don’t have that? I could just start making a list of all of the ways I was incredibly blessed. What it did was just kind of weigh the scales differently, so rather than it being such a huge weight of how much I’d lost, now all of a sudden the scales weighed pretty heavily with what I still had.

This Is Bigger Than Me. I Need Some Help.

One thing I want to say on that topic is that my thought was that I was weak. The fact that I had to do this meant that I wasn’t strong enough. The question I kept asking myself was, “What’s wrong with you, Michele, that you can’t do this? What’s wrong with you?”

That wasn’t the right question. I eventually learned how to be a little kinder to myself. “Well, of course you’re exhausted. Look what has happened.”, “Look what you’ve been through.”, “Look what has gone on.” To offer that grace to yourself a little bit more and understand that true strength is being willing to say, “Okay, this is bigger than me. I need some help,” is important.

Overall Whole

If we look at just one particular chapter, one particular scene, we can get really overcome with the weight of what’s happening in that moment, but if we can step back and see the overall transition and flow of the story that’s taking shape in our lives, all of a sudden it becomes something that’s quite a beautiful piece of art. But you just can’t look at it one slice at a time. You have to see the overall whole, and when you do, you’ll realize there is an artist who’s weaving all things together for some kind of glorious end, and you get to experience it, but you have to step back and take that kind of vantage point.

古巨基唱出的匆匆那年

匆匆那年的电影我是有去国内的电影院看过的,可惜当时正片刚结束伴随着王菲的匆匆那年,辛勤的工作者们就迅速的开启灯光并挥手指示“出口在这边!”就把观众给疏散掉了,没机会好好听一听。

后来听到古巨基在《我是歌手》里演绎了男声版的匆匆那年,觉得真的是很有感情。用她的话讲就是,王菲唱出的是经历后的美丽,而古巨基唱出的是经历中的痛苦。古巨基谈这首歌的时候说,关键词就是两个字,遗憾。歌词很美,中文很美,故事很美,却是美的遗憾。

匆匆那年

(电影《匆匆那年》主题曲)
作词:林夕
作曲:梁翘柏
演唱:王菲

匆匆那年我们究竟说了几遍
再见之后再拖延
可惜谁有没有爱过不是一场
七情上面的雄辩
匆匆那年我们一时匆忙撂下
难以承受的诺言
只有等别人兑现

不怪那吻痕还没积累成茧
拥抱着冬眠也没能羽化成仙
不怪这一段情没空反复再排练
是岁月宽容恩赐反悔的时间

如果再见不能红着眼
是否还能红着脸
就像那年匆促刻下永远一起
那样美丽的谣言
如果过去还值得眷恋
别太快冰释前嫌
谁甘心就这样
彼此无挂也无牵
我们要互相亏欠
要不然凭何怀缅

匆匆那年我们见过太少世面
只爱看同一张脸
那么莫名其妙那么讨人欢喜
闹起来又太讨厌
相爱那年活该匆匆因为我们
不懂顽固的诺言
只是分手的前言

不怪那天太冷泪滴水成冰
春风也一样没吹进凝固的照片
不怪每一个人没能完整爱一遍
是岁月善意落下残缺的悬念

如果再见不能红着眼
是否还能红着脸
就像那年匆促刻下永远一起
那样美丽的谣言
如果过去还值得眷恋
别太快冰释前嫌
谁甘心就这样彼此无挂也无牵
如果再见不能红着眼
是否还能红着脸
就像那年匆促刻下永远一起
那样美丽的谣言
如果过去还值得眷恋
别太快冰释前嫌
谁甘心就这样彼此无挂也无牵
我们要互相亏欠
我们要藕断丝连

Sorry I Failed to Give You A Complete Family

“Sorry I failed to give you a complete family”. I heard it from both my mom and dad, from time to time.

Every time I go back China, I’m actually scared in some level to spend nights with either of them. I could sense it, “Oh my god he/she is gonna bring that again…”, then we all drowned in the emotional flood.

Although I do refer to them as a convenient “excuse”(joke) for my inappropriate behavior or inability of communication, in my heart I never ever blame them for anything. But as parents with good will and intention, I guess they may never forgive themselves, I don’t like to see that kind of face…

Writing these because I had a dream this morning, for the 30 years in my life it is the first time to have such a dream seeing them being together, happy, smiling, doing things together, worrying about my marriage(this part is so real hah), I just can’t forget that warm feeling. If one day human technology is developed enough to make a machine that could control your dream, I might surrender to that.

Phew, what an emotional morning! And I won’t surrender! I was just being weak for now. And no such thing as a “functional family” so take it easy :)

One Pitfall About Saving Money

I consider myself strict at spending money. I would choose a station in 20 minutes walk distance over a 3 minutes one just to save less than 200 JPY yen. I would bypass a vending machine even though I’m thirsty but not buying a bottle of water. I would go into bathroom without turning on the light, and choose wearing more clothes rather than turning on underfloor heat to save electricity expense, the list goes on and on… (most of these habits are inherited from my parents, saving money is like a gene inside their body)

Some time ago I randomly picked up a book in bookstore, one chapter was about saving money. Can’t remember the exact word, but the general idea is this:

People who have the habits of saving money, tend to buy more and/or expensive stuff than they need, have low resist to the temptation, because they don’t know the joy of spending money, they think they have been suffered enough that they so deserve to have that one item.

That rings a bell. I do remember I say something like that to myself in the past when struggling with buy or not buy situation.

“Come on you’ve been working so hard, you definitely deserve this!”

“Look at others, see how they’ve spent money on drinks, clothes, parties, no harm to indulge yourself a bit this time!”

“It’s 50% off sale, you’ve got to buy something for yourself right?!”

And things I’ve bought under that mindset usually turns out to be a total waste: either I don’t like it, not using it anymore(like clothes), or over spec that’s higher than my need(pc parts).

Since I realized this pitfall, I’ve been really conscious about the conversations with myself. I stopped using the word “deserve”. Now it looks like this: “I choose to spend the money because of …, so that I could …, I’m 100% it’ll contribute to my …, I know it’s a clear YES, it’s a worthwhile investment, not because I deserve it, not because it’s on 30%, 50% or even 80% sale, not because I feel shy to say NO.”

I could be spending more money overall on food, books, self investment now than before, but that’s my rational choice & investment under conscious mind, with a purpose on health, learning, and self growth. Most importantly, I don’t feel the urge to indulge myself, the guilty when spending money anymore.

Review 2014

2014 has passed, this is the perfect season to write a personal review post. This one is organized in the perspective of family, relationship, friends work and self development.

Family

At the end of 2014 I took some day off and came back to China to visit my mom and dad. Probably 3 years since our last met.

As always my mom prepared everything for me: new clothes and coat, cloves, shoes(-20 degree in my hometown), good foods, money for me to use here… She kept all the gifts in the perfect shape I gave her before, always seek to connect, always support me… Amazingly I really can’t find any flaws from her as a mother, she’s perfect.

My dad is the same, so unique in his own way… I’m not a good talker just like him, we don’t talk that much, and don’t feel the urge to, which made me really relaxed, felt home. Sometimes I take the initiative and tell him my life in Tokyo, and after my talk he either suddenly leaves without a comment or change the subject completely to something he wants to talk about… And we’re totally fine about spending the time separately even though we’re in the same room, he checks his computer while I write blog, just like the old days.

Strangely for one moment I dreamed about, what if, what if they didn’t get divorced, how would it look like now? What if I look at the left there’s my mom, and turn right there’s dad? I know it’s 200% impossible already, but this is the first time for the last 10+ years I imagined such scene and I kinda want to say, “please don’t wake me up”.

Relationship

I remember early 2014 we were sitting at the dining table in our brand new house, having afternoon tea and cakes, enjoying the beautiful view from 27th floor and sharing stories to each other. That was such a peaceful picture in my memory, I wish I could freeze the time forever, I thought after all these years we finally managed to get the harmony moment, but we didn’t.

After that our relationship hit the bottom, it was the darkest time for me. I suffered a lot from distrust, every couple have fights and may even say some harsh words too, but nothing hurt more than distrust. I felt my character, loyalty and integrity was doubted, it made me feel all the things I had been fighting for was nothing, worthless. I started to ask the wrong questions. “Why me? Why shit things always happen to me? Why I can’t have a peaceful day? I’m not a perfect boyfriend but also not a bad guy shouldn’t I deserve a little better? Why I did nothing but is treated like I was cheating on her? It’s so unfair why?”

Question shifts focus. Asking the wrong questions could only drive you crazy, making all possible negative impacts, so stop. Pain is a powerful tool, if you can make good use of it. There’s a technique introduced in the book “Awaken the Giant Within”, saying if you want to quit your bad habit, you should link massive pain to that. In my case this trust issue was such a huge pain for me I don’t want to experience it anymore, ever. So I tweaked the questions like this:

“What’s the root cause? Am I misbehaved? Or lack of communication makes me appear suspicious? Is it related to our past issue? Is it her issue? Is it fixable? What could I do now on my side? What are my choices?”

Immediately my focus shifted to the present, and helped me made a big decision then. I’ll leave all that pain to 2014, 2015 I will have a better, brighter life.

Friends

I like to hang out with friends, but not doing good job at inviting them. Always reluctant to send the message. 8:00 AM, maybe they’re on the train. 10:00 AM they must be working. 12:00 AM they’re probably having lunch with colleagues. 6:00 PM, hmm maybe working hard to get things done. 8:00 PM maybe they’re enjoying dinner with family/friends. 10:00 PM maybe too late… I’m such a genius to find no good time to contact during a whole day lol!

And even though I’ve been living in Tokyo for 7 years, I still don’t get the distance with Japanese friends(not those have experience abroad). I consider some are good friends, but not sure how they feel about me, the distance is still there. Don’t get me wrong they’re good people, polite and kind, but that also confused me about where we are, and how to develop it to the next level.

On the contrary, I’m glad the “gaijin” group get together regularly. BBQ, Chicago Pizza, fireworks, Bounenkai. The psychological guard is low, people are more open, more casual, easier to talk to.

Also appreciate my friends in China. Every time I come back, they all manage to come no matter how busy they’re, give me the welcome party and farewell party within 1 week, I’m flattered. I’ve known each other for over 10 years, I’ve seen them from slim to fat hah, from a boy to a father, yet we still drink like a teenage, talk in the same way, as if time never passed us.

Work

One big challenge was building Cooksnaps widget which is integrated to food blogs with fancy features like user login, browse and like cooksnaps, leave comments, auto post to facebook wall, admin tools to manage visibilities, etc. I did heavy javascript project before but this time is different. It’s a 3rd party javascript widget running on the food bloggers blog, the code is part of a rails project. Challenging but fun! Third-Party Javascript, this book written by Disqus engineers helped a lot!

Another big project is Cookpad global, it’s like a database-less rails app, we’re using API to transfer all the data we needed. At first we were using a gem called Her to let the model have ActiveRecord like interface, but due to performance problems and lack of maintenance we shifted to spyke.

Oh and almost forgot that I switched to VIM from Sublime Text, felt like long long time ago :) The transition phase didn’t take long, I used janus for a quick bootstrap then tweaked the parts one by one everyday. Love it so much.

Self

Some achievements on personal development:

  • Established the habit of going to gym 3 times a week
  • Established the habit of writing a journal every day
  • Challenging Audible audio book(“challenge” because of my English skill is still not enough to catch all the audio)
  • Shifting to principle centered person, made first draft of personal mission statement
  • Become an amateur Youtuber: published a gaming channel now have 566 subscribers, 500k views, generated about $277 income, estimated watched time is 3 years 280 days in total.

The Number of 2015

2015 = 1024 + 512 + 256 + 128 + 64 + 16 + 8 + 4 + 2 + 1. Such a beautiful number isn’t it!? Happy new year~!

Good Things about Turning Into 30

三十而立

This year August I turned into 30, I wasn’t happy at all. In fact I was quite desperate. I felt I accomplished nothing, far away from who I expected to be. Now 4 months later, I finally managed to see the bright side, accepted myself and got physical and mental positive changes in life.

Gap Between Dreams and Realities

Turning into 30 is quite a big thing in China. There is a saying “三十而立”, directly translated to “a man should be independent [steadfast] at the age of 30”, nowadays it’s interpreted as financially independent, emotionally mature, have a good family to take care of. I was born and raised in that culture and unavoidably affected by it. When I was in high school, I dreamed about the day when I’m 30 I’d be mature for sure like a real adult, disciplined and principled, knowing everything about life, handle any tough situations well, have a lovely wife, a happy family, maybe even with 2 children, a boy and a girl, and doing my best job to protect them. Sadly none of these happened.

Goals are dreams with deadlines. Even though I had been working hard these years, but I didn’t make it like a real goal with concrete steps to make it happen. That explains why I ended up like this.

I didn’t celebrate that day, I wanted to write a post but couldn’t finish it because of the dark energy. Part of me was still refusing to accept the fact that I’m 30, I felt not young anymore.

Everything Has To Become Worse Before It’s Getting Better

So what would you do if you’re not happy about the situation? You simply change it. One thing I know for sure that if I take the action it would definitely make a positive impact but I’ve never done it yet, is exercise.

Unlike early 20s when I could play intense games 12 hours straight overnight then still manage to finish a whole day lesson in college, nowadays even 1 hour Starcraft II game would make me feel exhausted. Sleeping 7-8 hours is supposed to be enough but I still have to drag myself out of bed each day. I know there must be so many rooms for improvement.

I’ve read it many times in different places that exercise regularly will generate more energy and boost your creativity. Understand it is one thing, but taking actions is another thing. This time I showed no mercy to myself. I went to the gym near my place, asked the staff to give me a tour and immediately signed the paper for the membership. They was suggesting there’s a program will be available soon that I could use a coupon to join with relatively cheaper price, only thing I have to do is wait for it, but I turned it down said I want to do it now, today, I commit to do it, don’t wanna give myself any other chance to make any excuses. I know taking the actions now is way more valuable than the extra percentage of the price for me.

My goal is not getting big muscles to make myself looking better to attract any females, I want to regain control of my life, to know that I’m capable of improving myself, to have more energies to accomplish the essential things in the future. I have the clarity, I’m absolutely sure about the direction, everything else just naturally happened without any resistance. It was as simple as that.

I am planning to write another post about my routines about going to the gym and some extra benefits.

Keep The Ball Rolling

Another side effect of having physical exercise is paying more attention to health. I became more conscious about what and when to eat, not like before I ate whatever I wanted, whenever I wanted without limitation. Have vegetables regularly, try to have dinner at least 3 hours before sleep, push dishes away even though there’s some left if I know it’s enough already, etc. I’m still have little knowledge in this area so I’m also gonna take a cooking lesson to learn more systemically.

Also found myself have more time to read books. Reading is such an effective way to learn great thoughts from great people, asynchronously. It allows me to constantly revisit my past and recognize which part could have been done differently to have better result. One great thing for getting older is that you could find so many references from your past when reading, to fully explore the idea in your context, in your real experience.

By reading “The 7 Habits of Highly Effective People” I realized I had been living with impulse not correct principles, and that was why I was so weak to temptations, made several bad decisions and hurt the people around me. I followed the suggestions from the book and got my first draft of personal mission statement done. Whenever I have to make tough decisions it’s the reference for me to look up, who I want to be, who should I put first, what’s my responsibility. Decisions are never easy, but having correct principles guide me, it makes me look from the big picture, be more determined to my choice and commit to the result no matter it turns out good or bad at that time.

Willing to Think About Life Plan

I was never a fan of making long term plan. Even just think about it made me headache. “I just want to enjoy everyday and forget those complex things”, I said to myself.

But now I’m really willing to take the challenge. I know I actually like to plan things, like for a trip, for Christmas, even plans in games. What stopped me from planning my life, was the fear of the future. Family issues, relationship issues, unresolved conflicts, fear of the unknown… Made me feel stressed and overwhelming, so I ran away, used “just enjoy everyday” as the excuse.

Every family has a issue, so does relationship. You can’t run forever. I started to explore the options and possibilities, it wasn’t as hard as I expected. I could still breathe, it didn’t kill me. Be proactive, take the initiative also applies here. It has to be me to handle these things.

At Last

None of these changes require you to physically be the age of 30, but I surrendered to the fear of the future before and was unable to see things clearly, unwilling to deal with them, until now. For what it’s worth, I’m glad I overcame all the internal struggles, it’s never too late to make a meaningful life.

I’ll end with some of my favorite quotes:

Life is a gift, go make it count. - Michael Hyatt

The only true security in life comes from knowing that every single day you are improving yourself in some way, that you are increasing the caliber of who you are and that you are valuable to your company, your friends, and your family. - Anthony Robbins

Run DelayedJob Manually in Test Env

TL;DR

1
2
3
4
5
# in config/initializers/delayed_job_config.rb
Delayed::Worker.delay_jobs = true

# in your spec
Delayed::Worker.new.work_off

Common Setup of DelayedJob

Assume you follow DelayedJob readme example to configure it like this: Delayed::Worker.delay_jobs = !Rails.env.test?, what it does is in test env it doesn’t delay the job, meaning DelayedJob is being transparent, the job you put will be executed in “real time”. In most cases you don’t even need to worry about it, your test should be just fine, but recently it caught me…

It Fails When…

To give some background, I’m working on a API centric rails project. In order to authenticate with API we pass in access token for every request, and that’s done in the middleware layer. Since access token is stored in cookie, and in middleware we can’t access browser cookie directly, so another tool called RequestStore is used. If in the same request, what you stored in RequestStore you can access it later no matter the context, a unrealistic example would be you store a cookie value to RequestStore then use it in model later. Don’t do that :).

The code below is a simplified version to illustrate the flow.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
class ApplicationController < ActionController::Base
  before_action :set_api_access_token

  def set_api_access_token
    RequestStore.store[:access_token] = cookies.signed[:access_token]
  end
end

class Authentication < Faraday::Middleware
  def call(env)
    env[:request_headers]['Authorization'] = RequestStore[:access_token] if RequestStore[:access_token]
    @app.call(env)
  end
end

Every api request happened inside the rails ApplicationController stack should have the access token being set, but what would happen in a different context like rake task or DelayedJob where you need to send request to the API? The before_action is not gonna be executed there so RequestStore[:access_token] would be nil. This is an easy-to-spot issue if you try it once, but if you follow the TDD work flow and write test for it first, then it’ll fail you.

With Delayed::Worker.delay_jobs set to false in test env, the job will be executed immediately in the same request, so the RequestStore[:access_token] still contains the value and will pass to the Authorization header in the middleware, spec passed but but in real world env it failed. Typical false positive result.

To Run It Manually

1
2
3
4
5
6
7
8
9
10
11
# in config/initializers/delayed_job_config.rb
Delayed::Worker.delay_jobs = true

# in your spec
# here is the code to enqueue a job to DelayedJob queue
visit post_path(post)
# run it manually
Delayed::Worker.new.work_off
# expectation
expect(api_endpoint).to have_been_requested
end

Delayed::Worker.new.work_off returns an Array like [1, 0] indicating succeeded job counts and failed job counts. I’ve also seen some people testing against that like expect(Delayed::Worker.new.work_off).to eq([1, 0]), personally I don’t think it’s necessary.

  1. You have your own expectation right after that and that should be the main concern of the spec. If the job failed, your spec should be failed too.
  2. What if multiple jobs are enqueued while you’re only focusing one of them in the spec? Update the value to [2, 0]? That’s just noise.

I guess what I encountered is a rare case, but definitely an interesting case. I kinda prefer this way to mimic real world environment to prevent any possible regressions.

Commercial time: If you’re about to build a API centric rails app, be sure to check out the awesome gem called spyke made by @balvig, the slogan is “Interact with remote REST services in an ActiveRecord-like manner.”

Book “Essentialism - The Disciplined Pursuit of Less”

“Have you ever found yourself stretched too thin? Have you ever felt both overworked and underutilized? Have you ever found yourself majoring in minor activities? Do you ever feel busy but not productive?”

This book is about answers to these questions. The key messages and takeaways for me are:

  • Life is a tradeoff. You can’t have it all, therefore you have to choose, choose what matters the most. Less, but better.
  • You have to give yourself permission to say No to others, so you can say Yes to your goal and make highest contribution.
  • It’s not about getting more things done, it’s about getting the right things done. Effective over productive. I love this so much.

If You Don’t Have Time to Read it…

Here is a great video reviewing this book, and actually I started reading it because of this video. To be honest I think it might be arguably better than the book itself. If you don’t have enough time, just check out the video, should take you less than 25 minutes.

Chapters I Would Like to Read Twice

Part I: Essence: What is the core mind-set of an Essentialist?

  • CHOOSE: The Invincible Power of Choice
  • DISCERN: The Unimportance of Practically Everything
  • TRADE-OFF: Which Problems Do I want?

Part II: Explore: How can we discern the trivial many from the vital few?

  • SLEEP: Protect the Asset
  • SELECT: The Power of Extreme Criteria

Part III: Eliminate: How can we cut out the trial many?

  • DARE: The Power of a Graceful “No”

Part IV: Execute: How can we make doing the vital few things almost effortless?

  • PROGRESS: The Power of Small Wins

Overview

The first part, the “What” part, is really great. All the problems introduced there are so real, I could map literary everything to my real life. Very inspirational.

But sadly the following chapters, the “how” part, are less compelling to me. I agree with the general idea, it’s just the examples and evidences are not convincing enough.

Overall it’s a good book, I’d rate it 4 out of 5. It does give me positive energies and courages to improve my life, makes me pause to think about the past, which choices were made by “default”(others) and which were made by “design”(me), makes me think twice before purchase any non-essential items, makes me observe my bad habits & routines and fix them, makes me pursue less but better.

p.s. I didn’t title this post as “Book Review”, as I realized the word “review” is too big for me, makes me want to cover every aspect of the book, pros and corns, scan every note and highlight I made during the reading, that is overwhelming and will simplify stops me from writing. “Done is better than perfect”, indeed, the essential thing for me is to write this post and share my findings!