February 23rd, 2009

I came across this article on digg. Its about a Glenn Beck program on Fox News called ‘War Room’. The article provides an interesting read (though a bit long). The embedded fox videos contain a fair bit of fear mongering, a la… <The government isn’t upholding the values of the constitution and the militias (or bubbas) may need to fight a new civilwar in 2104>

The videos will mean different things to different people based on their views. The reason I’m writing THIS post is to point out a glaring error in Fox News’ fact checking.

War Room Scenario #2 paints the very bleak outlook :

50 million people worldwide are unemployed. There are riots in the streets.

The problem is, as of 2007 there were 180 million people unemployed!

Just image the carnage that would be unleashed if 130 million people got new jobs!

0
Posted in Uncategorized |
January 30th, 2009
safari cookie monster

Safari has been causing me much grief recently.  It would seem that I’m not the only one, and so far I’ve been unable to find any suggestions other than deleting all your cookies and and resetting Safari (a solution which doesn’t actually work) .

I seem to constantly get logged out of various web apps when using Safari, including Facebook & Gmail.  With Gmail I usually get an 400 error message or a warning the the header is too long. Sorry to anyone who was hoping to read a solution here. I don’t think anyone has one at the moment.  I really just wanted to post the image and vent a little…

 

 

0
Posted in tech |
January 17th, 2009

