Wednesday, March 03, 2010

Make Apple Mail more like Gmail

I like Gmail. I like its consolidated inbox/sent view. Whenever I use a mail client I set it up to copy sent items into my inbox (it usually defaults to a "Sent" folder) and use a threaded view in the inbox so that my messages are interleaved with those of others. I find this simpler to work with than a separate sent folder. This wasn't possible with Apple Mail. It lets you "keep a copy of sent items" but it does not let you specify which mailbox to put the copy in. But I figured out a way to achieve the same thing using Smart Mailboxes. The idea is to set a condition to something simple that will catch all messages.

  1. Give it a name. I named mine "Mail"
  2. Click the Mailbox menu and select New Smart Mailbox...
  3. Select "Date Received" as the first part of the condition.
  4. Select "is after the date" as the second part.
  5. Leave the date as something in the past.
  6. Check the "Include messages from Sent" checkbox.
  7. Click OK.
Having obviated the need to click on different mailboxes, I decided I could live without the sidebar. The little gripper at the bottom of the sidebar lets you completely remove the sidebar. You can get it back by clicking on the left-most pixel edge of the window and dragging it right again. Also, I decided I didn't care what Mailbox my message was in, so I removed that column. View menu => Columns => Uncheck Mailbox. There. Much simpler.

Monday, May 12, 2008

Marking Up Ruby Code for Blogs

I jazzed up this blog a bit and redid the code highlighting because before I was using Vim's :ToHtml but the HTML it generated made me cry inside. I wrote this script to do it, which is derived from this one. Advantages over the linked script:

  • This version doesn't rely on dcop (KDE), so you can run it under any window manager you like. I run it under Xubuntu with Window Maker.
  • This version doesn't rely on RIO so you have fewer gems to install.
#!/usr/bin/ruby -w
#
# ruby2html
# Copyright (C) 2008 Greg McIntyre
# All rights reserved.
#
# Takes Ruby code from the clipboard and replaces it with HTML marked up
# version of it.
#
#   ruby2html mycode.rb
#   # writes mycode.html
#
#   ruby2html
#   # replaces Ruby code in clipboard with HTML marked up version
# 
# My version of this:
#   http://blog.wolfman.com/articles/2006/05/26/howto-format-ruby-code-for-blogs
#
# Requires:
#   sudo aptitude install xclip
#   sudo gem install syntax

require 'rubygems'
gem 'syntax'
require 'syntax/convertors/html'

if ARGV.size > 0
  code = File.read(ARGV[0])
else
  code = `xclip -out`
end

convertor = Syntax::Convertors::HTML.for_syntax('ruby')
convertor.tokenizer.set(:expressions => :highlight)
@code_html = convertor.convert(code)
@code_html.gsub!(/^<pre>/, '<pre class="ruby">')

puts @code_html

if ARGV.size > 0
  fn = "#{File.basename(ARGV[0], File.extname(ARGV[0]))}.html"
  File.open(fn, 'w') do |f|
    f.puts @code_html
  end
else
  # Put it back in the clipboard.
  IO.popen('xclip -in', 'w') do |f|
    f.puts @code_html
  end
end

Saturday, May 10, 2008

Word Scrambler

Apparently you can scramble the letters inside words, leaving the first and last letter intact, and still recognise the words. A lot of our word recognition in English comes from word length and the bounding letters. This is an old Ruby script I wrote that scrambles the interior letters in words. Some examples:

$ ./scrambler.rb < file.txt
$ echo "I can still read this sentence despite the spelling being totally messed up." | ./scrambler.rb
I can stlil read this seenncte dsteipe the snleplig benig ttollay mseesd up.
#!/usr/bin/ruby -w
#
# Copyright (C) 2004 Greg McIntyre
# All rights reserved.
#
# Randomises letters inside words, leaving the first and last intact, creating
# scrambled sentences which are still readable because the human brain works
# like that.
#
# e.g.
# Reionasmds leertts isidne wrods, laivneg the frsit and last itcant, ctneirag
# scrlmeabd steneecns wihch are stlil radalbee bauesce the hmuan biran wkors
# like taht.

WORD = /[\w]+/
LETTER = /[A-Za-z]/

def scramble(string)
  string.gsub(WORD) do |word|
    # Collect indices of scramblable letters.
    indices = []
    word.split(//).each_with_index do |character, index|
      indices << index if LETTER.match(character)
    end

    # Remove 1st and last index.
    indices.shift; indices.pop

    # Jumble the letters at these indices.
    indices.each do |i|
      # Swap the letter at this index with the letter at a
      # random index.
      swap_i = indices[rand(indices.size)]
      word[i], word[swap_i] = word[swap_i], word[i]
    end

    # Evaluate to the word.
    word
  end
end

while line = ARGF.gets
  puts scramble(line)
end

Tuesday, July 10, 2007

Ctags and Actionscript

I used to apply a patch to Exuberant Ctags to get Actionscript jump-to-definition functionality working, however a co-worker pointed out the other day that you can define regular expressions in its configuration file and obviate the need to recompile it. Hurrah! No more software updates breaking my ctags binary! This is my ~/.ctags showing its support for Actionscript (2 and 3):

--links=no
--langdef=ActionScript
--langmap=ActionScript:.as
--regex-ActionScript=/function[ \t]+([A-Za-z0-9_]+)[ \t]*\(/\1/f,function,functions/
--regex-ActionScript=/function[ \t]+(set|get)[ \t]+([A-Za-z0-9_]+)[ \t]*\(/\2/p,property,properties/
--regex-ActionScript=/interface[ \t]+[a-z0-9_.]*([A-Z][A-Za-z0-9_]+)/\1/i,interface,interfaces/
--regex-ActionScript=/class[ \t]+[a-z0-9_.]*([A-Z][A-Za-z0-9_]+)/\1/c,class,classes/
Using this, you can hit the little build tags button in GVim or run
ctags -R .
yourself to build your index (called "tags"). You can also throw in some standard libs source files:
ctags -R . "${FLEX_HOME}/frameworks/source"
From within Vim I like to press "g" and click on a function, class or interface name to jump to its definition, or position the cursor over it and press "CTRL-]". Saves loads of time, especially since Actionscript files, like Java files, are heavily nested in often arbitrarily named packages. Nowadays I never really worry about where .as files are located. If in doubt, rebuild tags and jump to it.