Another good example of a PHP “quirk” is the way PHP handles constants. It was one of the major factors affecting performance. Just removing all the constants allowed us to improve the performance by almost 2x (we left one constant to be precise).

From The Need for Speed.

That’s right - PHP is up to 2X faster if you don’t use constants. You know, that means hardcode values in…

View Comments (2)   RSS Feed for Comments on this Post
diff -r 5e13047a2284 Support/hg_commit.rb
--- a/Support/hg_commit.rb	Mon Apr 27 11:38:15 2009 +0930
+++ b/Support/hg_commit.rb	Mon Apr 27 11:39:00 2009 +0930
@@ -79,7 +79,7 @@
   commit_paths_array = matches_to_paths(commit_matches)
   commit_status = matches_to_status(commit_matches).join(":")
   commit_path_text = commit_paths_array.collect{|path| path.quote_filename_for_shell }.join(" ")
-  commit_args = %x{"#{commit_tool}" --status #{commit_status} #{commit_path_text} }
+  commit_args = %x{"#{commit_tool}" --diff-cmd hg,diff --status #{commit_status} #{commit_path_text} }

   status = $CHILD_STATUS
   if status != 0
View Comments (0)   RSS Feed for Comments on this Post

I’ve cloned and updated the included Prolog bundle to use my Run script.

This can be found at GitHub: SWI-Prolog.tmbundle.

View Comments (0)   RSS Feed for Comments on this Post

In the continuing effort to do ‘productive’ tasks, but not actually the project I am supposed to be working on, I present a TextMate command to run the current prolog file, with nice HTML output, and input via a dialog box.

#! /usr/bin/env ruby

require ENV["TM_SUPPORT_PATH"] + "/lib/tm/executor"

command = [ENV["TM_PROLOG"] || "swipl", "-s", ENV["TM_FILEPATH"]]
two_line = false

welcome = /^(Welcome to SWI-Prolog)|(Copyright )|(SWI-Prolog comes with)|(and you are welcome)|(Please visit)|(For help, use)/

TextMate::Executor.run(command) do |str, type|
  if type == :err
    if two_line
      two_line = false
      # this line is part of the previous message
      "#{str}</div>"
    # Is this a warning line?
    elsif str =~ /(Warning):\s(.*):(\d+):/
      warn, file, line = $1, $2, $3
      filename = file.split('/')[-1]
      two_line = true
      file_link = "<a class=\"near\" href=\"txmt://open?line=#{line}&url=file://#{file}\">#{filename}</a>"
      "<div class=\"#{warn}\">#{warn}: #{file_link}, line #{line}:"
    elsif str =~ /(ERROR):\s(.*):(\d+):(\d+):\s(.*)/
      file, line, char, message = $2, $3, $4, $5
      filename = file.split('/')[-1]
      file_link = "<a class=\"near\" href=\"txmt://open?line=#{line}&column=#{char}&url=file://#{file}\">#{filename}</a>"
      "<div class=\"err\">ERROR: #{file_link}, line #{line}, col #{char}: #{message}</div>"
    elsif str =~ /ERROR:\s(.*)/
      message = $1
      "<div class=\"test fail\">ERROR: #{message}</div>"
    elsif str =~ /%\s(.*)\scompiled\s(.*)\ssec,\s(.*)\sbytes/
      file, time, length = $1, $2, $3
      filename = file.split('/')[-1]
      file_link = "<a class=\"near\" href=\"txmt://open?url=file://#{file}\">#{filename}</a>"
      "<div class=\"test ok\"> #{file_link} (#{length} bytes) compiled in #{time} sec.</div>"
    elsif str =~ welcome
      "<span class=\"copyright\" style=\"font-size:xx-small;\">#{str}</span> "
    else
      "<div class=\"output\">#{str}</div>"
    end
  else
    "<div class=\"output\">#{str}</div>"
  end
end
View Comments (0)   RSS Feed for Comments on this Post

It would be cool to be able to run my Django tests from within TextMate.

Update: this version will run just the tests from the active file, if there are any. Otherwise, it runs all of the tests in the whole project.

Here is a Command to do just that:

#! /usr/bin/env ruby

command = [ENV["TM_PYTHON"] || "python", "-u", "#{ENV['TM_PROJECT_DIRECTORY']}/manage.py", "test", "--noinput"]

File.open(ENV['TM_FILEPATH']) do |f|
  f.readlines.each do |line|
    if line =~ /class (.*)\(.*TestCase\):/
      test_case = $1
      app_name = ENV['TM_FILEPATH'].split(ENV['TM_PROJECT_DIRECTORY'])[1].split('/')[1]
      test_name = "#{app_name}.#{test_case}"
      command << test_name
    end
  end
end

require ENV["TM_SUPPORT_PATH"] + "/lib/tm/executor"

ENV["PYTHONPATH"] = ENV["TM_BUNDLE_SUPPORT"] + (ENV.has_key?("PYTHONPATH") ? ":" + ENV["PYTHONPATH"] : "")

TextMate::Executor.run(command) do |str, type|
  if type == :err
    if str =~ /\A[\.EF]*\Z/
      str.gsub!(/(\.)/, "<span class=\"test ok\">\\1</span>")
      str.gsub!(/(E|F)/, "<span class=\"test fail\">\\1</span>")
      str + "<br/>\n"
    elsif str =~ /\A(FAILED.*)\Z/
      "<div class=\"test fail\">#{htmlize $1}</div>\n"
    elsif str =~ /\A(OK.*)\Z/
      "<div class=\"test ok\">#{htmlize $1}</div>\n"
    elsif str =~ /^(\s+)File "(.+)", line (\d+), in (.*)/
      indent = $1
      file   = $2
      line   = $3
      method = $4
      indent += " " if file.sub!(/^\"(.*)\"/,"\1")
      url = "&url=file://" + e_url(file)
      display_name = file.split('/').last
      "#{htmlize(indent)}<a class=\"near\" href=\"txmt://open?line=#{line + url}\">" +
        (method ? "method #{method}" : "<em>at top level</em>") +
        "</a> in <strong>#{display_name}</strong> at line #{line}<br/>\n"
    end
  end
end
View Comments (0)   RSS Feed for Comments on this Post

I seem to recall my internet going down, and then coming back up, at around the same time every night.

Tonight it flaked at 8:21pm.

View Comment (1)   RSS Feed for Comments on this Post

I didn’t realise until today that there was a part of iTunes Genius that makes suggestions when browsing the iTunes store.

I went to click on one item, and got:

Now, why would you go and recommend something you can’t give me? That is just plain mean!

View Comment (1)   RSS Feed for Comments on this Post

Using TextMate, it is very easy to get snippets and commands to do things that you often do. However, the python bundle is a bit lacking, and this is a great opportunity to improve that.

I’ve created a Command that will enter a newline, and if not inside a list, function call, dictionary or multi-line string, automatically add a trailing \.

I’ve hooked it in to the Enter key, and the other settings can be seen in the screenshot below:

The actual code follows:

#!/usr/bin/env ruby

scope = ENV['TM_SCOPE'].split

no_trail = ['punctuation.definition.arguments.end.python',
            'meta.structure.list.python',
            'meta.structure.dictionary.python',
            'string.quoted.single.block.python',
            'string.quoted.double.block.python']

print (scope & no_trail) == [] ? "\\\n" : "\n"
View Comments (0)   RSS Feed for Comments on this Post

I’m loving coding in TextMate - it makes ruby much more fun. And python, too.

It integrates really well with heaps of other tools, including my diffing app of choice (Changes.app), and my preferred DVCS (Mercurial).

It even has its own Commit pane that appears when you choose to commit. There is one problem with it, however. Invariably I have made a change to a file and can’t remember exactly what it was. You can’t view the changes using the Mercurial bundle and Changes, and leave that window open while you commit. So, I end up having a terminal window open that I type ‘hg chdiff’ into.

Instead, we should be able to quickly see the changes made to the working copy. Perhaps using a button like below:


Of course, that’s just a mockup (although it is done in IB) - the button is not connected up to anything. I have no idea how to reverse engineer the Commit.app to do this. But it would be cool.

Update: It appears all you have to do is tell the CommitWindow.app tool that you want to use –diff-cmd “hg,diff”, and it is all done.

View Comment (1)   RSS Feed for Comments on this Post

Dr Seuss.png

View Comment (1)   RSS Feed for Comments on this Post