My sidekick made it!

Weblog by Cato Johnston, Web Developer from Auckland, New Zealand

Local Development With an iPhone and Charles

Posted on 25 August 2011.

When I’m developing a site, I always setup a local development enviroment on my laptop. This is usually just an Apache server with a Virtual Host setup for each site.

One step that is required is to add an entry to the hosts file on my laptop so that the URL resolves to 127.0.0.1

Recently I have been working on a project that required lots of testing on mobile phones. This is where I ran into an issue. There is no way to change the hosts files on a iPhone without jailbreaking the phone.

Enter Charles…

Charles Web Debugging Proxy

Charles is a web debugging proxy. You can download it from here

I mainly use Charles to examine http requests made by a browser, usually to debug json packets. But it is also possible to use it as a http proxy that you can route iphone http traffic through. The magic bit is: any requests from the iPhone are also subject to the proxy machines hosts file.

Charles Setup

  1. Open Proxy > Proxy Settings.
  2. Take note of the Port number. The default is 8888
  3. Click the HTTP Proxy mode button.

iPhone Setup

  1. Open Settings > Wifi > Your Wifi Network Settings
  2. Under HTTP Proxy choose Manual
  3. Server: you dev machine’s ip address Port: 8888 Authnetication: Off

The iPhone will now use the hosts file on the proxy machine for any URL requests. Boom!

Day Two - Ruby - Seven Languages in Seven Weeks

Posted on 25 March 2011.

Find:

  • Find out how to access files with and without code blocks. What is the benefit of the code block? Info about how to accessing files with and without code blocks can be found here. One of the benfits of using code blocks is that the IO object will be automatically closed after the code blocks finishes.

  • How would you translate a hash to an array? Can you translate arrays to hashes? A hash can be translated into array using the to_a method. It will convert the hash into a nested array of [key, value] arrays.

  • Can you iterate through a hash?

  • You can use Ruby arrays as stacks. What other common data structures do arrays support?

Do:

  • Print the contents of an array of sixteen numbers, four numbers at a time, using just each. Now, do the same with each_slice in Enumerable.

  • Update the Tree class so that the initialiser accepts a nested structure with hashes and arrays.

  • Write a simple grep that will print the lines of a file having any occurences of a phrase anywhere in that line.

Day One - Ruby - Seven Languages in Seven Weeks

Posted on 22 March 2011.

Language One, Day One is Ruby:

Find:

Do:

  • Print the string “Hello, world”.

  • For the string “Hello Ruby”, find the index of the word “Ruby”..

  • Print your name 10 times.

  • Print the string “This is sentence number 1”, where the number 1 changes from 1 to 10.

  • Run a Ruby program from a file.

  • Write a program that picks a random number. Let a player guess the number, telling the player whether the guess is too low or too high.

Seven Languages in Seven Weeks

Posted on 21 March 2011.

My order from Amazon arrived at work while I was away in Melbourne last week.

Thanks @animoller Thanks @animoller

One of the books was Seven Languages in Seven Weeks by Bruce Tate.

I’m going to post my attempts at the self study sections for each of the languages here. These are just to help me follow through with the book, but if someone finds them useful, then all the better.

In order, the languages are:

  • Ruby
  • Io
  • Prolog
  • Scala
  • Erlang
  • Clojure
  • Haskell

Day One - Ruby - Seven Languages in Seven Weeks

Posted on 21 March 2011.

Language One, Day One is Ruby:

Find:

Do:

  • Print the string “Hello, world”.

  • For the string “Hello Ruby”, find the index of the word “Ruby”..

  • Print your name 10 times.

  • Print the string “This is sentence number 1”, where the number 1 changes from 1 to 10.

  • Run a Ruby program from a file.

  • Write a program that picks a random number. Let a player guess the number, telling the player whether the guess is too low or too high.

Older Posts