Wednesday, January 19, 2011

Mathematica TextMate Bundle

I've been working with David Howell on a TextMate bundle for Mathematica. Development has slowed as I find fewer and fewer things to change, to the point that I decided it was time to publish my fork of it in my blog in the hopes that someone somewhere finds it useful.

My .vimrc File

This is my .vimrc file.

syntax enable
set background=dark
set tabstop=4
set softtabstop=4
set shiftwidth=4
set expandtab
set smarttab
set smartindent
set hlsearch
highlight DiffAdd term=reverse cterm=bold ctermbg=green ctermfg=black
highlight DiffChange term=reverse cterm=bold ctermbg=cyan ctermfg=black
highlight DiffText term=reverse cterm=bold ctermbg=gray ctermfg=black
highlight DiffDelete term=reverse cterm=bold ctermbg=red ctermfg=black

" Shortcut to rapidly toggle `set list`
nmap l :set list!

" Use the same symbols as TextMate for tabstops and EOLs
set listchars=tab:▸\ ,eol:¬

"Invisible character colors
highlight NonText guifg=#4a4a59
highlight SpecialKey guifg=#4a4a59

au FileType xml setlocal shiftwidth=2 tabstop=2 softtabstop=2 noexpandtab

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.

Sunday, August 29, 2010

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.


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


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


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:

# Called after the irb session is initialized and Rails has been loaded
IRB.conf[:IRB_RC] = do
logger =
ActiveRecord::Base.logger = logger
ActiveResource::Base.logger = logger

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 = ""

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.

Monday, February 18, 2008

Forcing Windows to Install on the C: Drive

As a Windows administrator, I often find it necessary to re-install Windows. Thankfully, ever since Windows 2000, the number of times I have to format a computer has reduced drastically, however, every now and then, something goes wrong and nothing short of reinstalling the operating system will solve it.

Recently, my Windows XP x64 computer died on me. The problem seems to be hardware related and I have a sneaking suspicion that it is the memory, but I will leave the troubleshooting to the hardware guys at my local computer store since the system is still under warranty. However, my computer doesn't boot. So, I decided to reinstall Windows to fix whatever non-sense happened after the hardware failure.

After booting into the installation routine, I arrive at the partition section and guess what? - The Windows installation has decided to change around all my drive letters and looks something like this:

Drive 1:
Partition 1 - E: 80 GB
Partition 2 - C: 240 GB
Drive 2:
Partition 1 - D: 320 GB

Needless to say, it would be far better if my original installation drive (the E: drive) could be called the C: drive, as it was called in my original installation.

Now, if you google around, you'd find that everyone makes the suggestion of simply unplugging the drives before starting your installation so that Windows is forced to use the first drive letter it comes up with, namely, the C: drive. But we have a problem here. Partition 2 cannot simply be unplugged! It is a separate partition, not a separate drive, and cannot be unplugged without unplugging the partition we want to install on.

Prior to discovering this neat little trick that I'm about to share with you, I used to copy the files from the second partition of the primary drive to a backup disk, reformat and repartition the entire disk, then copy the files back. Needless to say, it wasy very time consuming. Now, before I continue, I would like to warn you right now that this solution is going to require a Linux Live CD, some patience and all your brains. With that in mind, let's begin.

Preparing the Linux Live CD:
The first thing we need to do is to get our hands on a copy of a Linux Live CD. If you already know how to do this, then by all means skip ahead to the next section, in which we modify the partition table and wherein contains the real contribution of this post.

For the uninitiated, Linux is an alternative operating system to Microsoft Windows and Apple's Mac OS X. It is free and supported by a community dedicated to the ideals of free computing. If you're interested in learning more about Linux, I suggest taking a look at Ubuntu, a relatively easy to learn Linux distribution. For our purposes however, we are going to download Knoppix. Knoppix, I find, has much better support for hardware than most other distributions. This is often important to me because I support a wide variety of hardware and I like it that my Live CD works well with all of them. That being said, you can download Knoppix here:

Once you get there, you should click download, pick a mirror and download the latest version. The file that you download is a CD image (.iso). You will need a CD burning tool to burn this image to a blank CD. There are many commercial applications such as Nero and Roxio that you can use to burn the ISO to a CD. If you need a free one, you can try InfraRecorder which you can download here:

