Unintelligible

Saturday, January 12, 2008

Paul Graham’s “On Lisp” - in a single HTML page

Paul Graham kindly made this available free of charge in PDF and Postscript formats (here). However, because I wanted to change the printing format (to print it in booklet format, which is two A5 pages per A4 sheet), I was looking for something I could change the layout of, which proved hard to do in PDF (unsurprisingly, since the aim of the PDF and PS formats is fixing layout for print). I found a multi-page HTML file here; this wasn’t too convenient for printing though, so I concatenated it to a single file. I’m posting it here (860k) in case anyone else finds it useful.

posted by Nick at 5:01 pm - filed in lisp  

Monday, December 17, 2007

Vi! Vi! Vi!

I’ve been using Vim for about 4 months now, and I must admit that I’m not sure how I did without it. Modal editing seems like a natural paradigm to me (similar to lifting your hands off the keyboard to perform operations with the mouse, except without lifting hands from the keyboard :-), and the movement commands seemed intuitive and somehow logical, much easier than remember all the different keybindings Emacs has. Vim is a great text editor; however, it isn’t as well suited to more specific tasks, such as being an IDE or a document editor, as dedicated software such as IntelliJ IDEA or Word/OpenOffice are. The problem with those, in turn, is that text editing isn’t half as smooth as with Vim.

So, I was quite pleased when I stumbled upon this:

http://jvi.sourceforge.net/

A Netbeans module for Vi-like editing in Netbeans. I’ve been playing with it a bit and it definitely looks promising; this goes at least some way to resolving the IDE question, as I’ve found Netbeans to be great for Ruby/Rails and second only to IntelliJ as a Java IDE. For work, I’m thinking of splashing out on this:

http://www.viemu.com/

I’ve had a go with the demo and it works great. They have a version for Word/Outlook too, which is definitely very enticing - even though I already find editing text with Vim a lot more efficient than with a traditional editor, I still feel like I could be quite a bit more productive, and the more I get to practice, the easier this should hopefully become. Now if only I could find an equivalent for Open Office and Thunderbird…

posted by Nick at 11:15 pm - filed in linux, windows  

Monday, October 1, 2007

Dvorak touchtyping - week 4

Well, I broke the 55WPM mark on the home row this week, but things go downhill pretty rapidly from there. On other exercises I hover between 35 and 45WPM, and on a general typing test I fare much worse (around 33-35WPM on this typing test). So, I’m still pretty far off the mark from my ambitious ‘60WPW in a month’ aim, but I guess the idea was to aim loftily, and then reassess after a month…

I’ll definitely need a lot more practice to reach 60WPM. My overall speed is still slower than my quick hunt-and-peck QWERTY skills, which was probably to be expected but is still disappointing. I also still have to think about where letters are on the keyboard when I type most of the time, and in the real world (i.e. not typing tests) I still make a lot of mistakes even on the keys I’ve practiced the most on. On the positive side, I can actually type mostly without looking at the keyboard, and I’ve more or less assimilated using the basic copy-cut-paste keyboard shortcuts with the DVORAK layout.

The key to faster speeds will obviously be more practice (which I’d let up on a little in the past couple of weeks) - with regular practice, I’m hoping to make 60WPM overall in the next month or so.

posted by Nick at 6:19 pm - filed in dvorak  

Friday, September 28, 2007

Using SSL/HTTPS for Gmail and Google Apps

Today, I was thinking about Google Apps and wondering whether it used SSL to encrypt email. Now the Gmail POP/SMTP facilities use encryption for any data transferred between the mail client and Google’s mail servers, so I would have thought it natural that SSL was used to encrypt any email sent via the web interface as well. As it turns out though, that isn’t the case; firing up my trusty copy of Fiddler, I sent an email to myself using the Google Apps web interface and monitored the resulting HTTP exchange. This is the result (this is the POST request transcript - the relevant bits are in bold).

The same applies to Gmail itself. I know for most people this is a non-issue as email is generally insecure (as it gets transmitted unencrypted from mail server to mail server). I was thinking about local malicious users or sysadmins viewing the email I am sending or receiving. There are quite a few cases I can think of when I’d like to know local sysadmins can’t read my mail: a public internet cafe (in China for example, or another country free speech not a given), a corporate VPN, a non-encrypted (or WEP-encrypted) WiFi hotspot, etc… 

With Gmail, the solution is to access Gmail via https://mail.google.com rather than http://mail.google.com. In this case, a secure session is maintained throughout and all communication between Gmail and the browser is encrypted.

With Google Apps, the solution is to log in using a URL like this:

https://mail.google.com/a/mydomain.com

However, I couldn’t get https://mail.mydomain.com to forward to the above, which is a shame as it’s my main gateway to Google Apps (and others’ too I suspect - and therefore possibly a minor security issue for sysadmins administering domains using Google Apps…).

posted by Nick at 3:50 pm - filed in Uncategorized  

