Notes on VIPER

45 total views, no views today

Recommended books for developers

107 total views, no views today

Stupid Interview Questions

The original is 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

76 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

112 total views, no 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

102 total views, no 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

425 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

355 total views, no views today


  1. Navigating and discovering an iOS codebase using lldb

241 total views, no views today


Jobs may come and go, but it’s the people I’ve worked with that I always remember

  1. This is why you never end up hiring good developers
  2. Effective Programing: More than writing code Hiring Programmers The Right Way
  3. The Five Essential Phone-Screen Questions
  4. How to Interview a Programmer
  5. The Guerrilla Guide to Interviewing (version 3.0)
  6. SellsBrother interview
  7. Smart and Gets Things Done: Joel Spolsky’s Concise Guide to Finding the Best Technical Talent
  8. How to get a job at Atlassian – An insider’s perspective

339 total views, no views today

Software engineering

  1. 15 things I wish I’d learned earlier about software engineering
  2. The Ten Commandments of Egoless Programming
  3. 6 common traits of good programmers
  4. The Joel Test: 12 Steps to Better Code

332 total views, no views today

© 2015 Fantageek

Theme by Anders NorenUp ↑