I read in an article that “Working in fashion? Go to NYC. Working in Software development? Go to SF. It’s just that simple.”. By SF or other high tech scene places, I mean we can have opportunities to learn in the best universities, work with the best people, meet new friends in local meet ups, conferences, …

I see questions on Quora a lot on how to relocate to work in those companies, how to have eligible visa to attend bootcamp, conferences, …

But think for a while now, we already have access to all these things by other means, to a certain degree even if we ‘re not in the Bay Area. All we need is the the right attitude. So be positive and do effortful study. The world is more likely to be flat now

  • University: We can learn course from edX, Coursera, Udacity, …
  • Meet up: Some meet up talks push their presentations on Slideshare, SpeakerDeck
  • Conference: Some conferences (WWDC, Google IO, …) provide streaming and archived videos
  • Book: We can buy and read the same books. Recommended books for developers
  • Bootcamp: Some like Bloc, … have their bootcamp program available online
  • Chat room: Most of the chat rooms (Stackoverflow Chat, IRC, Gitter, …) are public
  • Tech talk, Web Seminar: Most allow us to join (Raywenderlich Tech Talk, SenchaTouch web seminar, …) on Google Hangout, …
  • Work: Some companies allow remote work and the trend is increasing. What Remote Working Means & The Tools We Use – Buffer’s Founder Chat Friday
  • Projects: We can learn and contribute to open source projects. Some companies like Artsy have “Open Source By default” in mind, and we can learn much from their work
  • Blog: Popular developers have blog. You can learn a lot by reading their blogs. What are the most popular software developer blogs/news sources?
  • Trend: Twitter is a good source for learning new trends in the community. And following popular people cost you zero
  • Network: You can connect with awesome people on Linkedin and share experience about your professional subjects

160 total views, 1 views today

iOS Asynchrony


Grand Central Dispatch (GCD) comprises language features, runtime libraries, and system enhancements that provide systemic, comprehensive improvements to the support for concurrent code execution on multicore hardware in iOS and OS X.

// Doing something on the main thread