Saturday, September 22, 2007

Dvorak touchtyping - week 3

Well, better but still far from perfect. I broke the 50WPM barrier on the home row this week, at 98% accuracy too, but I also let up on the regular practise a little (I must have practised two or three times this week for an hour or so at a time, down from 6 the two first weeks at an hour and a half or so each). I’m still nowhere near as good at any of the other exercises though, and I still catch myself looking at the keyboard quite regularly.

Interestingly, I noticed myself being rather verbose in some of by emails this week, presumably as a subconscious reaction to the joy of finally being able to type at something approaching reasonable speeds. I’m also starting to get a feel for the positions of the keys other than the home row without having to look at them too, although I’m noticing that I frequently get the ‘e’ and the ‘o’ mixed up. Another interesting thing is that I seem to be in a different mindset when typing freely and doing the exercises; for some reason, some of the keys I remember well typing freely don’t seem to make it over to the exercises - I guess the different visuals (the terminal for dvorakng and Windows for daytime work) disassociate the two in my mind, which is a shame…

posted by Nick at 2:48 pm - filed in dvorak  

Sunday, September 16, 2007

Dvorak touchtyping - week 2

Well, there has been progress, but it has been slow. I’m on around 40-45WPM on the home row (which accounts for 70% of keys in English), but my error rate is still high at round 95-96%. The WPM drops dramatically once I leave the home row though, at around 30-35WPM for anything involving the top row (I haven’t even tried any exercises involving the bottom row). At least the frustration of typing letters at what seemed like 2WPM has abated, so I can stop resorting to using the mouse as much as possible and actually write emails without crying…

posted by Nick at 2:47 pm - filed in dvorak  

Saturday, September 8, 2007

Dvorak touchtyping - week 1

So I’m going to try to learn how to touch-type again; this will be my second attempt, the first being about three months ago. The difference is that this time I’m switching to Dvorak cold-turkey; the last time I had also tried to learn Dvorak, but I think that the constant swiching between Dvorak and Qwerty was what ended being discouraging, as progress was very slow.

It’s been just over a week now, and the first few days were among the most frustrating I remember having in a long time. The double-switch of Dvorak and touch-typing proved very difficult. On the first day, it took me almost 20 mins to write a 5-line email sheerly due to my typing speed; it got to the stage that I was not emailing people back because the frustration at not being able to type was so great. It’s not so bad now; I can type at a reasonable speed, I’m guessing around 10-20 WPM, which is still horrendously slow but at least workable. I had set myself an ambitious goal of 80 WPM in a month, which right now doesn’t seem achievable, especially given my still very high error rate - still worth trying though…

posted by Nick at 12:49 am - filed in dvorak  

Thursday, August 16, 2007

One line Ruby memoization

Memoization is a functional programming technique used to cache the result of expensive method calls for later re-use; this allows us to avoid repeatedly performing an expensive calculation when the result has already been calculated once. Today I stumbled accross an interesting method of achieving memoization in Javascript for nullary functions (i.e. functions taking no arguments); the author was re-defining the method called to perform the calculation to return the computed result, meaning the repeated invocations of the method would return the computed value once the initial calculation had been performed. This seemed like an elegant way to achieve result caching; I was curious to see if the same could be achieved with Ruby.

The standard method of result caching in Ruby might be:

class Cached
  def cached_method
    return @cache unless @cache.nil?
    puts 'computing expensive value'
    sleep(2)
    @cache= "hello world"
  end
end
 
c=Cached.new
10.times do
  puts 'result: ' + c.cached_method
end

Using memoization:

class Memoized
  def memoized_method
      #expensive computation goes here
      puts 'computing expensive value'
      sleep(2)
      cache="hello world"
      self.class.send(:define_method, :memoized_method, lambda{cache}).call
  end
end
 
m=Memoized.new
10.times do
  puts 'result: ' + m.memoized_method
end

Here, we are re-defining memoized_method within the function itself so that it returns the computed value once it has been invoked. Disappointingly though, this isn’t much of an improvement line-count wise - the result is slightly less readable too, mainly because define_method is private (which is why we need to use the self.class.send hack above). What about performance (over 50000 iterations)?

nick@unintelligible:~/Desktop$ ruby perf.rb
Rehearsal ---------------------------------------------
cached:    0.120000   0.020000   0.140000 (  2.135206)
memoised:  0.110000   0.020000   0.130000 (  2.139923)
------------------------------------ total: 0.270000sec
                    user     system      total        real
cached:    0.100000   0.040000   0.140000 (  0.134768)
memoised:  0.130000   0.020000   0.150000 (  0.144927)

Nope - it’s roughly equivalent (very slightly slower in fact, presumably due to the extra cost of routing the method through define_method). So, although memoization is definitely a useful technique, result caching yields is still more readable and slightly more performant for nullary functions in Ruby than this particular implementation.

posted by Nick at 1:09 pm - filed in ruby  

