Tag Archives: development

AnotherTab Chrome extension FTW!

OK, the Google Chrome new tab page extension I’ve been (extremely lazily) developing for quite some time is live now! It’s not much, really – just displaying one bookmarks folder (I use “Bookmarks Bar”) and launchable extensions, but that’s what I use the most myself. Oh, and some Chrome shortcuts – like cookies, passwords etc. – too:

AnotherTab screenshot

It’s on Chrome Web Store – but there’s also a separate page to send around: http://hydralien.net/anothertab/

Oh, and the code is public, too: https://bitbucket.org/hydralien/anothertab

Exporting Apple Mail filters to Sieve format

What’s this?

It’s a script (in AppleScript) that goes through all Apple Mail filters and converts them to Sieve filters, so you could go server-side on email filtering

Why?

The answer is, as usual, “because I’m lazy” – I’ve accumulated a fair bunch of Apple Mail filters along the way, and converting them manually wasn’t much fun. And I found no working option to convert it on the Internet.

Code and disclaimer

Code is available at:

https://bitbucket.org/hydralien/tools/src/23bca8d016ef88085c98cb1278174be86dfbba4e/apple/Mail2Sieve.applescript?at=master

feel free to clone, submit your patches etc.

NOTE that this is validated with a quite limited use case – in my filters, I mostly match against subject and sometimes against CC/To, so it definitely has some issues with other fields. Please review / try loading the results first and don’t disable all your Mail filters right away.

Exporting Mail filters

Just run that script – it will ask you if you want to use disabled filters as active (useful to re-export after you have already disabled Mail filters), then if you want to disable Mail filters (useful when you’re certain in your Sieve filterset), and then where to save the results.

Was it fun?

Well… the answer is “look at the code”. On the one hand, writing in AppleScript is quite unlike writing in most of the “conventional” languages – some constructs are very different, some seem more natural, others more awkward. On the other, loops management reminded me of programming Turing machine – I mean, using THIS as “continue”, really?!

So to conclude – I think it was, as any unusual experience is fun in it own (however peculiar) way. And it’s the “proper way” for the case – you deal with official API, not parsing the XML (which I could, because Mail rules are stored in XML files) because there’s no way to foretell where the source would move or how its structure would change eventually. Mail API is way less likely to do so.

Resources

Some Sieve-related resources FTR:

What’s next?

Have a beer!

Greatest prime divisor

Just for the record – custom algorithm for searching greatest prime divisor of a number, O(n) worst-case (O(sqrt(n)) taken by prime detection):

def prime(num, get_number=False):
  for divisor in range(2, int(math.sqrt(num)) + 1):
    if num % divisor == 0:
      return False
  return num if get_number else True

def hydra_gpd(num, get_number=None):
  sequence = range(2, int(math.sqrt(num)) + 1)
  gpd = 1
  for divisor in sequence:
    divided = int(num / divisor)
    if num % divisor == 0:
      if prime(divisor) and divisor > gpd:
        gpd = divisor
      if prime(divided) and divided > gpd:
        gpd = divided
      recursive_gpd = hydra_gpd(divided)
      if recursive_gpd > gpd:
        gpd = recursive_gpd
      return gpd
  return gpd

Nothing too special, just to keep it around.

Developers on support

37signals recently posted a great article on developers doing support: http://37signals.com/svn/posts/3676-everyone-on-support. I think it’s extraordinary good description of why, how and what for (i.e. what good does it do) developers should sometimes be involved in customer support. That’s what I sometimes do now (it’s occasional, unfortunately – mostly when questions are too deep into code for support) and did that a lot beck in RightMedia/Y! days, and I can say it’s all true. To a certain limit, of course (that I faced, too) – but if you do a balanced shifts, it plays nicely.

Remove duplicates from iTunes playlist

UPDATE: Script could be found on BitBucket now – https://bitbucket.org/hydralien/tools/src/8e751cbd676eb7c2604d4e2e25633f9291e631f0/apple/iTunesDedupe.applescript?at=master

If one adds music to iTunes playlist by dragging them files in (without moving to iTunes library), one might end up with a fair number of duplicates. And one might get frustrated about it.

ALso, one might even go and solve it, and then share for other suffering fellas – like this: http://hydralien.net/storage/apps/nodupes.dmg

NOTE: playlist should be sorted by name. And it makes sense to export a playlist for backup reasons – for I give no warranties here.

Code is included to the image – but let it rest below as well. FTR to launch/edit it, run AppleScript Editor (use Spotlight) – it’s simple but nice tool to write AppleScript apps.

 

tell application "iTunes"
display dialog "Gimme playlist name" default answer ""
set plName to the text returned of the result
set curPl to user playlist plName -- current playlist
set dupes to {}
set prevTrack to {"", 0}
set trackNo to 1
repeat with aTrack in every track of curPl
set curTrack to {get name of aTrack, get time of aTrack}
if curTrack = prevTrack then
set the end of dupes to trackNo
end if
set trackNo to trackNo + 1
set prevTrack to curTrack
end repeat
set dupePos to 0
repeat with dupe in dupes
set rmTrack to dupe - dupePos
-- log rmTrack
delete track rmTrack of curPl
set dupePos to dupePos + 1
end repeat
set dialogLine to "Deleted " & (count dupes) & " dupes in " & plName & " playlist"
display dialog dialogLine buttons {"OK"}
end tell