Murphy Bytes

September 29, 2010

GAE is Better than EC2

Filed under: Uncategorized — John Murphy @ 11:25 am

Recently, my friend Josh got me interested in Google Application Engine. I’ve been building distributed applications for a number of years now and have always assumed that if I were deploying to a cloud platform, it would be on EC2 because of choice of operating systems, and support for environments that I know well like Rails. GAE doesn’t support the same environments (at least not out of the box). It also abstracts the OS away from you almost entirely. That is the reason that I think GAE is better. I like the idea of not dealing with the OS at all. OS is complicated. To do a Unix application right you need to understand shell scripting, daemons and security. I usually like to set up a user with limited privileges for my applications to run under (no login, limited file system access, etc.) I also like to have a group for users who can admin the application and another group for a more limited set of users who can admin the machine. This of course implies that you set up sudoers correctly so an application admin can start the application as root (the app is then demoted to run as a user with limited privileges after it’s gotten access to all resources it needs to run). And of course you need to be cognizant of things you want the application administrators to have access to like read access to /var/logs. Anyway, it’s complicated to get right. GAE abstracts the OS away from you so you don’t have to worry about any of this stuff which is a good thing. You just focus on the application logic and let Google worry about the OS which is a big win in my opinion.

September 24, 2010

λ + concurrency = evil

Filed under: Uncategorized — John Murphy @ 8:52 pm

I ran into an awful bug in some JavaScript the other day that I thought I’d share as one more reason that non-functional programming languages are really awful in concurrent or asynchronous execution environments. Without further ado, here’s the code:


function update_watchlist() {

    var selected_instruments = $('div#instruments').data( 'selected_instruments');

    for( var selected =  0; selected < selected_instruments.length; ++selected ) {
    
        $.post( '/getquote',
            selected_instruments[selected],
            function( quote ) {
                $('div#quote_last' + selected ).html( quote.last );
                $('div#quote_volume' + selected).html( quote.volume );
                $('div#quote_datetime' + selected).html( quote.datetime );
            },
            'json'
            );    
    }
  
}

This code is supposed to use JQuery and ajax to update a watch list of quotes. Data values for each quote are stored in numbered divs where the div number matches the index in selected_instruments which is an array of information needed to look up a particular quote. In other words we update div id=’quote_last0′ with a quote that we look up using information in selected_instruments[0]. Can you spot the problem?

What is the value of selected in the lambda function passed to $.post? We don’t really know because post is an asynchronous call, the lamda function


            function( quote ) {
                $('div#quote_last' + selected ).html( quote.last );
                $('div#quote_volume' + selected).html( quote.volume );
                $('div#quote_datetime' + selected).html( quote.datetime );
            },

is only called after the http post to the remote server returns. By the time this has occurred, selected has passed out of scope. The fix for this problem would have been to make lambda functions in JavaScript more like first class functions so in this case, the only way to pass the index data to the lambda function illustrated above would be to pass it in the post data, and then have the server return it in the argument passed in the lambda function as illustrated below.


function update_watchlist() {

    var selected_instruments = $('div#instruments').data( 'selected_instruments');

    for( var selected =  0; selected < selected_instruments.length; ++selected ) {
    
        $.post( '/getquote',
            {
                // selected is a valid variable here
                instrument : selected_instruments[selected],
                index : selected
            },
            function( result ) {
                // result.index = selected passed to post target and returned
                $('div#quote_last' + result.index ).html( result.quote.last );
                $('div#quote_volume' + result.index).html( result.quote.volume );
                $('div#quote_datetime' + result.index).html( result.quote.datetime );
            },
            'json'
            );    
    }
  
}

September 23, 2010

Media Storage System