dispatch_queue_t myQueue = dispatch_queue_create("My Queue",NULL);
dispatch_async(myQueue, ^{
    // Perform long running process
    dispatch_async(dispatch_get_main_queue(), ^{
        // Update the UI

// Continue doing other stuff on the 
// main thread while process is running.


A promise is an object that wraps an asynchronous task. Pass that object around, and write clean, ordered code; a logical, simple, modular stream of progression from one asynchronous task to another.

[self login].then(^{

    // our login method wrapped an async task in a promise
    return [API fetchKittens];

}).then(^(NSArray *fetchedKittens){

    // our API class wraps our API and returns promises
    // fetchKittens returned a promise that resolves with an array of kittens
    self.kittens = fetchedKittens;
    [self.tableView reloadData];

}).catch(^(NSError *error){

    // any errors in any of the above promises land here
    [[[UIAlertView alloc] init…] show];



A task represents the result of an asynchronous operation. Typically, a BFTask is returned from an asynchronous function and gives the ability to continue processing the result of the task. When a task is returned from a function, it’s already begun doing its job.

A task is not tied to a particular threading model: it represents the work being done, not where it is executing.

[[self saveAsync:obj] continueWithBlock:^id(BFTask *task) {
  if (task.isCancelled) {
    // the save was cancelled.
  } else if (task.error) {
    // the save failed.
  } else {
    // the object was saved successfully.
    PFObject *object = task.result;
  return nil;


ReactiveCocoa (RAC) is an Objective-C framework inspired by Functional Reactive Programming. It provides APIs for composing and transforming streams of values.

Rather than using mutable variables which are replaced and modified in-place, RAC provides signals (represented by RACSignal) that capture present and future values.

By chaining, combining, and reacting to signals, software can be written declaratively, without the need for code that continually observes and updates values.

    flattenMap:^(User *user) {
        // Return a signal that loads cached messages for the user.
        return [client loadCachedMessagesForUser:user];
    flattenMap:^(NSArray *messages) {
        // Return a signal that fetches any remaining messages.
        return [client fetchMessagesAfterMessage:messages.lastObject];
    subscribeNext:^(NSArray *newMessages) {
        NSLog(@"New messages: %@", newMessages);
    } completed:^{
        NSLog(@"Fetched all messages.");


  1. Taming Callbacks in iOS: Bolts Framework
  2. Asynchronous Operations in iOS with Grand Central Dispatch
  3. PromiseKit: Promises for iOS
  4. Recommended resources for learning ReactiveCocoa

155 total views, 1 views today

Recommended resources for learning ReactiveCocoa



GitHub Reactive Cocoa Developer Conference

Atomic Object

ReactiveCocoa Design Patterns



RAC Issues


304 total views, 1 views today

What define a good programmer?

I always found myself asking this question “What define a good programmer?”

I ask lots of people and the answers vary, they ‘re all correct for certain aspects

Good programmer is someone who has a solid knowledge of the “how-to” both in theory and in practices. Understanding customer requirements clearly and having a vision to fulfill it through dedication and execution !

Good programmer is one who has in depth knowledge of one particular major and wide understanding of many thing else

Algorithm (actually this is my definition)

But I think I find the answer now, it is “responsibility”.

Thanks Uncle Bob for pointing it out in his experience sharing “The Professional Programmer” in the book 97 Things Every Programmer Should Know: Collective Wisdom from the Experts

The single most important trait of a professional programmer is personal responsibility. Professional programmers take responsibility for their career, their estimates, their schedule commitments, their mistakes, and their work- manship. A professional programmer does not pass that responsibility off on others.

  • If you are a professional, then you are responsible for your own career
  • Professionals take responsibility for the code they write
  • Professionals are team players
  • Professionals do not tolerate big bug lists
  • Professionals do not make a mess

Although he talks about professional programmer, but my intention in “good programmer” term is the same as that

214 total views, 1 views today

Recommended books for developers

269 total views, no views today

Stupid Interview Questions

The original is http://exold.com/article/stupid-interview-questions but it seems the site if off, so I made a copy here as a reference for myself and those who need

I was reading a blog post on some guy’s programming interview, where he complained about being asked to write a file copy function. Now, while it’s quite possible to take umbrage at this, if I were in that situation, I’d see it as a chance for some free entertainment cool.

Q. What do you mean by “copy”?
A. Ummm…copy the contents of the file to a new file.
Q. What about the date/time stamps?
A. No, those don’t need to be copied.
Q. Does the result file have to have the same name?
A. No.
Q. Can it have the same name?
A. Umm…no.
Q. Do I have to worry about name spoofing? What about the Turkish I?
A. Don’t worry about that.
Q. Does it have to be in the same location? Note that if it is in the same location, it (probably) can’t have the same name. Unless you copy it to itself (another question…).
A. Yes.
Q. What about the attributes?
A. Make the attributes the same.
Q. Should I modify the attributes of the source file? If this file copy is part of a backup or archive operation, it’d probably be a mistake to leave the ‘Archive’ attribute on.
A. No, leave them as-is.
Q. What if the source file has the Archive attribute off? If I make it off on the new file as well, it could screw up the user’s backup software.
A. Just make it the same. I don’t care about the user’s backup software.
Q. Well, I’m not sure that’s the best approach to take when thinking about designing software FOR users, but if you say so.
A. …
Q. What about compression? It’s a file attribute, but the copy destination may not support compression.
A. Don’t compress the copy.
Q. Even if the source is compressed, and the destination supports compression?
Q. What about encryption? What if the source file is encrypted, but the destination does not support encryption?
A. Don’t encrypt the copy if the destination doesn’t support it.
Q. Mmmmm, sorry, don’t mean to digress, but…that could be a serious security hole. Especially if wherever this file copy function ends up supports arbitrary parameters (directly or indirectly).
A. Look, just copy the damn file.
Q. What about the file creator?
A. Don’t care.
Q. What about the file owner?
A. Don’t care.
Q. What about file permissions? Is there a separate way we should handle inherited permissions and assigned permissions?
A. Forget the permissions.
Q. What operating system will this function be required to run on?
A. Windows XP.
Q. Home, or Pro, or Media Center, or one or more?
A. Pro.
Q. What service pack level are we aiming for?
A. Service Pack 2.
Q. Does that mean we don’t have to support any other SP level?
A. Yes, fine.
Q. How will the source file name be supplied?
A. As a parameter.
Q. Is it going to be supplied as a null-terminated string, a counted string, or an object?
A. Null-terminated string.
Q. Is it possible that a NULL pointer will be passed in?
A. No.
Q. Is it possible that an empty string will be passed in?
A. No.
Q. Is it possible that a malformed string will be passed in (e.g., no NULL terminator)?
A. No.
Q. What encoding will the filename be in?
A. Unicode.
Q. Sorry, umm…Unicode is not an encoding, really. If we’re using Unicode data, it has to have a specific encoding, like UTF-8, UCS-2, UTF-16, etc.
A. Fine. Make it UTF-8.
Q. OK. I’d like to note at this point that it’s a bit of a pain to have to transcode UTF-8 to UTF-16 in order to be able to supply it to Windows API calls.
A. Fine! UTF-16!
Q. Big-endian or little-endian?
A. ARGH. Whichever you want!
Q. Should we accept relative paths, or only fully-specified paths?
A. Only full paths.
Q. Are there any characteristics of the paths we are supposed to accept that I can screen the parameters on?
A. No. The caller will do all screening of paths and file names.
Q. How will the destination file name be generated or supplied?

Q. Am I required to support (or allow) an asynchronous copy operation?
A. No.
Q. How should I report errors? Exceptions? Error codes?
A. Whatever.
Q. Should I try and handle exceptions from called functions internally, or let them pass through to the caller?
A. Err…let them pass through.
Q. What if the destination file already exists?
A. It won’t.
Q. So the caller ensures that?
A. Right, sure.
Q. So if it does exist, I can just terminate the program, then? Obviously this would be a violation of preconditions, and who knows WHAT is going on.
A. Sure, whatever you want.
Q. What about alternate data streams?
A. Do whatever you want!
Q. Look, I’m sorry if you feel put-upon here, please don’t get hostile. I’m just trying to get a clear picture of the specs I need here. Obviously if I’m going to write a file copy method, instead of using one of the many extant file copy routines in various libraries and frameworks, it’s going to be fulfilling a specialized set of requirements, and I’m going to need to have good answers for these questions. If you want, I can hack something together in a minute, but I’d have to note that there were many unresolved issues as to requirements and purposes.

Mission accomplished. wink

213 total views, no views today


Develop the nature of you

  1. Effective Programming: More Than Writing Code
  2. The Ultimate Code Kata
  3. Becoming a Better Programmer
  4. The Clean Coder: A Code of Conduct for Professional Programmers
  5. Professional Software Development: Shorter Schedules, Higher Quality Products, More Successful Projects, Enhanced Careers
  6. The Pragmatic Programmer: From Journeyman to Master
  7. The Passionate Programmer: Creating a Remarkable Career in Software Development
  8. Peopleware: Productive Projects and Teams
  9. Coders at Work: Reflections on the Craft of Programming

207 total views, 1 views today


Learn to get trusted

  1. Effective Technical Leadership
  2. Elastic Leadership
  3. Talking with Tech Leads
  4. Notes to a Software Team Leader
  5. Becoming a Technical Leader: An Organic Problem-Solving Approach
  6. The Geek Leader’s Handbook: Essential Leadership Insight for People with Technical Backgrounds

205 total views, 1 views today

Understanding new code base

This post contains some tips I found useful when navigating to a new code base. Some may overlap with each other, but you know the point.


This is the best library for Aspect Oriented Programming on iOS. Furthermore, its hooking system is useful

For example, this allows you to know which ViewController you are in

[UIViewController aspect_hookSelector:@selector(viewWillAppear:) withOptions:AspectPositionAfter usingBlock:^(id<AspectInfo> aspectInfo, BOOL animated) {
    NSLog(@"View Controller %@ will appear animated: %tu", aspectInfo.instance, animated);
} error:NULL];


This allows us to easily detect which views we are seeing. I see that it’s much better than Xcode 6 View Debugging. I don’t like the idea of a massive storyboard with lots of ViewController in it, so I don’t look at storyboard first.

[[FLEXManager sharedManager] showExplorer];


LLDB is good, and it’s much better with chisel. It provides lots of useful commands for you to interact with views and properties.


Xcode jumpbar menu 1 gives you some more info about class: Counterparts, Superclasses, Siblings, Includes, Included By, …

Symbolic Breakpoint

You can create symbolic breakpoint through Xcode or LLDB.

Symbolic breakpoints stop program execution when a specific function or method starts executing.
You can specify the symbol as:
A method name. For example, pathsMatchingExtensions:.
A method of a particular class. For example, [SKTLine drawHandlesInView], people::Person::name().
A function name. For example, _objc_msgForward.

Object graph

objc-dependency-visualizer Objective-C class dependency visualizer. It’s tool that helps to visualize current state of your project. It’s really easy to see how tight your classes are coupled.
ObjectGraph-Xcode ObjectGraph can show oriented graph of dependencies between classes in your project.
objc_dep Graph the import dependancies in an Objective-C project
KSHObjcUML KSHObjcUML can show oriented graph of dependencies between Objective-C classes in your project


  1. Navigating a New Codebase: Tips and tricks for getting up to speed quickly
  2. Navigating and discovering an iOS codebase using lldb

527 total views, no views today

Handling UITextField change with symbol

In my app, there is a requirement to allow user to input value with symbol, like $45, 28 lbs, 22″, …, plus some more requirement like limiting the number of digits, validating against max and min value, showing default text when the field is empty, only showing symbol when there is at least 1 digit, …

I only want the easy way :]

There are 2 solutions that came into mind
1. Show $45. When user begins editing, remove that dollar symbol. When user ends editing, add that dollar symbol again
2. Show $45. When user edits, check and handle appropriately to keep that dollar symbol along

People prefer option #2 because it make user aware of the unit they are inputting. But it requires a lot of handling as you must separate the symbol from the digits. Some libraries prove this TSCurrencyTextField, …

There is option #3, that is to use UITextField leftView and rightView for the symbol. The idea is to determine the text property of UITextField and show/hide leftView, rightView accordingly

leftView and rightView

Let’s create a label called decoratorLabel to use as the leftView and rightView

- (void)setupDecoratorLabel {
    self.decoratorLabel = [[UILabel alloc] init];
    self.decoratorLabel.text = self.decorator;
    self.decoratorLabel.textColor = [UIColor blackColor];
    self.decoratorLabel.font = [UIFont lightFontWithSize:kProfileTextSize];

    CGSize size = [self.decoratorLabel sizeThatFits:CGSizeMake(20, CGRectGetHeight(self.textField.bounds))];
    self.decoratorLabel.frame = CGRectMake(0, 0, size.width, size.height);

Show and hide decoratorLabel accordingly

Subscribed to UITextFieldDelegate and UIControlEventEditingChanged event. Here I demonstrate for leftView, the same for rightView

- (void)textFieldDidBeginEditing:(UITextField *)textField {
    [self determineToShowOrHideDecoratorLabel];

- (void)textFieldDidEndEditing:(UITextField *)textField {
    [self hideDecoratorLabel];

// This is from UIControlEventEditingChanged
- (void)textFieldEditingChanged:(UITextField *)textField {
    // Tell textField to invalidate intrinsicContentSize, so that its width is dynamic
    [textField invalidateIntrinsicContentSize];
    [self determineToShowOrHideDecoratorLabel];

- (void)hideDecoratorLabel {
    self.textField.leftView = nil;     

- (void)showDecoratorLabel {
    self.textField.leftView = self.decoratorLabel;
    self.textField.leftViewMode = UITextFieldViewModeAlways;

- (void)determineToShowOrHideDecoratorLabel {
    // self here is UITextField
    if (self.text.length > 0) {
        [self showDecoratorLabel];
    } else {
        [self hideDecoratorLabel];


I don’t know why but UITextField only update its intrinsicContentSize when it resigns its first responder status, and its size is affected by its placeHolder text also. See Resize a UITextField while typing (by using Autolayout)

So the solution is to override intrinsicContentSize and return width based on the text

- (CGSize)intrinsicContentSize {
    if (self.isEditing) {
        CGSize size = [self.text sizeWithAttributes:self.typingAttributes];
        return CGSizeMake(size.width + self.rightView.bounds.size.width + self.leftView.bounds.size.width + 2, size.height);

    return [super intrinsicContentSize];

Here we +2 to make room for the caret

PS: If for some reasons, you want UITextField intrinsicContenSize to take effect immediately, call textField layoutIfNeeded


  1. How to handle number text field change with symbol?
  2. Resize UITextField horizontally with text using Auto Layout
  3. UITextfield leftView/rightView padding on iOS7

489 total views, 1 views today

© 2015 Fantageek

Theme by Anders NorenUp ↑