Thursday, December 30, 2010

Multi Terminal Bash History

Add the following to ~/.bashrc:

# Bash history fixes
shopt -s histappend
export PROMPT_COMMAND='history -a'
export HISTSIZE=5000

Commands from all terminals will be appended to the .bash_history file instead of replacing it. Very useful for if you routinely use multiple terminals.

Tuesday, August 24, 2010

How to make Orange Pekoe Tea

For reasons I cannot fully comprehend, the perfect cup of Orange Pekoe Tea can often be quite elusive. Today, however, I have discovered how to make the perfect cup.


Ingredients:

- 1 Tetley orange pekoe tea bag
- Distilled water (approx 1 1/2 cups)
- 1 teaspoon of white granulated sugar
- 1% low fat milk


Steps:

1. Boil the distilled water
2. Put tea bag into cup
3. Fill cup with boiling water until cup is approximately 7/8 full
4. Brew tea for a maximum of 60 seconds
5. Dispose of tea bag
6. Add sugar while stirring
7. Add milk while stirring until tea becomes slightly light brown


Notes:

The amount of milk to use is dependent on the tea bag, the temperature of the water and the purity of the water. I have discovered that tap water is often chlorinated. The chlorine in the water will adversely affect the brewing of the tea. The only way to be absolutely sure that the tea will brew properly is to use distilled water. Even spring water or mineral water can adversely affect the brewing of the tea.

If you do not have access to distilled water, you should allow the tea to brew longer. In this case, the idea is to overpower the existing flavour of the water.

The reason the tea is stirred while the milk is added, is so that you can see the colour of the tea change.

I find that 2% often gives the tea a very milky flavour which is undesirable (for me). 1% milk prevents the flavour of the tea from being overpowered by the milk.

Thursday, August 05, 2010

MacFUSE 64-bit Preference Pane

MacFuse ships with a 32bit version of the preference pane. I managed to find a 64bit version here.

Friday, July 30, 2010

Configure Rails console to show ActiveRecord SQL

ActiveRecord, like all other ORMs abstracts away your database and its associated SQL so that you're effectively just dealing with objects. The abstraction method is determined by the ORM and it sometimes makes mistakes.

Most recently, I built a self referencing ActiveRecord object in order to model a hierarchical relationship. Unfortunately, hierarchies are not easily represented using a relational database because the database consists only of flat tables. There are various ways to represent hierarchy in a table.

However you choose to model your data, you need to make sure that ActiveRecord isn't doing something stupid when you ask for your data.

I kept looking this piece of code on the net so I decided to just paste it here so that I'd remember it in the future.

Add this to the ~/.irbrc file:

if ENV['RAILS_ENV']
# Called after the irb session is initialized and Rails has been loaded
IRB.conf[:IRB_RC] = Proc.new do
logger = Logger.new(STDOUT)
ActiveRecord::Base.logger = logger
ActiveResource::Base.logger = logger
end
end


Now, you can see what ActiveRecord is doing whenever you perform a query.

Wednesday, June 16, 2010

Using Homebrew with a SOCKS5 proxy server

So, one of my coworkers, David Howell recommended that I use Homebrew instead of MacPorts on my new Mac at Wolfram. Homebrew is basically a package management system for keeping open source software up-to-date.

I very quickly ran into a proxy problem. All internet requests must first pass through the Wolfram proxy server. I was able to configure the http and ftp proxy locations, but for some reason, curl, which Homebrew uses to download files, was having a hard time with the proxy configuration.

Prior to configuring the ftp_proxy environment variable, I would get a 500 -- unauthorized error for any ftp request. After setting the ftp_proxy environment variable, I would get a request timed out error. This problem only seemed to be with curl. It worked fine with wget.

After a lot of crazy things -- including a hack to the Homebrew source code to use wget, I discovered a much easier way to get curl to work with a SOCKS5 proxy server instead. All I had to do was add the following line to ~/.curlrc

socks5 = "socks.wolfram.com:1080"


So, I reverted my changes to the Homebrew source code. Everything works great now.

It is interesting that there are no environment variables for SOCKS5 proxy servers in unix. I'd imagine that it is a very useful thing to have. For the moment, I guess you just have to check the man pages for existing tools to see if they have a configuration option for a SOCKS5 proxy and whether they have a configuration file that the configuration can be added to.