Booting into Linux and Updating the Partition Table
At this point, you should have burned the Linux Live CD to some blank media. Pop this media into your broken computer and you should get the Knoppix prompt at bootup. This prompt is provided so that you can pass extra parameters to the operating system before it boots. In most cases, you wouldn't have to type anything here, so just hit enter. But, if you have trouble booting, or if you do need to pass extra parameters in order to get your system to boot, take a look at the Knoppix cheat codes here:

I, for one, have a large monitor and the resolution that Knoppix chooses for me is not a very good choice, so I usually pass the screen parameter so that I can achieve native resolution once I boot into Knoppix. The command I use is:

knoppix screen=1920x1200

Once you've booted into Knoppix, start the terminal which you will see an icon for at the bottom left of the screen. Before we modify the partition table, it is important to first unmount any harddrives that may have been automatically mounted by Knoppix.

$ mount

This will show you a list of mounted devices. Your windows partition will be called something like, /dev/sda1 or /dev/hda1 and it will be mounted in the folder /media. If you see any of these, you must unmount them before continuing:

$ sudo umount /media/sda1
$ sudo umount /media/sda2
$ sudo umount /media/sdb1

Now, double check that there are no further mounts and then start fdisk on your primary drive.

$ sudo fdisk /dev/sda

This will start fdisk. Type p [enter] to list the existing partitions. Now, what we want to do is hide the second partition from the Windows installer. To do this, type t [enter]. You will be prompted for which partition, type 2 [enter]. You will now be prompted for the Hex code. The Hex code represents the file system type described by the the partition table. Hit L [enter] to get a list of partition types. What you'll notice is that there are a very large number of partition types. The NTFS partition is represented by the code 07.

If you look right down at the end of the list, you'll notice that there's one called LANstep which is represented by the hex code fe. As it so happens, a long time ago when there were two flavours of Windows called, Windows NT and 3.1, Microsoft had used the code fe to administratively designate a partition that was not to be touched. Sound a little convenient? I thought so too. I learned about this fe code from the following site:

Which states quote:
fe Windows NT Disk Administrator hidden partition:

