Saturday, May 10, 2014

#method_missing

method_missing in ruby is a really interesting and powerful concept. Inside of every Class you create in ruby you have the ability to override #method_missing to do whatever you would like it to do. Here is an example:

class Person
  def walk
    puts "I'm walking"
  end

  def method_missing(sym, *args)
    puts "Looks like you can't do this"
  end
end

person = Person.new
person.walk #=> "I'm Walking"
person.fly #=> "Looks like you can't do this"

When person.fly was called ruby looked for the method fly and realized that it did not exist. Instead of throwing an error we had created our own #method_missing so when a method does not exist it puts the string in the method. 

This can be used in many more ways than such an elementary example such as metaprogramming, observer patterns, etc, but you can get the point of the power of something like this.

Monday, May 5, 2014

Nested RESTful Routes

Let's say Lessons has a  has_many relationship to Courses and you want to do #show on method in the view. Here is a view of the path:

course_lesson GET      /courses/:course_id/lessons/:id(.:format)      lessons#show

What you will need to do is:

<%= link_to "#{lesson.description}", course_lesson_path(lesson.course, lesson) %>

This will allow the link to populate both the :course_id as well as the :id of the lesson.

Sunday, May 4, 2014

Project Completion, Pitfalls, and how to avoid them

Completing anything in life can always fail because of a number of excuses that we give ourselves on a daily basis. I personally think many things don't get finished for a number of reasons:

1. Fear of Failure: If you have been working on something a long time, the fear of disappointing others or even yourself are prevalent and hinder our ability to build and execute on projects quickly. Is it good enough? Will others use it?

2. Focus on core competencies: I find myself doing things that aren't immediately needed to complete a project. FOCUS on MVP (Minimum Viable Product). Why the hell am I blogging when I should be finishing iOS Academy this moment? Why am I doing CSS styling when I could be finishing the content. Build a list of priorities based on importance and do NOT jump around. Start at the top and move your way to the bottom of the list.

3. Laziness: Most people at this level do not have a problem with laziness, but I think this goes back to focusing on core competencies. I consider laziness when I efficiently do everything BUT what I should be doing in an attempt of avoiding a move difficult integral task.

Most to come, just had to get that out...

Friday, May 2, 2014

Little things I learned today

1.  xctool: This was a tool built by a facebook employee that lets you run your simulator from your command line and allows you to setup your tests for Travis CI. This is great to allow integration and unit tests being added into the same CI Build to test the whole suite.
2.  Self.webView.scrollView: webView has a nested scrollView within it that has various methods that can be called on it to update the position of where a user is within the webView (example: scrolling to a  place in the readable based on reading progress).

3.  $ gem outdated: Shows you what gems you have that are outdated and the newest versions available.

Tuesday, April 29, 2014

xctool, xcode, and Travis Integration

Hey Guys,

I know many people have been having trouble currently with xcode and xctool playing nicely with Travis and with the new 5.1 release of xcode there have definitely been some bumps in the road, but I have found a way that works for me. Here is a sample travis.yml file to see what it should be looking like and the pieces you will need to have it run properly:

travis.yml
language: objective-c
before_install:
  - gem install cocoapods
  - brew update
  - brew upgrade xctool
script:
  - xctool test -simulator ipad -freshInstall -workspace myApp.xcworkspace -scheme 'iPad Tests for Travis' -sdk iphonesimulator ONLY_ACTIVE_ARCH=NO
  - xctool test -simulator iphone -freshInstall -workspace myApp.xcworkspace -scheme 'iPhone Tests for Travis' -sdk iphonesimulator ONLY_ACTIVE_ARCH=NO 

The most important addition to this yml file is adding brew update and brew upgrade xctool. This will upgrade your xctool to be compatible with the new xcode 5.1 build.

Secondly, you will need to take out any --freshSimulator hooks that you have in the script as the new build of xctool builds a fresh simulator each time and this can cause issues. Here is a link to the current issue on Github that members from Travis are currently addressing this if you need a reference point: http://bit.ly/1hNI8SE. Good Luck and let me know if you have any questions because I've definitely been through it with this the last few days!

Thursday, February 20, 2014

Protocols and Analytics

Things I learned today:
1.  Protocol: Defining protocols declares the methods expected to be sued for a particular situation. Protocols are implemented in the classes conforming to the protocol.

a.  Syntax of Protocol:
@protocol ProtocolName
@required
// list of required methods
@optional
// list of optional methods
@end

b.  Syntax for conforming to Protocol
@interface MyClass : NSObject <MyProtocol>
...
@end
c.    Protocols allow you to eliminate clutter with interface methods!
d.  Required methods: Once protocol is implemented, the required methods MUST be implemented or the compiler will complain.
e.  Ran First: Once implemented, protocol methods MUST run first before other methods can be called. Check to make sure this is true
2.  Google Analytics vs. Mixpanel
a.  Google Analytics: Is a free resource to track page views and number of unique visitors. This is a great resource to see how much raw traffic you are getting to your site and from what geographic regions.

b.  Mixpanel Tracks Events: This is good for seeing how far a user gets down the sales funnel before they stop, or how often a feature is being used.

Thursday, February 6, 2014

Authentication Headers


Things I learned today:
a.    This allows you to see how the dynos are running and if the system is down.
2.  Authentication Headers: Authentication headers are used in Devise for authenticate current_user. In order to pass this from the authentication you need to pass an HTTP header as well as the url in a NSURLConnection call.

- NSString *userToken = [NSString stringWithFormat:@"Bearer %@", [[JFCurrentUser shared] authenticationToken]];
  
 - NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:kJFWebViewURL]];
 -  [request setValue:userToken forHTTPHeaderField:@"Authorization"];

 -  [webView loadRequest:request];