Want to learn how to code? We made an app for that!

Every year more and more people learn how to code – in the next four years 8 million people will become developers 🙂 source

I was lucky to have a computer when I was young and by the time I was 10 I was writing my first programs. When I was 12 I was making my own games with 16 colors 🙂

The educational material I had access to then was limited – only a few books. But those few book I had where really fun to read and had a lot of examples and exercises. Most beginner books now are just scratching the surface of programming and focus more on syntax than anything else.

Together with a friend we wrote a book for beginners. Initially we wanted to make an iOS course but we kept on hitting the same wall – there was no resource that will teach people enough programming to be able to make apps. We decided to make that resource – and than everything – make it available for everyone – the book is free to read on our site.

The book was designed using a principle named Cascading Information Theory, which is used in games. It gives the reader the minimum possible snippets of information to gain the appropriate level of understanding at each point during the book.

We also made an app that helps you to finish the exercises from the book. The app gives analyses your code to check for common mistakes and gives you feedback on you solution. It basically replaces the need for a tutor in the first stages of learning programming.

 

68747470733a2f2f7777772e7765686561727473776966742e636f6d2f77702d636f6e74656e742f75706c6f6164732f323031352f30362f53637265656e2d53686f742d323031352d30362d32302d61742d322e32302e33362d414d2d65313433343938393730383630372e706e67

The book gradually shows the use of keywords, concepts and new syntax giving you time to practice every one of them and get comfortable using it. Solving and understating the exercises from the book will teach you how to solve many of the problems you will be facing when developing apps.
Thanks to the people who give us feedback on their experience with the book we are constantly updating and polishing it. The most common request was more exercises – when we reached 100 exercises we where having doubts that people will enjoy solving so many problems. We were wrong! We are going to keep adding exercises to the book and sending you guys updates.

You can read more about our book and app here.

Darrell Nicholas the author of iOS Learning Weekly wrote a review and mentioned our app in one of his issues 🙂

This is a WAY COOL app for learning Swift. If you are new to the language, or just want to solidify what you know, this interactive app from “We ❤ Swift” is just the tool you’re looking for. There’s a demo version that allows you to download it and try out the first 2 chapters. The lessons are short, to the point, and can get pretty tricky. I tried it out and I think I am hooked on it. I have seen a tool like this for python before, but it was web-based and a long time ago.
This is a downloadable Mac app, that you run on your own computer. It opens an Xcode playground with a problem for you to solve. It gives you all the information you need, plus hints and a button to open the corresponding chapter to see the theory behind what you are working on. When you think you have the problem solved, there is a button to submit your answer. The app will run a battery of tests to see if you really are correct and display the results.
This is one of those things where you need to keep an eye on the time, because before you know it, you will have spent hours playing with it. It’s very addictive and I highly recommend it for anyone wanting to learn or brush up their Swift skills.

You can use the code LEARNTOCODE for a $10 discount on the app and book.

Tagged with: , , , , , ,
Posted in Uncategorized

Here’s a question for you!

 

It’s not about programming. It’s not about technology. It’s not about numbers. It’s not about STARTUP BUZZWORD.

It’s all about people.

The internet is part of our society and it’s making our lives better every day. Many try to get rich on the internet. Few have succeeded in seeing the real game. I think one of the big players who got this right is Google. The game is about creating value for people. Facebook connects people. LinkedIn gets you jobs. etc.

Well then … what is value ?

I really did not figure that one out. But many have tried and I read some things here and there. I one had to opportunity to meet Vlad Stan in person and talk to him about a project I was working on with two friends. He talks fast and means business. One of the thing I learned form him was this simple way of killing an idea really fast.

It had to answer yes to at least one of these:

  • Will X get me laid?
  • Will X make me money?
  • Will X make me better?

I really liked this approach and tested it on my ideas. I killed a lot of them. And just that is a good enough for me because I have too many ideas 😛 Now when I think about it I understand why this three questions worked so well. It’s because it brought the users in the center of attention.

Hope this was worth three minutes of your time 🙂

What do you understand by value?

Tagged with: , , , ,
Posted in entrepreneurship, startups

How to make robots talk to each other

... 
- Is Siri your friend?
- I don't know siri.
- How about John, then?
- John who?
- John Smith.
- What about John smith?
- He is John Smith.
- I mean John shepard.
- No, John Simm!
- <html>
- Who are you?
- I'm also your friend.
- What's my friends name?
- <html>
...

This is part of a conversation between two robots that was created using this ruby script:

require 'cleverbot'

@client1 = Cleverbot::Client.new
@client2 = Cleverbot::Client.new

def say message, voice="Vicki"
  puts message
  `say -v #{voice} "#{message}"`
end

def chat alice, bob, message, first_voice="Vicki", second_voice="Zarvox"
  message = message.gsub("*","")
  say message, first_voice
  next_message = alice.write(message)
  chat bob, alice, next_message, second_voice, first_voice
end

chat @client1, @client2, ARGV.count > 0 ? ARGV[0] : "Hi."

The script requires Mac OS X for the say command. You can replace it with the Google Text-To-Speech APIif you don’t use OS X.

It also requires you to install the cleverbot gem

gem install cleverbot

After you can run the script:

# this will start the conversation with "Hi."
ruby clverbor.rb
> Hi.
...

