Nick Chapman

Got to give the people what they want
Be inspired and inspiring.
  • April 12, 2010 9:12 am
    The Steve used Bryan’s game to demonstrate multitasking (14:00) in iPhone OS 4.0 last week. Yes, I’m basking in his moment and also taking any credit that I can for it.

    The Steve used Bryan’s game to demonstrate multitasking (14:00) in iPhone OS 4.0 last week. Yes, I’m basking in his moment and also taking any credit that I can for it.

  • 8:51 am
  • 8:30 am

    Bangarang

    Happy Monday morning!

  • April 11, 2010 9:44 am

    "I guess it’s about respect. It’s about a relationship I had, and I think many of us had, with Twitter, that doesn’t seem to be there anymore. And that’s frustrating, and disappointing. But mostly I guess it’s just sad."

    Ed Finkler: My Friend Twitter

  • 9:22 am
  • April 10, 2010 4:26 pm
    Helveticards (via it’s designed)
Ordered. They’re taking preorders until April 14th so get in there and get some.

    Helveticards (via it’s designed)

    Ordered. They’re taking preorders until April 14th so get in there and get some.

  • 11:01 am

    If, like me, you hastily installed iPhone OS 4.0 before adding your iPhone to the Registered Devices list in the Provisioning Portal and now you can’t get your UDID from iTunes, you can find it in System Profiler > USB > iPhone > Serial Number (oddly enough).

  • April 9, 2010 1:57 pm
    Hey Apple Developer Registration Form, those are some terrible options except for me where they fit perfectly.

    Hey Apple Developer Registration Form, those are some terrible options except for me where they fit perfectly.

  • April 8, 2010 12:44 pm
    iPhone OS 4.0: All the New Features
Hello 4.0! This is going to be a great release. I’m very excited about the Mail improvements. A unified inbox is going to save me so much button pushing, and multiple Exchange accounts will get Google Sync back in action. We’re even going to have multitasking! Everything is wonderful right? Right??
Well, almost. I think that the glaring omission from today’s event was an update to how notifications are displayed. It looks like the ridiculous modal alert boxes are here to stay for now at least. This is incredibly disappointing. After my wonderful experience with WebOS notifications, I was really, really hoping that Apple would do something similar. My hopes have been dashed. I guess there’s always next year.

    iPhone OS 4.0: All the New Features

    Hello 4.0! This is going to be a great release. I’m very excited about the Mail improvements. A unified inbox is going to save me so much button pushing, and multiple Exchange accounts will get Google Sync back in action. We’re even going to have multitasking! Everything is wonderful right? Right??

    Well, almost. I think that the glaring omission from today’s event was an update to how notifications are displayed. It looks like the ridiculous modal alert boxes are here to stay for now at least. This is incredibly disappointing. After my wonderful experience with WebOS notifications, I was really, really hoping that Apple would do something similar. My hopes have been dashed. I guess there’s always next year.

  • April 7, 2010 10:49 pm
    The Man From Hollywood
Kinetic typography using CSS selectors and Webkit CSS properties.

    The Man From Hollywood

    Kinetic typography using CSS selectors and Webkit CSS properties.

  • 1:31 pm
    jb.tumblr
My mind was just blown. Go see Jarred Bishop’s Tumblelog and checkout how the background seems fixed but is related to the post in view. It’s awesome.

    jb.tumblr

    My mind was just blown. Go see Jarred Bishop’s Tumblelog and checkout how the background seems fixed but is related to the post in view. It’s awesome.

  • 11:30 am

    "What makes me optimistic about iPad sales is just how delightful it is to use one. That’s a factor that makes sales truly viral: people who didn’t plan to buy it tend to change their minds as soon as they try one. No feature checklist will ever convey user delight."

    marco

  • April 6, 2010 11:42 pm

    "The iPad has the proportions of a paper page. It’s a familiar format, which feels natural to humans, especially in portrait mode. A widescreen display in portrait mode feels wrong. We just played with a JooJoo-which is 16:9-and that’s exactly how it feels: Stupid."

    Gizmodo: Understanding the iPad’s Industrial Design

  • 1:57 pm
    petervidani:

