This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%%% File : recomendations.erl | |
%%% Author : Russell Brown <russell@pango.lan> | |
%%% Description : The first chapter of Programming Collective Inteligence, but in elrang, like. | |
%%% Created : 15 Jun 2009 by Russell Brown <russell@pango.lan> | |
-module(recomendations). | |
-compile(export_all). | |
%% |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Main where | |
import Network.Socket | |
import System.Environment | |
import Control.Concurrent | |
import Control.Monad | |
-- Port number to listen on | |
listenPort :: PortNumber | |
listenPort = 3000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
How great is named_scope? | |
Dave » 12 December 2008 » In Technology » 3 Comments | |
If you haven’t used named_scope in Rails 2.1+ yet, I suggest you learn about it ASAP. Prior versions of Rails had a plugin that could perform similar functions, but it’s nice to have it part of the core system. | |
What does it do? | |
It does just what it says. It gives you a way to utilize the power of with_scope but name it. The best way to show it is with an example. | |
Let’s say you have a user model. Users have a gender attribute and a activated flag. When operating on your user object, you could sprinkle your code with something like: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Ruby Background Tasks with Starling | |
Dave » 25 March 2008 » In Technology » | |
At Inquisix, we help sales professionals exchange trusted referrals. To do that requires several background tasks, some that could take 10-15 minutes to process. Obviously, I can’t make a client wait for that, so I needed a system that could handle background tasks. At first, I started with backgroundrb, and it worked just fine. Backgroundrb was in production for two months while Inquisix grew. However, there were a few things about backgroundrb that bothered me: | |
It uses a lot of memory. Every worker creates at least one process. Plus, there is a master process to watch everything and deal with communication. It doesn’t take much before you end up with 5-6 processes. I had to upgrade my test server just to deal with the extra memory requirements. | |
It’s not easy to build a queue with control over threads without creating a ton of processes. | |
Too many times, I wanted to do something pretty straight forward, but I had to dig throug |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
More Asynchronous Processing | |
Dave » 04 November 2008 » In Technology » | |
In a previous series on using workling and starling for asychronous processing, I described how to setup background tasks. Here is a quick way to use this for emails without a lot of changes to your application. | |
First, create lib/asynch_mail.rb: | |
# Makes an actionmailer class queue its emails into a workling queue | |
# instead of sending them sycnhronously | |
# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'mechanize' | |
require 'hpricot' | |
site="www.twitpic.com" | |
# Grab the highest picture number | |
agent = WWW::Mechanize.new | |
agent.user_agent_alias = 'Mac Safari' | |
page = agent.get("http://#{site}/public_timeline") | |
doc = Hpricot(page.body) |
NewerOlder