Mark Morgan Lloyd ( writes: Windows NT Disk Administrator marks hidden partitions (i.e. present but not to be accessed) as type 0xfe. A primary partition of this type is also used by IBM to hold an image of the "Reference Diskettes" on many of their machines, particularly newer PS/2 systems (at a rough guess, anything built after about 1994). This clash can cause major confusion and grief if running NT on IBM kit. When this Reference Partition is activated, it changes its type into 1 (FAT12) and hides all other partitions by adding 0x10 to the type.
Based on that quote, you should be careful if you're running this IBM kit. Assuming that none of this matters to you, go ahead and type fe [enter]. This will change the partition type of your second partition from NTFS to the administratively hidden NT partition. At this point, you're ready to save the changes you've made and then return to the Windows installer. In order to save your changes, type w [enter]. This will write the changes to your drive. Then you can quit fdisk by typing q [enter].

If you have other partitions that you would like to hide (say on a separate drive, etc) now would be the time to do it, by repeating the procedures described above. When you're finished hiding all your partitions, restart your computer, put the Windows installer back in the drive and then try to reinstall Windows. You'll find that the Windows installer detects the other partitions, but doesn't try to assign them a letter. This is good. Go ahead and install Windows on the 1st partition of your primary disk. You may be prompted about there being other operating systems and that by installing Windows, it may disrupt their operation. This is normal and you can safely ignore the warning.

When you're finished installing Windows, you'll notice that your other partitions are still hidden. You need to unhide these partitions in order to see them again. So, pop the Knoppix CD back in the drive and get back into fdisk. This time when asked for the hex code, use the value 07. This will flag the hidden partition as being a normal NTFS partition. When you restart back into Windows, your previously hidden partitions will become visible.

And voila! Your Windows is on C and you didn't have to repartition or reformat or even unplug your drives from the computer.

I hope this helps people who've had this problem in the past, however, I recommend that you back up your data before trying this for the first time. I cannot be held responsible for any loss of data that may be caused by following these procedures.

Monday, June 25, 2007

What I Do Matters

It's a universal question that most of us ask ourselves at least once during our lives: why am I here, and what is my purpose? Some of us believe in a God, or perhaps we believe in destiny in which case we believe in a purpose, but that purpose has not yet been revealed to us. Many of us do not believe in a God and some of us believe that our destiny can be controlled by our actions. For those individuals, the esoteric question, "why?" is explained by the chain of events that led up to the question and is based purely in logic and an understanding of human behaviour. Purpose, and destiny are no more relevant to the question than the colour of my bedspread is relevant to whether the sun will rise again tomorrow. But regardless of our spiritual persuasion, we still ask ourselves every now and then, what the heck is the point of it all?

Depending on our stations in life, this question may matter more to some than to others. For many graduate students including myself, this question is on our minds a lot of the time. Graduate work is a tedious process of infinitesimally small advances in science. Breakthroughs in any particular field generally occur in more than one place at the same time because the right amount of information was available. Once a breakthrough has been made, people in that field of study look at the result and comment, "why didn't I think of that? It's so obvious!" Well, hindsight is 20/20, and we can't all be geniuses. But what about all of those infinitesimally small advances? Some results are not obvious without those infinitesimally small advances, and what's so special about the breakthrough anyway? Anyone could have thought of it; but those infinitesimal advances are not always so obvious. More importantly, the vast amounts of literature in any given field often make it difficult to find the true gems that constitute an infinitesimal advance as opposed to recycled junk and cross field publications. And since these true gems are difficult to find, the authors seldom receive the recognition they deserve and they ask themselves, "what the heck is the point of it all anyway?"

So what is the point? What did you do today? Not everyone is cut out to be great. Main stream entertainment recognizes this fact and there is an undercurrent in every movie that allows the common man who will probably never amount to anything to feel that his station in life is justified by the way he lives it. As long as he's a good father and provides for his family, the fact that he never won an Oscar, or a Pulitzer or any other recognition or award is largely irrelevant. But why should anyone settle for being so ordinary? It certainly is easier to just accept one's abilities; give in to mediocrity and just exist for the time you have been given. Perhaps, you will enjoy every moment.

But maybe the point isn't to be great. Maybe it is to simply do something that matters in our own ordinary way and to be proud of what we have accomplished. I for one state proudly, that what I do matters. In my infinitesimal advances towards the next breakthrough, I stand proud as the shoulders on which greatness will stand. And maybe that's the whole point.

Wednesday, June 20, 2007

The Scale

I do not claim to know the meaning of everything: from a mathematical standpoint, one can only theorize based on a minimal set of axioms. I have heard a wide variety of theorems about the meaning of life and the nature of existence. The one that holds most true:

"But in this world nothing can be said to be certain, except death and taxes."
-Benjamin Franklin

Of this we can be sure. Of the rest, I humbly assert that it is pulled out of my ass. I also take this opportunity to appologize to all denominations that I will intentionally or inadvertently offend in the following. You have been warned. =)

So what is the universal truth? Balance. Yin and Yang. Opposites, positives and negatives. Dualities and dichotomies. Matter and energy. Symmetry and continuity. Male and female. Earth and heaven. God and man. Balance can be an integral part of our diet and lifestyle.

Whether you believe it or not, balance is the ultimate truth. The universe is an equilibrium and many of the dynamics that we observe, whether chaotic or harmonic are held together by a symmetry that maintains an elegant cohesion. From the minute atom to planetary systems, these balanced dynamics are observable in one form or another. From a mechanics standpoint, Newton's 3 laws of motion epitomizes this balance while from a philosophical standpoint we have Yin and Yang.

Yin and Yang is a dual concept originating from ancient Chinese philosophy. The Chinese believed that the dualities of the world could be expressed as either Yin, represented by the dark element, or Yang represented by the bright element. Yin's dark element symbolizes Gaia or mother earth, and corresponds to the night while Yang's bright element sybolizes activity, and corresponds to day. It is important to realize that Yin and Yang do not represent good and evil. The symbol depicts Yin and Yang chasing one another in a cyclical fashion much in the way that night and day are cyclical events: both elements are crucial to existence as they represent continuity. Eastern philosophies in general are not cut and dry. Hinduism speaks of the Devatas and the Asuras. When literally translated, the Devatas are angels, while the Asuras are devils, however much is lost in translation. The Devatas and the Asuras are a lot like Yin and Yang; their existence is dependent on the balance they share as one cannot exist without the other. The Vedas describe the Devatas as immortal beings that preside over natural processes while the Asuras are immortal beings that preside over morality.