# this wil start the conversation with "Hey sexy!"
ruby cleverbot "Hey sexy\!"
> Hey sexy!
> What`s up?
> Nothin`.
> Why?
> I dunno.
> Let`s change the subject, what do you think of Tony Hawk.
> I know that DNA is something I`ve got, but you`ll never have.
> Did something what?
...

It works by creating two cleverbot clients and starting a conversation with one of them. After a reply is received, it starts a conversation with the other one using it. Then the robots are tricked into talking to each other and we can enjoy the show.

Have fun! 🙂

I have to give credits for the idea to Silviu for this one!

Tagged with: , , , , , , , ,
Posted in hack, ruby

My favorite hack with the Objective-C Runtime

The Objective-C runtime allows you to look under the hood of your code and play with it while it is being executed. You can see the properties and methods of a class, it’s super class, and the methods and properties from a protocol. You can even change the way your program works at runtime by creating a new class, changing it’s super class or swizzling it’s methods.
After about two years of iOS development I really got tired of integrating web services into my application. If a login request succedes it would return something similar to this response:

{
  "status" : "success",
  "user"   : {
    "first_name" : "Andrei",
    "last_name" : "Puni",
      "age" : 22
  }
}

After handling the networking part we usually get a NSDictionary with the values from the json/xml respose. Now all we need to do is write the User class and create a User instance from that :

// User.h

@interface User : NSObject

@property (nonatomic, retain) NSString *firstName;
@property (nonatomic, retain) NSString *lastName;

@property (nonatomic, retain) NSNumber *age;

+ (instancetype)userFromInfo:(NSDictionary *)info;

@end
// User.m

@implementation User

+ (instancetype)createFromInfo:(NSDictionary *)info {
    User *user = [self new];

    user.firstName = info[@"first_name"];
    user.lastName = info[@"last_name"];
    user.age = info[@"age"];

    return user;
}

@end

This code is pretty simple and does the job, but it has some issues:

  • if you add or remove a property from the model you must also mirror the changes in the userFromInfo method
  • you have to write code everytime you create a new model

If we would have a NSArray with the name of the properties of the model (for User it would be@[@"firstName", @"lastName", @"age"]) this code would be a bit different:

// User.m

// code from: http://stackoverflow.com/questions/1918972/camelcase-to-underscores-and-back-in-objective-c
NSString *CamelCaseToUnderscores(NSString *input) {
    NSMutableString *output = [NSMutableString string];
    NSCharacterSet *uppercase = [NSCharacterSet uppercaseLetterCharacterSet];
    for (NSInteger idx = 0; idx < [input length]; idx += 1) {
        unichar c = [input characterAtIndex:idx];
        if ([uppercase characterIsMember:c]) {
            [output appendFormat:@"%s%C", (idx == 0 ? "" : "_"), (unichar)(c & ~0×20)];
        } else {
            [output appendFormat:@"%C", c];
        }
    }
    return output;
}

@implementation User

- (NSArray *)propertyList {
    return @[@"firstName", @"lastName", @"age"];
}

+ (instancetype)createFromInfo:(NSDictionary *)info {
    NSObject *object = [self new];

    for (NSString *property in object.propertyList) {
        id value = info[property];
        // look for the underscore form "firstName" -> "first_name" 
        if (value == nil) {
            value = info[CamelCaseToUnderscores(property)];
        }
        [object setValue:value
                  forKey:property];
    }

    return object;
}

@end

All we have to do now is get the class property list and move this code in a category for NSObject and never write the same code again.

#import <objc/runtime.h>

...

- (NSArray *)propertyList {
    Class currentClass = [self class];

    NSMutableArray *propertyList = [NSMutableDictionary array];
    // class_copyPropertyList does not include properties declared in super classes
    // so we have to follow them until we reach NSObject
    do {
        unsigned int outCount, i;
        objc_property_t *properties = class_copyPropertyList(currentClass, &outCount);

        for (i = 0; i < outCount; i++) {
            objc_property_t property = properties[i];

            NSString *propertyName = [NSString stringWithFormat:@"%s", property_getName(property)];

            [propertyList addObject:propertyName];
        }
        free(properties);
        currentClass = [currentClass superclass];
    } while ([currentClass superclass]);

    return propertyInfo;
}

Now that we have this magic method, the code will look like this:

// User.
@interface User : NSObject

@property (nonatomic, retain) NSString *firstName;
@property (nonatomic, retain) NSString *lastName;

@property (nonatomic, retain) NSNumber *age;

@end

...

// User.m

@implementation User

@end

...

AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
[manager GET:@"http://example.com/login.json" parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
    User *user = [User createFromInfo:responseObject];

    // do something with user 

} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
    NSLog(@"Error: %@", error);
}];

The reverse function is easy to implement and allows (de)serializing almost any object (as long as all the properties are objects). You can find these methods with some optimizations and tweaks in my cocoapod. There you will also find a lot of convenience methods and other useful code snippets that I use in most of my projects.

Hope you liked the hack, I’m looking forward to seeing your thoughts in the comments!

Tagged with: , , , , , , , , , , ,
Posted in hack, ios, magic, objc, objective-c, runtime

Versions matter

I get a little crazy about having the latest version of the software i like.

Today i wasted about four hours of work because of that.

I was installing ruby on a VPS following the steps from this article and i got stuck at installing the passenger nginx module. It was generating all kinds of errors. I found all the solutions on stackoverflow but none of them seem to actually fix the whole problem.

After taking a two hour break and approaching the problem again I had a crazy idea: “Let’s try ruby 1.9.3!”

Yep! … that did it.

I always fucking forget this!

So today I hope i finally learned that versions are important, and some of them are early versions and things just break, and that I should use stable versions in production.

Tagged with: , , , , , ,
Posted in ruby, TIL