Nexus Weblogging
ChinaonRails
You are here ChinaonRails > Ruby on Rails > Newbie > aidanf.net - Aidan Finn's Home Page
aidanf.net - Aidan Finn's Home Page
本频道中共有 10 条消息,返回讨论版 Newbie,17 个其他相关频道

  aidanf.net - Aidan Finn's Home Page

SimpleICM 

SimpleICM

So after programming almost exclusively on Unix for the last 10 years, I recently found myself doing some windows desktop development.

And since a significant portion of those years were spent programming in python, I started playing around with IronPython as a way to explore the Windows API. One of the projects I build as a learning exercise is SimpleICM.

SimpleICM is a poker tournament equity calculator. You give it the stack sizes of the players left in a poker tournament, along with the payout structure for that tournament and it calculates each players tournament equity according to the Independent Chip Model.

If you don't play a lot of poker tournaments and study tournament theory then this probably doesn't mean much. But professional poker tournament players need to do these calculations daily while reviewing their play and practicing making correct decisions etc. If you're interested, check out this example of an equity calculation using SimpleICM.

It's written using IronPython. You can download the application from here and you can get the source from the git repository.

I've written quite a bit of poker-related software for personal use over the last couple of years. I may release some of it over the coming months. So I've setup a site at pokerkernel.com as a holding page for my poker-related stuff. If you're interested in this then you can subscribe to the pokerkernel blog.

blog comments powered by Disqus

I'm on Last fm 

I'm on Last fm

I've been using Last fm for the last couple of months.

mylastfm1

My musical tastes are wide and varied but a common theme with stuff that I like is that it almost involves talented guitar players. Melody and groove feature heavily too.

mylastfm2

I find that it's very rare these days that I find new bands that I like. The main reason I started using Last fm was to get some decent recommendations. It's already paid me back by recommending I check out Band of horses.

If you have vaguely similar tastes feel free to add me or send me recommendations.

mylastfm3

blog comments powered by Disqus

Opening the default browser on windows 

Opening the default browser on windows

The problem

I have a windows application with an embedded WebBrowser component. I want to write a function to open the default browser. When the use clicks on a link in the embedded window, I want this link to open in a new window or tab in the default browser (WebBrowser components seem to like to hijack any attempt to open a url).

Windows has no easy way to reliably do this. There are some easy ways to attempt it. These work for some cases but they all failed in certain cases that I tried. The problem is that if there are any existing WebBrowser instances (E.g. an open IE window or a WebBrowser component in the calling application), windows will open the page in that window. That means it will use the WebBrowser component from open browser windows, or from applications that are using the WebBrowser component and have the AllowNavigation property set to true.

The Solution

The following IronPython code will open the default web browser on windows.

Note: python has a webbrowser module in the standard libary but it also fails in the way described above. This code can replace that module on windows.

import clr
import System
import Microsoft
import Microsoft.Win32.Registry as Registry

def get_default_browser():
    try:
        key = Registry.ClassesRoot.OpenSubKey("HTTP\shell\open\command", False)
        browser = key.GetValue(None).ToString().ToLower().Replace("\"", "")
        browser = browser.split('-')[0]
        browser = browser.strip()
        return browser
    finally:
        if key:
            key.Close()
   
def launch_default_browser(destination):
    p = System.Diagnostics.Process()
    p.StartInfo.FileName = get_default_browser()
    p.StartInfo.Arguments = "%s" % destination
    p.Start()

I haven't tested this much but it works on my windows vm for my for the cases that were failing using the other methods.

You can also hook this code into the Navigating event of the WebBrowser instance of your application so that any links clicked will be opened in a new default browser.

def handle_navigate(sender, event):
    event.Cancel = True
    launch_default_browser(event.Url)

b = System.Windows.Forms.WebBrowser()
b.Navigating += handle_navigate
blog comments powered by Disqus

Long Urls please 

Long Urls please

Shortened urls break the web! Don't use them unless you absolutely have to.

A while ago I posted how tinyurls bug me and people use them way too much. If you don't know why tinyurls are evil please go and read that post or check out some other links.