Friday, July 20, 2007

Strongly-named assemblies and InternalsVisibleTo

One of the projects I work on wasn’t using strongly-named assemblies, so we decided to sign them (mainly to prevent version conflicts on sales laptops). However, after generating the key-pair and setting up the different assemblies to use it, building the solution gave this error:

Friend assembly reference ‘Company.Product.UnitTests’ is invalid. Strong-name signed assemblies must specify a public key token in their InternalsVisibleTo declarations.

The problem was that some of the assemblies were making their internals visible to the UnitTests assembly (making them accessible so that they could be tested), but when these assemblies are strongly names, the public key token must also be included in the InternalsVisibleTo declaration in Assembly.cs.

This introduces a chicken-and-egg scenario; the A assembly makes its internals visible to the UnitTests assembly, but must know the UnitTests assembly public key in order to build. The UnitTests assembly depends on assembly A to build, but assembly A can’t be built until we know what the public key token for UnitTests is, which in turn can’t build because it depends on assembly A…

After looking into a couple of solutions, the one that worked for me was:

  1. Sign all assemblies with the key-pair
  2. Generate the public key for the key-pair as such (from the Visual Studio command prompt):

    sn -p path\to\keypair.snk path\to\keypair.pub

  3. Get the public key token for the public key as such (still from the Visual Studio command prompt):

    sn -tp path\to\keypair.pub

    This will output a long (256 characters) public key; copy this to the clipboard

  4. Declare the InternalsVisibleTo attribute in Assembly.cs as such:

    [assembly: InternalsVisibleTo("Company.Product.UnitTests, PublicKey=<your public key>")]

    where <your public key> is replaced by the public key output in (3)

  5. Build the solution. The solution should now build as expected.

This assumes that all assemblies use the same key-pair - suggestions to use the public key token (using PublicKeyToken=... rather than PublicKey=...) didn’t work for me.

posted by Nick at 5:58 pm - filed in .net  

Friday, July 13, 2007

Rubyists and Photographers

I was browsing the net the other day, minding my own business, when I came across this:

http://giantrobots.thoughtbot.com/2007/5/1/coding-without-ifs

In summary, Jared Carroll is proposing to replace

def update_subscriptions
  Subscription.find(:all).each do |each|
    if each.expired?
      each.renew!
    else
      each.update!
    end
  end
end

with

def update_subscriptions
  subscriptions = Subscription.find :all
  expired = subscriptions.select {|each| each.expired?}
  expired.each {|each| each.renew!}
  active = subscriptions.reject {|each| each.expired?}
  active.each {|each| each.update!}
end

in the name of avoiding conditionals in Ruby. You’ll notice that the second version loops through the ’subscriptions’ array 3 times rather than one. In the comments (which span 9 A4 pages) follows a lengthy discussion on the aesthetics and validity of the design of the second solution. It struck me then that Ruby gives you power, a lot of power - perhaps, sometimes, too much power.

I’m reading Paul Graham’s Hackers and Painters at the moment, and continue with his “hacking is like a visual art” analogy, I’d like to propose the following: Ruby is to Java (or C#) what photography is to oil painting. As with all analogies, it has its limitations, but the logic is as follows:

  • creating an image using oil painting is long and hard
  • creating an image using photography is quick and easy
  • because creating an image is quicker with photography, the amount of time spent actually creating the image becomes a proportionally smaller part of the artistic process than it is with oil painting
  • as a result, the percentage of time spent on ’secondary’ considerations (lenses, film types, darkroom exposure techniques, filters, etc.) becomes a proportionally larger part of the artistic process

Most of the professional photographers I know actually spend little time thinking about the secondary considerations such as lenses, film types etc. - they seem to find something they like and stick with it, reviewing their choices only occasionally. However, some get tempted into spending a lot of time and energy debating the relative merits of different lenses, film types, darkroom exposure techniques etc. These items are still only a minor factor of a good picture; the most important element in a good picture is unarguably its content (in a studio picture, this could be the subject, angle, background, lighting, pose etc.)

The similarity here, I think, is that Ruby has empowered programmers to think about the lenses, film types etc. a lot more because taking a picture has just become so much easier. There is not doubt in my mind, however, that whether to use conditional logic or closures is a minor consideration compared to the main (and hardest to attain) aim of the hacker, which is the beauty of the resulting solution; as tempting as it may be to debate the best polarizing filter, debates about language constructs are only as valuable as their contribution to achieving that aim is (which in this case would probably be minor).

P.S. I’m not at all arguing that Jared Carroll or any of the commenters in his blog are bad programmers (most of them are probably more experienced and talented than I am), or that debating about lenses and cameras is pointless - it isn’t, but spending more time thinking about them than actually taking pictures is counter-productive for a photographer. I’m just reminding myself how easy it it to get sidetracked.

posted by Nick at 12:53 pm - filed in ruby  
« Previous PageNext Page »