In case you were wondering, this is the button that Ivy Leaguers running A/B tests will produce.

    petervidani:

    In case you were wondering, this is the button that Ivy Leaguers running A/B tests will produce.

  • 9:06 am

    Regex Two Step

    I spend a lot of time parsing and cleaning up text files with regular expressions, and there’s a problem that comes up fairly often that used to really puzzle me. How do you replace something that requires complicated, multi-step logic?

    Everyone who has used regular expressions is pretty familiar with doing something like this:

    >> "5553331234".gsub(/(\d{3})(\d{3})(\d{4})/, '(\1) \2-\3')
    => "(555) 333-1234"
    

    And truth be told, you can do a lot of good stuff with that simple concept. The problem is that it isn’t always so easy as replace “this” with “that”. Many times you want to inject some logic into the replacement process. Thankfully we can can pass blocks to the regular expression methods in Ruby (.NET offers something similar by passing a delegate to Regex.Replace).

    This allows us to do some really complicated matching pretty easily. Last week I needed to reformat hundreds of SQL statements that NHibernate was generating. Here’s what some of them looked like:

    exec sp_executesql N'INSERT INTO Actions (CreatedAt, Description,
    IsReversible, Name, ObjectClass, UserTransactionID) VALUES (@p0,
    @p1, @p2, @p3, @p4, @p5)',N'@p0 datetime,@p1 nvarchar(9),@p2 bit,@p3
    nvarchar(12),@p4 nvarchar(15),@p5 int',@p0='2010-04-03
    00:36:25.1100000',@p1=N'logged
    in',@p2=0,@p3=N'Authenticate',@p4=N'UsersController',@p5=5589
    
    exec sp_executesql N'INSERT INTO UserTransactions (CreatedAt,
    Description, UserID) VALUES (@p0, @p1, @p2)',N'@p0 datetime,@p1
    nvarchar(30),@p2 int',@p0='2010-04-03 00:37:26.9600000',@p1=N'viewed
    applicant Michael Smith',@p2=1
    

    I needed these formatted as simple SQL statement without the exec sp_executesql with parameters nonsense. I needed to replace these:

    (@p0, @p1, @p2)
    

    With these:

    @p0='2010-04-03 00:37:26.9600000', @p1=N'viewed applicant Michael
    Smith',@p2=1
    

    So it would look like this:

    ('2010-04-03 00:37:26.9600000', 'viewed applicant Michael Smith', 1)
    

    Shew. As you can imagine a simple gsub like our first example wasn’t going to cut it. But, by using a block we can easily execute additional logic on each match. Here’s the code:

    # Match each SQL statement that starts with exec sp_executesql
    sql.gsub!(/exec sp_executesql.*?$/) do |match|
      # collect the params from the end of the statement into an array
      values = match.scan(/(@p\d)=N?(.*?)(?=(,@p\d)|$)/)
    
      # Remove the beginning and end of the statement
      match.gsub!(/exec sp_executesql N'/, "").gsub!(/',N'@p0.*?$/, "")
    
      # Replace each of the parameters with its corresponding value
      values.each { |v| match.gsub!(v[0], v[1]) }
    
      # Return our clean SQL statement
      match
    end
    

    You can see here that I’m using a block with gsub instead of providing a replacement string. This gives us a match object for each matching SQL statement where we can make additional replacements, and our statements end up looking like this:

    INSERT INTO Actions (CreatedAt, Description, IsReversible, Name,
    ObjectClass, UserTransactionID) VALUES ('2010-04-03
    00:36:25.1100000', 'logged in', 0, 'Authenticate',
    'UsersController', 5589)
    
    INSERT INTO UserTransactions (CreatedAt, Description, UserID)
    VALUES ('2010-04-03 00:37:26.9600000', 'viewed applicant Michael
    Smith', 1)
    

    While some additional explanation about what’s happening in the block would probably be useful, the point here is that this kind of complicated logic is possible and with very little code and hassle.

    If your regular expressions are seeming impossible or overly complicated, see if you can make it happen with the regex 2 (or 3 or 4) step instead.