Much of the eastern philosophy is deeply entrenched in mythology. Balance however can be a guiding principle. Consider evolutionary theory and its position on altruism. Evolution states that altruism is a characteristic detrimental to survival and as such is a rare occurrence.

Altruism is a quality wherein the individual expresses "selfless concern for the welfare of others" [|]. It is important to distinguish altruism from loyalty or duty. Duty is often precipitated by a moral obligation towards a benefactor (such as God, or a government) and is not the same as altruism as the benefactor often pledges a reward for the actions of the individual when those actions are performed to the benefit of the benefactor. Altruism on the other hand is a purely selfless action with no expectation of reward, and the vast majority of religions in the world believe altruism to be an important and essential virtue.

The Capuchin monkey of the Amazon rainforest is the most intelligent primate in existence and demonstrates cooperation within their community. If a predator attacks the group, the first monkey to learn of the threat will issue an audible warning to the rest of the group. This act in turn jeopardizes the survival of the individual as it facilitates the predator's ability to find the individual. Strictly in terms of game theory, the move that maximizes the monkey's survival in the short term is to flee, however what is most interesting is that the actual behaviour of the Capuchin improves its entire community's ability to survive in the long run even though it puts the individual at risk in the short term.

Within any community, there are three types of members: freeloaders, cooperators and altruists. A freeloading Capuchin monkey would only listen for warnings, but would never warn anyone else. An altruistic Capuchin monkey would always warn the community regardless of personal risk. Cooperators however, will only help those with whom they have already established a relationship, that is to say, they help those whom they expect would return the favour. When the Capuchins search for food, they will only share their food with the individuals that aided in the venture in a tit-for-tat fashion. In the long run, communities tend to develop a large fraction of cooperators with some freeloaders. Altruistic behaviour in general tends not to survive because the altruistic behaviour is easily exploited by the freeloaders.

Thus we have a fallacy: altruism cannot be a virtue. Altruism is a characteristic that leads inevitably to extinction. The same is true for freeloaders. Cooperators within a society will shun freeloaders, and so while freeloading will benefit an individual in the short term, the freeloaders will be shunned when they are discovered for what they are. Altruists can only exist in a system of primarily cooperative members as cooperators will reciprocate with individuals they trust. There are always some freeloaders and while altruists serve everyone, they also benefit the freeloaders which provides a disservice to the cooperators. Within any system, the cooperator is thus the optimal solution with the overall goal being survival. A balance between giving and receiving provides the appropriate mechanism by which a society can flourish. It is through the atomic exchanges between the individuals that trust is established.

The capitalist system is successful because it rewards cooperators. Money in the capitalist system is the currency of trust and the penny is the most atomic of exchanges. We all know that a rich person however is not necessarily trustworthy, however it is understood that if an individual's living is made through worthy endeavours that contribute to the wellbeing of a society, the money they earn is used to acquire other products and services from other members of the community which helps them survive. Naturally, the system isn't perfect. Money can be obtained through deception, however the cooperators of the community pay taxes, which enables the government to maintain the law which more or less benefits the cooperators. The most important point of this discussion is that the emergent behaviour of this system leads to balance. An individual's lifestyle must be balanced. We should give, but we should also expect reciprocation.

There are many examples of the necessity of balance in the individual such as the importance of a balanced diet. Couples entering into relationships should also be balanced. In this respect, the man should be the equal of his partner and vice versa. Unequal partners would lead to the harbouring of feelings detrimental to the relationship. A woman far more intelligent than her partner, for instance, would cause the man to feel insecure and she in turn would become annoyed when he simply doesn't measure up. Balance in relationships however can be tricky. A characteristic in one partner need not be balanced by the same characteristic in the other. Often, it is more important that the characteristics complement one another in order for the relationship to work.

This complementary balance is seen readily in nature in the form of symbiosis. Nature balances itself through natural processes that regulate everything. The entities on our planet share a symbiotic relationship with everything else within its biosphere much in the same way that a man's character must complement his partner. Their roles in a marriage must complement each other such that both of them appreciate each other's contributions to the relationship. Without this mutual respect for one another, the relationship is destined to failure.

Balance is indeed a universal phenomenon, after all, there can be no shadows without light. It manifests itself in the microscopic as well as the astronomic and we accept it unequivocally in our every day life. But understanding balance within the context of our lives helps us to understand ourselves and gives us the ability to make intelligent decisions. We all know that there is no such thing as a free lunch. So, when faced with a difficult choice, ask yourself the question whether the decision may upset the balance and tip the scales, because if it does, you will have to consider what the reaction will be.