And yet the number of url shortening services continues to proliferate and people continue to use them in inappropriate places. (Appropriate user are where space is restricted e.g. twitter messages or the link is so long it wraps over multiple lines in an email. Otherwise don't shorten it).

Fighting back

So the scourge of shortened urls continues to spread. How can we stop this? Spread the word about why they are bad. And if they bug you like they bug me, you can head over to http://www.longurlplease.com/ where you can get a firefox extension that will automatically replace these nasty little urchins with real proper urls.

blog comments powered by Disqus

Site update 

Site update

I'm rejigging this site.

Step 1: New minimalist theme.

Step 2: New server and new blogging software setup.

Step 3: Profit, Start blogging again.

I'm still working through the kinks so in the meantime check out the archive and the top posts from the archive.

blog comments powered by Disqus

Top posts from the archive 

Top posts from the archive

I've in the process of moving to a new blogging setup (and a new server). If you notice any bugs with the site please let me know. Rather than migrate all my old posts over I've just archived them as static pages. You can browse the archive of the old site here.

Since I'm archiving all these pages I had a look at my google analytics stats for the last couple of years. Here are the top ten posts from the archive.

  1. Basic User Authentication in Rails
  2. Adding a Rich Text Editor to your Rails Application
  3. Creating your own generators in rails
  4. A list of interesting Erlang links
  5. Clearwire Broadband in Ireland - It's getting worse
  6. Moving from Subversion to Git for revision control
  7. Deploying rails on a clean ubuntu slicehost VPS
  8. Learning Erlang
  9. Installing Drupal on FreeBSD
  10. Tools and tips for completing a postgraduate degree in Computer Science
blog comments powered by Disqus

Waveriders 

Waveriders

Waveriders is the previously untold story of the unlikely Irish roots of the worldwide surfing phenomenon and today’s pioneers of Irish big wave surfing. Waveriders was Winner of the Audience Award for Best Film at the Dublin International Film Festival 2008.


I went to see the preview of Waveriders last night in Sligo. Waveriders is a documentary about surfing in Ireland and Irish links to surfing history and heritage. Most surfing films are pure surf porn - sequences of well-known surfers surfing idyllic surf breaks. This one is different. It tells a story. It's interesting. It's beautiful and awe inspiring.

It was a lot better than I'd expected to to be and I'd highly recommend you go and see it in the cinema if you can. It launches nationwide on April 3rd.

I surf, and I live in Sligo (where a lot of the footage was shot) so I'm at the core of this films target audience. But I imagine it's a film that would appeal to non-surfers too as shown by it's winning of the audience award at the Dublin film festival.

The film culminates with footage from last Decembers huge storm. This footage alone is awesome and my stomach dropped while watching it. But it doesn't reflect the main theme of the film.

At the core of the film is a realization and celebration of what a beautiful and precious resource the west coast of Ireland is. It's inspiring and uplifting and something that's very difficult to achieve on film.

Below is a trailer for the film (which doesn't really do it justice). Go see it and let me know what you thought of it.

blog comments powered by Disqus

Disabling genre in iTunes 

Disabling genre in iTunes

I find the genre tab in the iTunes browser useless so I don't use it. There was a setting in preferences to prevent it being displayed. But after updating to the latest version of iTunes I found that the genre tab is showing up again in the browser and there is way of disabling it in the iTunes preferences.

As usual, the command line comes to the rescue. Enter the command below and restart iTunes.

defaults write com.apple.itunes show-genre-when-browsing -bool FALSE
blog comments powered by Disqus

Desperately seeking ... AC/DC tickets 

Desperately seeking ... AC/DC tickets

I'm a huge music fan. I own a lot of albums and I've been to a lot of gigs. I've seen most of my favourite bands live. But the one band in the world that I haven't seen live that I really want to are AC/DC.

They were the first band that really got me into music. I remember seeing Thunderstruck on the beat-box when I was about 12. I wasn't into music much at that stage but I was blown away and I spent all my savings on getting their entire back catalogue. That was the start of a long and expensive interest in collecting music.

AC/DC announced a couple of days ago that they would play in Dublin in April. I knew these tickets would sell out quickly so I was sitting at my computer at 9am today refreshing the ticket****** website. I managed to get into the queue for tickets but they sold out before I got one. Actually they sold out in less than 2 minutes. Of myself, my brother and 2 friends who were all trying to get tickets none of us managed to get any.

So I'm posting this in the slim hope that someone out there has a couple of spare tickets. I'd be eternally grateful and you'd get that warm fuzzy feeling from knowing you helped someone realize one of their lifelong ambitions. If you can help me out please get in touch.

And congratulations to all the lucky fans who got tickets.

P.S. I hope bad things happen to the scalper scum that bought tickets just for the purposes of selling them at an inflated price. I did a quick web search and some Irish websites are already offering tickets for €300 each.

blog comments powered by Disqus

Archiving a dynamic site as static content 

Archiving a dynamic site as static content

(And making pretty urls for static content)

I recently archived archived my old drupal site by creating a static copy of it. Thus for every url that existed in the old site there now exists a static page in the archive directory with the html extension.

So the page that once existed at /rails now exists at /archive/rails.html

Getting a html static archive of your site is fairly easy. If your blogging software uses a static page cache, then you can use the contents of that page cache and hammer your site with wget to generate the cache for every page. Mephisto does this caching by default. For drupal the boost module will implement a static page cache. Most good blogging platforms have a way of generating a static cache of the site. Alternatively you could do it yourself using wget -mirror.

Once you have a static archive generated you need to ensure that these files are served for all the urls that are associated with your old site. The easiest way to do this is to check if the archive contains a file with the requested path and a html extension and if so, serve it up.

Below is an set of apache rewrite rules for doing this.

This works by checking each request for an archived file:

  1. If there exists a document that matches the requested path with .html appended serve that. This catches all unarchived content that is statically cached.
  2. If there exists a document in the archive directory that matches the requested path with .html appended serve that. This catches all the archived html pages.
  3. If there exists an item in the archive directory that matches the requested path then serve that. This catches archived images, css, pdfs etc.
        RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_URI}.html -f
RewriteRule ^(.*)$ /$1.html [L]

RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_URI}.html !-f
RewriteCond %{DOCUMENT_ROOT}/archive/%{REQUEST_URI}.html -f
RewriteRule ^(.*)$ /archive/$1.html [L]

RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_URI} !-f
RewriteCond %{DOCUMENT_ROOT}/archive/%{REQUEST_URI} -f
RewriteRule ^(.*)$ /archive/$1 [L]

blog comments powered by Disqus

10 items

欢迎使用 RSS 阅读器订阅本页种子 http://www.aidanf.net/node/feed
© 2006-2010 A Jesse Cai Production   -   About   -   京ICP备07020911号
a site powered by Project Babel