I’m at startup camp sydney now (#scs on twitter) and we’re making an app called Givedo

First off, I’m kind of amazed that givedo.com was available.

This was born from the idea of ‘Search for the cure’. Using a google custom search we can collect revenue from adsense for search.

In the vein of not being evil, we figured that we’d set up a platform for charities to quickly and easily build their own branded search engine and funnel search ad revenue to them.

So that is givedo!

0
Posted in startup |
January 15th, 2009

Here is a summary of a few of the problems I encountered while trying to upgrade an app from rails 2.1 to rails 2.2.2

Getting my dev code to run

First, to update the rails code:

 > rake rails:freeze:gems

The first time I tried to run the app I got this error:

vendor/rails/activesupport/lib/active_support/dependencies.rb:445:in `load_missing_constant': uninitialized constant Inflector (NameError)
Accessing the inflector changes, so as described here you need update APP/config/initializers/inflector.rb so it looks like this:
ActiveSupport::Inflector.inflections do |inflect|
  ...
end

In my case, I was also using the ActiveMerchant plugin which needed updating for the same reason

script/plugin install git://github.com/Shopify/active_merchant.git --force

According to gusg.us, HAML needs to be at 2.0.4.   I didn’t see any problems in my testing but I didn’t want to try my luck so I updated HAML too.

sudo gem update haml

update my environment.rb gem requirement

config.gem "haml", :version => "2.0.6"
Then run
rake gems:unpack:dependencies

Production

While deploying to a staging server I got this error:

initializer.rb:514:in `send': undefined method `cache_template_loading=' for ActionView::Base:Class (NoMethodError)

As described here, to fix this, just update your APP/config/environments/production.rb (and staging.rb) file by removing the following:

config.action_view.cache_template_loading

Overall, it wasn’t too painful an upgrade…

I didn’t run rake rails:update. That may have fixed some of these things on it’s own, but my understanding was that that wasn’t needed anymore…

7
Tags: , | Posted in tech |
January 14th, 2009

I’m evaluating different domain name options for something I’m working on.  Typically, I register domains names with GoDaddy because they seem to be the cheapest.  Yesterday, I registered the domain wedding-website.ca as a test.  I wanted to compare writing instructions about how to buy a domain name vs. using the API vs. a reseller front-end.

My step by step instructions are now at step 13, and that’s before I get into any DNS alterations.

13 STEPS!?!?   What kind of e-commerce sales funnel is 13 steps?  I’m pretty sure I filled out my details 3 times and created a least 2 accounts. (I’m not sure – I’m still a little dizzy from the whole thing).  I do have about 5 long numbers now which I’m sure I’ll have to re-enter somewhere, at some point…

Many of the steps in the instructions I was tracking included things like ‘completely ignore everything on the page and just press the very tiny button at the bottom (the one hidden under the big button)’.  The 13 steps actually excludes some of the extra steps I had to take because it’s a .ca domain!!  Okay, so intructions through GoDaddy aren’t going to be part of my solution.  Register.com and Dotster.com have slightly cleaner processes (but not by much)

GoDaddy, Register, and some others offer resale program and APIs. The APIs are generally completely undocumented, and you get no indication of what is available (or even what technology is used) before they ask for the steep annual fee.  Register.com has the best API (it’s xml based) I’ve see, but so far it seems to be a big flat convoluted set of URLs.

Now, I’m sure most of these companies are making lots of money, I just wanted to rant about how annoying I find it all to be from my perspective as a consumer.

2
Tags: , , | Posted in Uncategorized |
December 8th, 2008

While trying to provide some more styling options for the wedding website builder I’m working on I came across a very cool and easy to use flash font tool.

FontBurner is essentially a hosted sIFR solution which makes getting cools flash fonts as easy as a simple copy and paste.

To get the headlines in this blog post to be as they are, all I needed to do was paste this code:

 

<link rel="stylesheet" href="http://www.fontburner.com/css/fontburner.css" type="text/css" media="screen" /> 

<link rel="stylesheet" href="http://www.fontburner.com/css/fontburner_print.css" type="text/css" media="print" /> 

<script src="http://www.fontburner.com/fontburner.js" type="text/javascript"></script> 

<script type="text/javascript" src="http://www.fontburner.com/js/white/action_man_extended.php"></script> 

<!-- sIFR fonts delivered by www.fontburner.com -->

 
If you need flash fonts, check them out:

 


0
Tags: , , | Posted in Uncategorized |
October 27th, 2008

I had the need to consume some exchange rate data for an internal project so I began looking for an about. My searching found no api for Google Finance, Yahoo Finance, XE, or Oanda. :-(

Fortunately I found the currency converter from Xavier Media and their simple currency exchange rate xml API, which includes historical data too. :-D

I put together an absolutely minimal lib to get the data I need.  I just needed the AU/US rate.  The xml provides all data as base to EUR, but with some simple math I can find the rate I need with reasonable accuracy.  In this case ‘accuracy’ is based on spot checking it against the yahoo rates.

I thought it worth sharing in case others are looking for something similar.

UPDATE: I changed the xml string below to better handle single digit date months. Xavier needs ‘01′ instead of ‘1′

require "cgi"
require "uri"
require "net/https"
require "rexml/document"

module XavierMedia
  # Returns the exchange rate (AUD/USD) on the given date.
  def self.exchange_rate_on(date)
    url = URI.parse("http://api.finance.xaviermedia.com/api/#{date.year}/#{date.strftime("%m")}/#{date.strftime("%d")}.xml")

    resp = Net::HTTP.get(url)
    xml  = REXML::Document.new(resp)

    us_to_eur = 1.0
    au_to_eur = 1.0
    xml.elements.each("//exchange_rates/fx") { |el|
      if el.elements[1].text == "USD"
        us_to_eur = el.elements[2].text.to_f rescue 1.0
      end
      if el.elements[1].text == "AUD"
        au_to_eur = el.elements[2].text.to_f rescue 1.0
      end
    }

    return us_to_eur/au_to_eur
  end
end

 

5
Tags: , , , | Posted in Uncategorized |
October 26th, 2008

Fragment caching in rails works great.  We use it a lot for MomentVille and easily get most of our responses in under 150ms because it dramatically reduces teh number of queries we need to run for our most common actions.

I did notice some slowness recently though, and was quite confused.  The slowness only occurred on our production servers. Our dev, test, and pre-production servers were all still fast.  I tried using new relic rpm service to help pinpoint the problem, and while it does a great job in helping you track things, it didn’t help me narrow down the problem.

Ultimately I discovered that the problem had to do with how we clear the cache. For some actions we have to expire multiple fragments, so we used regex expiration.  Unfortunately, that is very slow.  It seems that regex expiry compares your regex to each fragment stored, even if you think your regex looks like it’s targeting a directory.

Alexander Dymo had a post about regex expiry of fragment caches in rails that outlined a solution for him.  It helped guide me to a solution that works well for us.  OUr fragment caches are actually structured around the data as opposed to the actions, so related fragments are stored within sub directories.  When we need to clear a bunch at once, we just want to wipe out the whole directory.  So, I created a file called fragment_dir_expiration.rb and put it into my /config/initializers folder.  It looks like this:

# For rails 2.0 and lower
module ActionController
  module Caching
    module Fragments

      #dir is the cache path relative to the cache root
      def expire_fragment_dir(dir, options = nil)
        return unless perform_caching
        self.class.benchmark("Expired fragments in dir : #{dir}") do
          ActionController::Base.cache_store.delete_fragment_dir(dir, options)
        end
      end

      class UnthreadedFileStore

        def delete_fragment_dir(dir, options = nil)
          path = @cache_path + dir
          return unless File.exist?(path) #it's ok to not have the cache dir
          search_dir(path) do |f|
            begin
              File.delete(f)
            rescue SystemCallError => e
              # If there's no cache, then there's nothing to complain about
            end
          end
        end

      end
    end
  end
end

When you want to call this you can call it from an observer with a call like this

class WidgetSweeper < ActionController::Caching::Sweeper
  observe Widget
  def after_save(widget)
    # Expire all the fragments for the updated widget
    expire_fragment_dir("/widget/#{widget.id}/")
  end
end

UPDATE: For rails 2.1 and above use the following:

module ActionController
  module Caching
    module Fragments

      #dir is the cache path relative to the cache root
      def expire_fragment_dir(dir, options = nil)
        return unless perform_caching
        self.class.benchmark("Expired fragments in dir : #{dir}") do
          ActionController::Base.cache_store.delete_fragment_dir(dir, options)
        end
      end

    end
  end
end

module ActiveSupport
  module Cache
    class FileStore

      def delete_fragment_dir(dir, options = nil)
        path = @cache_path + dir
        return unless File.exist?(path) #it's ok to not have the cache dir
        search_dir(path) do |f|
          begin
            File.delete(f)
          rescue SystemCallError => e
            # If there's no cache, then there's nothing to complain about
          end
        end
      end
    end
  end
end

 

1
August 19th, 2008

I’ve converted all of my projects from svn to git.  If you haven’t done so already, and can do it, I would recommend not waiting anymore.  It does make things better.  

I used to really like the visual representations available on svn (such as tortoise svn) and rarely used the command line for repository related things.  The way git works (in particular, not having to have a special ’svn folder within each folder) makes managing files way easier.  The best way to learn is to check out the git peepcode. I borrowed some of the aliases below from the screencast.

Now that I’m on the command line more, I’ve created a .bash_profile to make my life easier.  It is full of nice goodies that I collected.  I figured that I’d share it with the world in case others find it helpful.  It includes:

  • Updating the OSX Leopard terminal title bar (and potentially the tabs) to include the working directory
  • Updating the command prompt to include the current directory and the current git branch (if you’re in a git repo)
  • Lots of aliases to save myself keystrokes.

# Get the name of the current git branc
function parse_git_branch {
  git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
}

# Update the command prompt to be <user>:<current_directory>(git_branch) >
# Note that the git branch is given a special color
function set_my_prompt {
  PS1="\u:\w\e[1;34m\$(parse_git_branch)\e[m > "
}

# Update the title for the terminal window to be the full working dir
function set_term_title
{
    local title="$1"
    if [[ -z "$title" ]]; then
        title="root"
    fi

    local tmpdir=~/Library/Caches/${FUNCNAME}_temp
    local cmdfile="$tmpdir/$title"

    # Set window title
    #echo -n -e "\e]0;${title}\a"
    echo -n -e "\e]0;${PWD#*/}\a"

   # Set tab title
   # This works by creating a process with the name of the working dir.  
   # So, the tab name doesn't stick if you start running a mongrel server :-(
    if [[ -n ${CURRENT_TAB_TITLE_PID:+1} ]]; then
        kill $CURRENT_TAB_TITLE_PID
    fi
    mkdir -p $tmpdir
    ln /bin/sleep "$cmdfile"
    "$cmdfile" 10 &
    CURRENT_TAB_TITLE_PID=$(jobs -x echo %+)
    disown %+
    kill -STOP $CURRENT_TAB_TITLE_PID
    command rm -f "$cmdfile"
}

set_my_prompt
PROMPT_COMMAND='set_term_title "${PWD##*/}"'

# Some aliases I find useful
alias gclb="git checkout -b"
alias gb="git branch"
alias gba="git branch -a"
alias gs="git status"
alias gca="git commit -a"
alias gcm="git commit -m"
alias gk="gitk --all &"
alias ss="script/server"
alias ssp="script/server -p"
alias sr="script/runner"

Big credit goes Christopher Stawarz to the the tab & title thing: l

3
June 12th, 2008

I had begun jotted down a list of resources I’ve found helpful while trying to start a business in Australia. I was going to make a blog post out of it. Yesterday I was introduced to a site that has beat me to the punch, and has made it much more useful then a blog post would have been.

Startup-Australia.org is a wiki that contains a range of resources that entrepreneurs will find useful. It’s new but already contains lots of great info about a range of things including funding, events, and startups.

Instead of finishing my blog post I’m just going to add what I know there instead. I suggest others do the same.

1
Tags: , | Posted in Uncategorized |