Filed under: Technical — John Murphy @ 11:08 pm
I just picked up a Western Digital My Book network storage device. I needed something with a bit of space to manage backups for all our family computers and it had be networked so I could set up cron jobs ( or a scheduled task for Audrey ) to automate the backup process and insure it occurs on a regular basis. I was a little concerned when I went to purchase the device because, as is usually the case the device was advertised to support Mac OSX and Windows 7. Nothing about Linux. I was pleasantly surprised when I got the device home. It has a cheesy web interface and after clicking the advanced management options, I discovered a check box that allows you to enable ssh which I did and connected to the box. I then typed uname -a and discovered the device OS is Linux running on an ARM 9 processor. A quick tour of /etc/init.d revealed the device had a series of network daemons that could be enabled by symlinks. These included nsfd, sshd, mini_httpd, inetd, smbd, fuse and others so I knew I could mount the WD device on my Linux boxes to back them up. I was unable to get NFS working, I could mount the WD file system only as read only which wasn’t terribly helpful. Here is the entry I put in fstab.

192.168.1.14:/DataVolume/Public /mnt/nfs nfs default 0 0

Anyway, I ended up using fuse instead and that works fine. For reference, to get this working on an Ubuntu box do the following.

sudo apt-get install sshfs
sudo usermod -a -G  fuse yourlocaluser
sshfs root@192.168.1.14:/DataVolume/Public /mnt/nfs
WD Digital Image

September 11, 2010

Florida Fruitcake

Filed under: Uncategorized — John Murphy @ 9:51 am

The following is an excerpt from a Facebook conversation about a Gainseville, Florida preacher gaining world media attention by threatening to burn the Qur’an. I reposted it here because I think it highlights what can be great about media today. To be specific, I’m referring to how new media allows us to add depth to a particularly inane news item.

Original Post

This is a little frothy, but it gets the ball rolling. We’ll call the author ‘Bob’.

Quit giving “religion” special rights. It’s fiction. Like Duck Tales. I’m going to burn my VHS copy of Duck Tales. It’s the SAME. THING. Remember when some guy was burning Harry Potter? I’m sure some hard core fan would be shattered by that. It’s all just a really old Japanese comic book convention. Would you threaten war and curtailment of the first amendment if I burned a Pokemon comic book?

Entertaining rebuttal from ‘Sue’

Dude. I would like to posit that burning a religious book is not about “religion.”
It’s about social prejudice. Historically, societies that burn books are intellectually unsound, morally deficient, and violent. No one cares about the actual theological content of the book; it’s a symbolic act of hatred against an enemy. It’s a threat. It’s like saying, I would destroy all your people if I had the power. Book burning is the first step in a process of syndicated terror—and this is consistent across history—that leads to physical violence towards people in a specific social group, ethnicity, or culture.

“Where they burn books, they will also ultimately burn people.” –Heinrich Heine, prophetically, in a book that was ceremonially burned by Nazis in 1933.

It’s not about giving “religion” special rights—it’s about giving people the right to live without fear. To live without fear of being singled out and persecuted for their beliefs or their background. ( Like having to wear a yellow star.) Book burning is the first step. It’s just that religious books happen to make better effigies of entire cultures than comic books do. (Although I think with Duck Tales, you could support a legitimate argument for a spiritual paragon of culture…)

Bob replies…

It’s true that there’s an element of deliberate symbolism going on here, a point being shot across using a something under the surface of the book itself. And in the right situation, I definitely see the horror of the symbolism present.

I would rather see a flag burn than a book, though neither would especially blow me away. I would be more amazed by how stupid these people are than offended by what they are doing. Which I feel is a better response to these people, because it’s not the reaction they’re trying to get out of us. When this story initially broke, I just ignored it, just another crazy guy doing something crazy. I thought this was a better story about how America needs a better education system, or better access to schizophrenia drugs.

My thing is, are we going to let some nobody in Florida send the official shot down the bow? In the internet age, anybody can burn a religious book, and in minutes, anybody in the world can see it. Here’s a guy burning a bible and a koran at the same time, just now. We don’t even need to wait for the Florida guy to do anything, the deed is done: http://www.youtube.com/watch?v=MZ4rBJfcIfE

