Mongrel is a lightweight web server that is quite popular with the Ruby on Rails crowd. It’s apparently really great at serving dynamic pages and is often coupled with Apache which serves the static pages. Set up is extremely easy
gem install mongrel
and running it is much the same.
mongrel_rails start -d
There are some things that I found particularly annoying about it. Mostly you have to be in the document root of the rails app when you start the daemon for it to know where everything is.
Because mongrel runs one thread at a time it can only answer one request at a time. This can be problematic when you’ve got a busy site with many requests a second (I’ve heard a single mongrel instance can handle around 25 requests a second, but I couldn’t site my source). To overcome this limitation you can run mongrel behind Apache’s mod_proxy and mod_proxy_balancer which allows you to create some psuedo load balancing. This is all done through Apache’s httpd.conf file (or whatever imports you want to add to it). You’ll need to load the proxy modules, the balancer module and the rewrite module for things to work right. My configuration looks something like this:
<virtualhost *:80>
ServerName myserver.com
DocumentRoot "/path/to/doc/root"
<proxy balancer://mongrel_cluster> #This is the name of the cluster group, can be anything
BalancerMember http://localhost:xxx0 # the location of your additional mongrel instances
BalancerMember http://localhost:xxx1
</proxy>
ProxyPass /images ! # Don't let mongrel serve these pages - static content
ProxyPass /stylesheets !
ProxyPass /javascripts !
Alias /appName /full/path/to/your/app #only needed if app resides somewhere other than docRoot
ProxyPass /appName balancer://mongrel_cluster
ProxyPassReverse /appName balancer://mongrel_cluster/
RewriteEngine On
ProxyRequests Off #SysAdmins don't usually like open proxies
# Check for static index
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME}/index.html -f
RewriteRule ^(.*)$ $1/index.html [QSA,L]
# Check for Cached pages
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} -d
RewriteRule ^(.*)[^/]$ $1/ [QSA,L]
# Send all other requests to Mongrel to be dynamically generated
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
RewriteRule ^/(.*)$ balancer://mongrel_cluster%{REQUEST_URI} [P,QSA,L]
# Compress text files so they can be loaded more quickly
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE application/x-javascript
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
As you can see its not overly complicated. The rewrite can be intimidating, but they’re recipes mostly you wouldn’t need to change them. There is some good documentation online, but not copious amounts of it. I’d recommend here and here for more resources, but you’re a smart kid, you can find your own answers using google.
An article in last week’s New York Times caught my eye. The short of it is McDonald’s is now selling a soda in a new size - the Hugo. The Hugo is 43oz. of carbonated beverage that when filled with Coca-Cola contains a whopping 410 calories and sells for as little as $.89 in some markets. Pretty good deal, eh?
The long of it is this: Say you’re hungry and you are an average American family whose income isn’t that high. You’ve been told that you should eat better, but it doesn’t taste as good as going out, it’s expensive and it’s a lot more work. Instead of making a meal for your family you all jump in your minivan and head down to the nearest McDonald’s. Like I said, you’re hungry so you’re going to order a Big Mac some fries and a soda. After placing your order the cashiers tells you that upgrading to large fries and the Hugo will only cost a buck and some change more, thats like 26 more ounces of beverage and 3.8 oz. more of fries. You’ll feed your family of four for less than $20.
That sounds pretty tasty, but was it worth it? It depends on how often you’d like to eat. According to Shapefit.com a Big Mac has 570 calories, large fries have 510 calories and the Hugo, which I mentioned above, has 410 calories. Say you want to splurge or maybe you’re just really, really hungry and you decide to go with the Big-Xtra, that’s 810 calories with cheese. In just one meal you’ve managed to consume between 1400 and 1700 calories. According to the FDA we should consume 1800 calories a day for women or 2000 a day for men. Talking strictly calories you’ve consumed between 3/4 and 100% of your daily recommend calories in one meal. With that kind of consumption you’d only need to eat once a day!
Sadly people tend to eat more than once a day and often the people who are targeted by these tactics are lower income, under educated consumers looking to stretch their dollar the farthest. McDonald’s dismisses these accusations claiming the market drives the business - consumers are demanding product, they are merely supplying the demand.
July 29th, 2007 by Dan Life
Essential
——————
cd - change directory
ls - list directory contents
cp - copy file
mv - move file/rename file
man - show documentation on a command
du - size of directory/file
grep - retrieve text in filecat - print file to screen
tail - print last 10 lines of a file to screen
ln - create a link
tar - pack/unpack archive of a file or directory
ps - list running processes
netstat - show network information
kill, killall - stop a processes
Good To Know
—————————-
sed - string manipulation (insert, delete, find/replace)
top - show memory/cpu usage
df - hard disk usage
screen - create virtual terminals
vim - text editor
diff - compare two files
Last week on This American Life there was a short segment by the guys over at Radio Lab about morality. The question was if you could save the life of four people by killing one person would you do it? In the first scenario where by pulling a lever which directed a train you saved the four people, but a fifth died instead nine out of ten people said that they would pull the lever. In the second scenario where to save the four people you pushed the fifth in front of the train the response was overwhelmingly NOT to push the person.
But why? It’s the same question - sacrifice one, save four. But overwhelmingly the response is that killing a person is better/easier/more justified to save others when you don’t have to been the one doing it. To examine why we have such a natural aversion to being the pusher the team at Radio Lab spoke to a scientist who was looking at the biology of moral decision making. Examining brain scans of people making ethical decisions one would expect that there is unique center of the brain that becomes active when making these decisions. What the scientist found was that there are numerous areas of activity competing for the right choice to make.
Upon hearing this I thought of another article I had just read over at National Geographic about swarm thought. Essentially the apparent intelligence of an ant or a bee is the sum of the intelligence of a the ant hill or hive. The result of many, many simple interactions build a complex system of results that suggest a greater intelligence.
An example given in the article is bees searching for a new hive. Scout bees are sent out and when one discovers a suitable location for a new hive it will return to the swarm and perform a dance advocating this new location. (The dance conveys information about where the location of the new hive is). When enough bees have returned and are doing the same dance the location of the new hive is determined. An almost democratic decision made by the entire hive.
Swarm thought and ethical decisions, what do they have in common? They are simple elements that combine to resolve a complex question. And perhaps a more important question, what does that mean about intelligence, artificial intelligence and computing? I would argue that our intelligence is the same as that of a hive of bees or a school of herring. Our understanding of the world is an amalgamation of competing inputs that drive our thoughts and behaviors. The system of competing inputs is the essence of our intelligence and perhaps can be modeled and reproduced.
If intelligence is a system of resolving multiple inputs then we have already created AI, but how many inputs are required for advance intelligence? How sophisticated must the resolution be? I think the future of computing will answer these questions. As our hardware increases in speed and capacity and our software becomes more capable at modeling our natural world we will see if there is anything more to intelligence than marching of ants and the buzzing of bees.
July 14th, 2007 by Dan Life
Stocks make sense to most people. You give a company some money, buy in as a partial owner, and in return if the company does well you get a cut of the profits. But what of Futures? They’re a little different, let me show you how:
Futures are about contracts and these contracts have a quantity, price and a expiration/delivery date. If you were going to buy a futures contract in, say, cattle you would buy a contract that would guarantee a delivery of 50 head of cattle at $20 a head that would be delivered on July 10th. Now you’ve got a contract worth $1000.
But how do you make money on it? It’s simple speculation. Will the market price be greater or less than the value of the contract when the contract comes due? If the value will be greater resell the contract at a higher price, if you think the value will be lower sell the contract now and get what you can for it.
July 7th, 2007 by Dan Money
If you do any investing you know that bonds are a safe place to put your money for a long term investment. Put a chunk of change in a 10 year Treasury bond with fixed 5.5% return and at the end of the ten years you’ve got a fair return on your investment. But if you’ve looked at the bond market recently (a growing economy, but then there’s the whole sub-prime mess) you’d be lucky to find something with a return greater than 5%. With uncertainty about the state of the economy bonds have fallen to a near record low. So what do you do? Look for funds with short-term maturity dates. Invest for 2 or 3 years and when rates turn around you can put your money back into a bond with a higher interest rate. Consider also municipal bonds which don’t always offer the highest return but are federally tax exempt. Remember that the point of investing in bonds is put your money somewhere safe - low risk with moderate return.
July 4th, 2007 by Dan Money
I recently spoke to a former employer who was interested in hiring me for some programming work in the fall. He’s reticent to hire contracted/consultant programmers because he believes that they are awful at communicating and he doesn’t think he should struggle to convince them to fix bugs on his dime. I added my own .02$ with the thought that they are elitist and arrogant which makes convincing them that there are bugs in the first place incredibly difficult. Now I’m not saying all code for hire programmers are like that, just most of them.
This point was reinforced today for me scrolling through the UIC ACM listserv. There’s a question about the new Windows 2008 server which quickly degenerated into zealotry, snobbery and name calling. I had thought that the haloed halls of academia would be more resistant to that kind of behavior(HA! shows how much I know), but alack it is not. I shutter to think that these are my peers and that in ten years I’ll still have to listen to them blather on about the how much more they know than that other guy and how he’s so arrogant for thinking he knows what going on.
Edit: The possible irony isn’t lost on me here
I’ve changed things around again and promise nothing about what you’ll find here next time. I’ve thought about making some kind of commitment to this thing, a real effort this time, but I’ve thought better of it. With expectations set too high I’m doomed to fail. Lets see if I can impress myself.
The hot news in this part of town is that I’ve got a great new internship here in Chicago and I’m really excited about the work I’m doing. To keep things on the down low I’m not saying who its with (these things come back to haunt you), but suffice to say that there one of the best companies to work for in Chicago.
Stay tuned, I’m sure I wont keep you updated.
July 2nd, 2007 by Dan Life