By: Shad Sharma

Broadband: Creating Global Communities

The Internet is one of the most revolutionary technologies ever invented and it is destined to be the single most important technology for creating and binding communities together as well as providing the means that allow these communities to have a global presence and a voice.

Over the last few years, there has been an important paradigm shift in the way the Internet influences the lives of individuals. Web based email giant, Hotmail proved to be one of the most prolific of Internet technologies – comparable to the cell phone in terms of its adoption rate. The Internet blog is also changing the way the media works. No longer are we tied to a specific news source. Clearly some of this success is the direct result of the flexibility to access content and services from any connected terminal at any time, which is the driving force behind Google’s latest and greatest web based technologies like Google Docs and Spreadsheets. On the other hand, peer to peer file sharing networks were the reason for the sudden and explosive adoption of the mp3 audio format, and with its creation, the birth and success of the hardware to play it. Most importantly, web based videos through community projects such as YouTube have found their success and place in the global community, and with the growing demand of these technologies in terms of bit rate versus quality, a faster Internet connection directly translates to a better overall experience.

The existence of web based technologies such as e-mail, p2p and others however, do not yet scratch the surface of the innovation to be realized. The Internet is a virtual world, and the physics of this world are virtually boundless. The Internet has the potential to be a much more user oriented technology than it was meant to be. Within this community, no longer will individuals be tied to their computer. User data will be stored within the network, accessible from anywhere. Computing will be provided by the network as a service. In effect we have the most important of paradigm shifts; the network will be the method by which the user receives computing resources. The Internet will become a vast distributed network incorporating massive data centres such as those owned by Google, large intranets operated by corporations, independent computers as well as smaller, more personal devices like cell phones and this network will be managed by peer-to-peer technology.

Due to the heterogeneous nature of the nodes and complexities involved, it will likely be supported by a hybrid of p2p overlay topologies. The design should adapt to the dynamic nature of mobile nodes while providing fast look-ups and high data streaming rates. A possible solution would involve a dual overlay p2p topology with a structured overlay to support distributed hash tables among persistent nodes and an unstructured overlay that all nodes participate in for quick and flexible connectivity. Persistent connections can be limited to nodes offering computing and data storage services. They would provide a database service backed by the network search operation whose function would provide the foundation for a relational database backed network file system. Each file will have various extensible tags associated with it. The use of this data about data, or metadata in the p2p network effectively incorporates the concept of the semantic web, by creating a network that intrinsically supports its operation. Machine learning algorithms, which have been ignored mostly in the area of communication networks, can help in associating meaning to data. This extensive understanding of the data stored within the network will allow for vastly superior search speeds and more importantly, very accurate and intelligent context aware searches.

Such dramatic changes in the nature of the Internet requires cooperation of both service and network providers. These organizations must consider development and use of new hardware for fast content processing and content routing. Further processing power located at the core of the network will accelerate development and performance of future web services. Security will also be an important factor to many users and it will be partly the responsibility of network providers to address this issue in their developments. Another very important issue to keep in mind is that tomorrow's networks will clearly be much more complex. Management of these resources to provide Quality of Service guarantees is a task which is impossible without careful consideration in the design of protocols and hardware components.

This extremely flexible and secure community network will be the new core network. It will be a service oriented technology which would ideally run as a background process on potentially millions of devices world wide. Libraries, universities, corporations, Internet caf├ęs and individuals will all be a part of this community driven network. Individuals and administrators will be able to dictate the degree of participation within the community network. New applications will be designed to be run through the available services in the network leveraging the vast computing and storage of the entire network. The programs will be accessible through portals ranging from mobile web browsers for cell phones to applications that run on desktops.

The new community network will enable communities stretched across the globe to remain in contact. We have already seen that it is possible for musical bands whose members have never met to produce albums online. Why does this seem at all amazing when open source software is created, updated and maintained by a group of individuals who have potentially never met? Such collaboration is possible due to tight communities, and such access is possible because of the Internet. The next stage in computing use will be made available by the community network. It is the only technology required to remain in communication with the world and it will be the basis for a global community network that brings people together and makes technology accessible and exciting.