In order for us to live in the new media world, we need to stop taking crackpots seriously, or we will not be able to live cohesively. There’s probably one Japanese guy in Japan that hates America and burns flags and burgers and whatnot. Do we let that destabilize our relationship with Japan? Is he flooded with reporters? Does the Prime Minister of Japan go to his house and beg him not to do it?

If it was somebody with real authority burning books, yes I would be very worried. But we’re talking about one screwball here and his tiny little whatever-it-is. He doesn’t have real political power, or a standing army. I really don’t understand how he become the official “okay we’re going to burn books now” guy, who is “negotiating with the mosque people” and after this whole thing is over, I would bet money we’ll never hear about him or of him ever again. If people settle down and realize nothing will come of this, it probably won’t even make the history books.

‘Sue’ weighs in again…

The difference is that Jones isn’t just a random guy in Japan burning a burger, or a guy on YouTube showing how both the Bible and the Koran are made of paper and therefore ignite easily.

Those are both merely random acts of silliness, definitely not to be taken seriously, I agree. So here’s why Jones is more dangerous than a random guy:

1) Jones is an established anti-Islam, anti-Muslim, anti-Arab author. He hates the entire religio-ethnic group and thinks they should die. And he has published books to that effect. So he’s not just a guy holding a Bic to some paper. He’s doing it out of outspokenly racist hatred.
2) American soldiers are at war in places like Afghanistan, where there is violence between religio-ethnic groups. That is very different from a guy in Japan burning a burger, right? We’re not enemies at war there. Jones believes that American Christians are at war with Muslims at large. He is sending this as a message, almost as if the book-burning were an act of war itself.
3) The burning was going to be on September 11th. That’s huge. That’s not just some guy on YouTube putting up a video of a fire. That’s an act of war. Jones sees that as the date on which Muslims declared war on Christians. If he commenced with the burning, Muslims abroad could get the impression that that’s what all Christians believe; that the two religions are opposed and hate each other. Which is NOT the case. The burning could legitimize the dynamic polarity between two sides which are not actually enemies. It could potentially be as large a catalyst as the German book-burnings of 1933, which were carried out by University students. Nobodies.

Anyway he’s already said he won’t go through with it, so you’re right, I don’t think it will make the history books in the end.

Yours truly weighs in

What a fabulous discourse. I really love how Sue ties in historical events to support her points. I have the historical perspective of having been around to experience the mass media during the sixties through today. When I was a kid, I don’t think we wouldn’t have heard of Jones. The US national news outlets were controlled by the big three networks who in turn voluntarily subscribed to certain standards of good taste (don’t remember what these were but it was the Better Broadcasting Bureau or some such). The upshot of this is that news reporting was much more fact based and the agendas of the broadcasters were expressed in what news they chose to report, not how they reported it. You saw things like real combat footage with blood and screaming (unlike sanitized war reporting of today) but not much about crackpots like Jones. Of course we did have Abbie Hoffman, but he didn’t take over the news to the degree that Jones has, plus he actually had something to say. Note that the their was a lot of coverage around the trial of the ‘Chicago 7′ but it was not about Hoffman himself even though he was extremely flamboyant and media savvy. My point is, that now there is no such control and it seems like things become significant through some sort of emergent mob mentality more than any other way. I don’t know if that is good or bad, but what’s scary to me is the degree to which people can be influenced by this and not even know that they are being influenced. It’s also disturbing to me how mainstream media focuses on sensational news that has high emotional impact to drive profits instead of news that has high impact from a economic/societal basis. I think that the upshot of all this is that there is a large cohort of educated critical thinkers are abandoning traditional media (TV/Radio) and getting their news from the internet. Unfortunately, this trend further dumbs down the audience of people who still watch mainstream media which leads them to dumb down their content and pick up increasingly sensationalistic content that is often of no real importance.

Powered by WordPress