More Wget

It's hard to understate the usefulness and robust feature set that most of the GNU tools have in their arsenal. Today, I'll make mention of one such tool, wget, and a novell use of the command. As I go through my work, I find that sites we agree to take over have little structure. They generally were slapped together a long time ago, with little thought to organization, made with Dreamweaver or, Stallman forbid, FrontPage. I'm not judging; as long as something looks okay in the browser, a company can proclaim, "We're on the intarwebs!" However, tracking down all of their pages to be converted into a CMS, for instance, can be time consuming. Not wanting to waste a client's money by searching through the source for links and images, then manually reconstructing the layout of the files, I fell on my trusty GNU tool wget. (I also did not have FTP access, but I knew there were dead pages that I didn't want to resurrect. Using wget in this case helped me retrieve only the pages that were still linked to from the main page). Here's a variation of the incantation of wget I used:

wget -r -A '*.htm*, *.jpg, *.png, *.gif' -l 3 http://www.example-site.com

What's it all mean? -r: wget should retrieve recursively -A: takes a comma-separated list of patterns to match files to accept (use -R to reject). In this case, we want all htm, html, and most picture format files. -l: denotes how far down the rabbit hole to venture. I started with 1, so only links from the first page were parsed and followed. I then tried 2, following links that were a level below the parent and compared the resulting structure. Trying 3, I found no difference between 3's results and 2's results, meaning all links had been followed and accounted for. The result: A directory called www.example-site.com that contains the files in their layout on the server. Now I knew which pages needed converting and which images to add to the new site. A side note: A handy way to see the layout of your newly downloaded directory is to use the tree command.

tree www.example-site.com/

will display something like this:

www.example-site.com/ |– about.html |– calendar.html |– committees.html |– contact.html |– otherdir | `– index.html |– images | |– header.gif | |– logo.gif | `– spacer.gif |– index.html

scoopholiday.html

Walk the Walk

I've had the pleasure of working on the technology that powers iliveinspired.com and know that the founders, Rob and Chris, are working their butts off to make this a great service. Armed with not much more than inspiration and determination, they are taking their service to the world by foot. Their first foray into marching marketing was to sign the Dalai Lama on as a content provider. Not only did the Dalai Lama receive them (read about their trip, starting here), but he embraced them and their message and agreed to work with the service. Now these two are on a mission to sign Oprah and are generating some press about it. Pick up the story from their blog here, and then read about some of the press they've gotten here, here, here, and here. This is a great service, there are lots of different themes to choose from, and it's a cheap service that can provide a lot of value. Why else would they offer the first 45 days free of charge? What's keeping you from living inspired today? Visit I Live Inspired and start receiving daily inspiration on your phone.

Iraq and Iran Pose Threat to False Strength of the US Dollar

It is hard to trust politicians, isn't it? I know I believed Colin Powell's speech to the UN detailing Iraq's WMD capabilities, with the mobile units and all that. That trust has gotten us involved in an unconstitutional war, one that has cost us and the Iraqi people dearly in lives, property, and money. Still, there is one politician who can be trusted, mostly because what he's been preaching in the House has come to pass in our experience. It should be no stretch to know I'm talking about Ron Paul. What I have come to learn is that Ron Paul is dead-on when he talks about the negative impact our foreign and monetary policies are having on our standard of living. While modern Republicans and Democrats think they represent different ideals, they are really two heads of the same beast. Both encourage a welfare state in our country; the Democrats just support a more visible version. In an article written by Ron Paul in February of 2006, Paul lays out the last 100 years of US monetary policy, and shows, in crystal clear HD detail, how the Federal Reserve and the Federal government have given us a very false sense of prosperity. In essence, because of the government and the people of this nation as a whole, cannot live within their means, we have had to control the value of our dollar by force, either covertly overthrowing governments that threaten our dollar supremacy, or by outright war. The problem is that, militarily speaking, we are unmatched in the world in military might. Why that's a problem is that, rather than producing more goods and exporting them, generating wealth, we are the schoolyard bullies who, when someone questions the value of our dollar, we push them around until we get what we want. So it was with Iraq and Saddam. As the world's reserve currency, the US dollar was the only currency used in pricing oil. In November of 2000, Saddam decided he would sell oil in Euros, challenging US dollar dominance. Before this time, there was no talk of Saddam and his threat to "national security". Using 9/11 as a false springboard to rally support, the US military went in, and soon after Hussein's capture, Iraq was selling oil in dollars, not Euros. A similar situation occurred in 2001 in Venezuela when an Venezuelan ambassador mentioned the possibility of selling oil in Euros. Within that year, there was a coup attempt supported by the CIA. Fast forward to today and Iran's plans to form an oil bourse that would sell its oil in a handful of non-dollar currencies, including the Euro. Following this announcement and subsequent execution, war drums began pounding in Washington, as the President fabricated Iran's nuclear armament program to scare Americans into another engagement in the Middle East. Rumors abound, with one saying Bush wants us in Iran by the summer. What is clear from reading the article is that our flawed and failed monetary policies are crumbling around us, and rather than face facts and make appropriate changes, we are resorting to violence against those that challenge our fairytale. Like punching a kid that tells you there's no Santa, forcefully stopping countries from conducting business, particularly oil exports, in competing currencies only delays the inevitable collapse, and worse still, alienates us from the rest of the world who perceive America as a bully living in a dream world. Are we surprised at how little support across the globe we have anymore? Sure, countries roll out the red carpet for us when we visit because they fear our military, but when it comes to supporting our inane wars, their support proves scarce. Dr. Paul's article is much longer (probably a 15-20 minute read) and runs through a lot more of the history and implications, but it is very much worth the time to read it and contemplate the consequences of voting in McCain, Clinton, or Obama, all of whom support war to varying degrees (maybe not Iraq with Obama, but he still supports operations in Afghanistan and possibly Pakistan). Keep in mind, too, that the article was written in 2006, and how much of its foretelling has come true. Remember, a vote for Ron Paul is a vote for true peace, not just withdrawal from Iraq. Join the REVOLUTION!

McCain Not Fit To Lead

It is easy to convince yourself that John McCain is able to be president. He has served in the Senate for years and is a veteran of our Armed Forces. Sounds pretty much like a textbook president. Except he's not fit. The presidency requires more than a militaristic view of the country and world. The economy can't be run with an iron fist; it must flow and have a life of its own, with the government protecting the economy's ability to thrive, not force-feeding it fertilizer in the hopes it would grow faster. McCain, by his own admission, doesn't "get" economics (for more on McCain and his economics squad, read this article from the Weekly Standard and you'll see the people he cites as advisers have economic views that are antagonistic with the others). The problem with not "getting it" is that national security and the economy are married issues. You can't get one and not the other. In an interview between Nathan Gardels and Nobel laureate Joe Stiglitz (Nobel Prize winner in Economics in 2001), Mr. Stiglitz responds to this lack of knowledge on McCain's part:

Gardels: The economic costs have now come back to undermine the whole post-9/11 security effort. When John McCain says he's not interested in and doesn't understand the economic aspect of things, and only knows about how to keep America safe, what does that say about his leadership capability? Stiglitz: If he doesn't understand the economy, he doesn't understand security. If we had infinite resources, we might be able to have perfect security. But America, like every other country, has resource constraints. That means you need to be smart – that is, economic – about the money we spend. If you weaken the American economy, you won't be able to find the resources you need for security. The two cannot be separated.

Sadly, this critique can be made of the two front-runners in the democratic race as well. What we need is a candidate who gets the economy and foreign policy. Hmm, Michael Scheuer knows all about bin Laden and foreign policy and he is on record as saying that only Ron Paul gets it. Dr. Paul is also the only candidate that can go toe-to-toe with Ben "I'm Alan Greenspan in a bigger man's body" Bernanke, head of the Federal Reserve and make him squirm. So Dr. Paul gets the economy. A candidate that gets foreign policy and the economy?!? Incredible! And yet, because of the nanny state our country has devolved into, people seem to not question the media's anointed Republican candidate. A man riddled in controversy (Keating 5, improper relationship with female lobbyist), lacking in moral integrity (dumping wife after she has an accident and marrying trophy wife a couple months later), embraces more war-mongering (stay in Iraq 100 years, bomb bomb bomb, bomb bomb Iran), and an ardent supporter of Bush Co.; no, John McCain is not fit to run this country. Join the REVOLUTION!

Michael Scheuer and Ron Paul

There may not be a better authority on Osama Bin Laden than Michael Scheuer. Intimately involved with the tracking down of bin Laden from at least 1996 to 2004, Scheuer has also written several books dealing with the handling of the Middle East by our government over the last 40 years or so. So when this man speaks on the Middle East and bin Laden, he speaks with authority that is unrivaled by most anyone else. With that in mind, have a listen to an interview he gave recently (video was posted February 19th, 2008). Two things, among the many, that I found enlightening: first, Scheuer makes it clear that bin Laden and al Queda do not hate us for our freedoms, liberties, etc, as Bush, Guiliani, et al, have tried to ram into the conversation. It is about our involvement in the Middle East that bin Laden fights against. Second, of all the presidential candidates, Scheuer believes Ron Paul "gets it". Having a girlfriend invested in the green movement, I'd be remiss to comment on another bit of Scheuer's interview and I'll paraphrase my understanding of his remarks. When you look at the Middle East, what is there that is of interest to the US? Oil, obviously. Hmm… umm… gee… well… Not much else! So if our government were to get serious about investing in green energy and not using it to garner support while not producing results, we'd lose our interest in the Middle East, at least from a policy perspective. So using less oil = stopping the support of terrorism! Here's my beef for the current crop of Bush clones: they preach Christianity, family values, and all that. Fine, all well and good. However, it seems not a week goes by that a Bush supporter in the Congress doesn't go down in flames with a scandal. But most important of Jesus' teachings was the Golden Rule: Do unto others as you would have them do unto you. Take a moment and think back to how mad, upset, fearful, irate, how incensed with anger you were on September 11th, 2001. Planes were high-jacked and rammed into the World Trade Center. Now imagine that level of violence occurring everyday. Now double it, and double that. You're starting to get an approximation of what the average Iraqi goes through each day. Imagine having to cope with all of those emotions everyday. Imagine, upon waking, not knowing whether you'd live or die in some suicide blast or gun fight. A terrible world for anyone. And yet our government is subjecting a country to that everyday with their occupation. I implore you, regardless of political affiliation, to investigate Michael Scheuer's writings and interviews and see an expert talk about the situation. Then compare that to the view given by your favorite candidate. More important than any other issue today is our foreign policy, including the economy. Our next president must understand what's at stake with respect to the rest of the world, not with respect to a small part of it (namely the European Union countries). The slim silver lining here is two-fold. Wean our economy and way of life off oil and we lose interest in the Middle East, and, support Ron Paul and bring a man into office that is knowledgeable in both foreign policy and the economy. Join the REVOLUTION

Fibonacci stream

The Fibonacci sequence: teacher of recursion for so many Computer Science students. But can it also teach us about streams? Yes! The function to build a stream (in Javascript):

var fib_stream_maker = function() {
  return (function() {
    var a = 0;
    var b = 0;
    var c = 1;

    return function() {
      a = b;
      b = c;
      c = a + b;
      return c;
    }
  })();
}

Let's break this down so Ben can follow along. First, the inner most function:

return function() {
  a = b;
  b = c;
  c = a + b;
  return c;
}

This anonymous function returns the next number in the sequence. Looking one level of scope higher, we see the variables a, b, and c declared:

function() {
  var a = 0;
  var b = 0;
  var c = 1;

  return function() {
    a = b;
    b = c;
    c = a + b;
    return c;
  }
}

So we initialize the variables and then return a function that increments those variables, local to the inner function's scope, so we can have multiple instances of the function running without collision of variables. To build the stream factory, we wrap the initialization function in parentheses, creating a continuation, and then execute the wrapped function, creating an initialized fib stream function. This is then set to return when the fib\stream\maker is called as a function.

var fib_stream = fib_stream_maker();

fib_stream(); // returns 1
fib_stream(); // returns 2
fib_stream(); // returns 3
fib_stream(); // returns 5
fib_stream(); // returns 8, etc...

This is only touching the surface of streams but I thought it was pretty cool that the Fibonacci sequence can be utilized to teach such important concepts as continuations and streams. Code on! Update While explaining the inner workings of the above code to CD, she asked a very astute question, one that Ben probably would not have, "What about going backwards in the stream?" A just question. Let's look at a table of how the values of a, b, and c act as the stream goes forward first (this will help us design our algorithm later).

  a b c Returns
Creating fib\stream 0 0 1  
fib\stream(); 0 1 1 1
fib\stream(); 1 1 2 2
fib\stream(); 1 2 3 3
fib\stream(); 2 3 5 5

So to go backwards, what do we need to do to values of a, b, and c? We need to assign b's value to c, a's value to b, and the difference of c and b to a, and still return c. In code, this would look like:

c = b;
b = a;
a = c - b;
return c;

To integrate this into the above example, we need to pass a boolean parameter to the inner-most lamda function and test to see whether to forward or reverse the stream. Let's see the inner-lamda now:

return function(go_forward) {
  if ( go_forward ) {
    a = b;
    b = c;
    c = a + b;
  } else {
    c = b;
    b = a;
    a = c - b;
  }

  return c;
}

We may want to put an additional test to see if we are at the beginning of the stream again:

return function(go_forward) {
  if ( go_forward ) {
    a = b;
    b = c;
    c = a + b;
  } else if ( a == 0 && b == 0 ) {
    ; // do nothing
  } else {
    c = b;
    b = a;
    a = c - b;
  }

  return c;
}

Let's see it all as one big fun function:

var fib_stream_maker = function() {
  return (function() {
    var a = 0;
    var b = 0;
    var c = 1;

    return function(go_forward) {
      if ( go_forward ) {
        a = b;
        b = c;
        c = a + b;
      } else if ( a == 0 && b == 0 ) {
        ; // do nothing
      } else {
        c = b;
        b = a;
        a = c - b;
      }
      return c;
    }
  })();
}

And there you have it. Thanks CD for bringing up this interesting idea! What a nerd!

Save the Tongass

Add your name to the list of those that want to save the Tongass (read more here). Call (202-205-1661), write, or email Abigail Kimbell of the US Forest Service and let her know your disapproval. The form email sent from the NRDC site is:

Chief Abigail Kimbell, U.S. Forest Service 1400 Independence Avenue, SW Washington, DC 20250-0003 Dear Forest Service Chief Kimbell , I strongly urge you to protect all remaining roadless areas in the Tongass National Forest and to direct Forest Service officials not to increase costly road-building or logging in this precious national treasure. Roadless areas comprise our last wild places and they should not be made vulnerable to logging, drilling or other development. As a nation, we must continue to safeguard the heart of our national forest legacy by protecting the ecological health, wildlife habitat, drinking water and recreational value of those few American forests still unspoiled by roads. It makes no sense to use taxpayer subsidies to destroy the Tongass, America's great rainforest and one of the crown jewels of the national forest system, and jeopardize all that it offers for local hunting, fishing, recreation, tourism and subsistence use. Time and again, citizens like me from around the country have called upon you and the administration to protect the Tongass. It's time to heed this overwhelming public sentiment by preserving, not destroying, the remaining wild stretches of this truly unique part of our natural heritage. Sincerely, YOU!!!

Save $150 Billion Much?

It's a sad state of affairs that we as voters must wade through so much posturing and pandering by the presidential candidates. Particularly hard is when we find out after they are elected that their words were vaporous and meaningless. What's a voter to do? A study released January 29th of this year by the National Taxpayers Union Foundation helps tax payers cut through the facade and see the real truth, expressed in hard numbers. Keep in mind that the United States has trillions of dollars ($9,200,874,834,693.13) in debt, is spending close to $1 trillion a year on Iraq and Afghanistan, and is facing the housing market implosion. Now, with all this economic unrest, which candidates actually want to do something about it and save some dough?

The four respective frontrunners in the two parties (John McCain, Mitt Romney, Hillary Clinton, and Barack Obama), proposed overall fiscal policy agendas whose net effect would raise annual federal outlays between $6.9 billion and $287.0 billion.

The top-tier GOP candidates often portrayed as "conservative" (Mitt Romney and Mike Huckabee) actually called for significantly larger spending hikes ($19.5 billion and $54.2 billion, respectively), than the so-called "moderate conservative" (John McCain, $6.9 billion).

Among Democrats, Barack Obama, often described as ideologically more "moderate" than Hillary Clinton, actually has the larger agenda of the two ($287.0 billion vs. $218.2 billion).

Defense-related spending items received the highest proposed spending increases among Republican candidates. Huckabee and Romney, for example, offered $67.2 billion and $40.6 billion, respectively. Among Democrats, Clinton's biggest boost goes toward health care ($113.6 billion) and Obama's for economy, transportation, and infrastructure ($105.0 billion).

Two of the eight candidates proposed sufficient spending cuts that more than offset their new spending plans: Rudy Giuliani (-$1.4 billion) and Ron Paul (-$150.1 billion).

Taking into account that Rudy Giuliani has dropped out, this makes Ron Paul the only candidate that actually wants to save the country some money, and he wants to do it on a large scale. Why are we pouring in so much money in taxes, to support a government that doesn't represent us? Why would you support a candidate that wants that trend to continue? Where is this money going to come from? Would you rather not pay income taxes? I know I would. What if you got to keep an extra third of your income? Don't you think that's a bigger chunk than a proposed $300 tax rebate Congress is now considering to "stimulate" the economy? I know it is significantly more for me. I would rather spend the money that I earned than some small rebate the government gives me. We don't know the source of that rebate either. The administration is currently engaged in deficit spending, racking up more debt to pass on to future generations. How long until China calls in those debts? It's time to make the government stop spending, and the only way to do that is by electing Ron Paul, the only candidate left that is 100% for real about cutting spending and saving US citizens their hard-earned income. Read his views, compare them with an open mind to the other candidates, and you'll see Dr. Paul is truly about getting our country back on track. Join the REVOLUTION

MySQL -> CSV

Always on the lookout for increases in efficiency, I love when I find a slick snippet of command line goodness that makes a hard sounding task simple and quick. I was tasked with creating an email list from a database and putting it into a csv format, and had only the command line to interface with the DB. My first attempt revolved around using the SELECT … INTO OUTFILE syntax. Unfortunately, I was unable to write out to a file with the DB user I had access to. What's a fella to do? Unix pipes to the rescue. First, the whole command:

echo "select * from example;" | mysql -u user -p dbname | tr '\V\I' ',' > filename.csv

Let's break this down, in case Ben is reading and can't follow along. The echo statement contains your query. It is sent to the mysql command, which connects you to the database and executes the query, returning the data in tab-delimited format to the console. The tr command reads from STDIN, and replaces tabs (Ctrl-V Ctrl-I) with whatever delimiter you want (in this case the comma). The final touch is sending it to a file of your choosing. Note - You actually have to type the Ctrl-V Ctrl-I when entering this command. Copy/paste won't cut it in the example above. Note - You typically do not want to actually enter your mysql password on the command line, as commands run are typically logged. Omit the password to force mysql to ask for it (it won't interfere with the query). And if you don't have your mysql access password protected, WTF? You're asking for trouble. So there you have it. Simple, easy to follow, effective. As always, this example can be extended into a variety of different ways. It's up to you to figure it out (you can, of course, pay me to figure it out).

Happy MLK Day

As we celebrate the life and message of Dr. Martin Luther King, we need to consider his work unfinished. With the presidential campaigns in full force, spreading their vision for the future, it has become clear that one candidate, for me, is truly offering a world view that makes sense. Dr. Ron Paul is bringing a vision that actually differs from the other candidates. He is challenging the status quo and it is working because there are constant attempts to exclude him from the debates, from political coverage, to label him "un-electable" (thanks Faux…I mean Fox News). Despite this, Dr. Paul's message is building enthusiasm and excitement across the country. There are many issues important to me that the candidate must offer solutions to for me to be interested in them (a note: we are interviewing these candidates to be our president, so we need to be as demanding as possible so we get the best. Don't settle for one based on party lines; consider each viewpoint, which means actually reading about candidates you don't agree with). First, and probably most important, is Iraq and our withdrawal from Iraq. Goodbye most of the Republicans. Dr. Paul wants us out and for so many good reasons. I believe Dr. Paul is 100% correct in his assessment of why 9/11 happened (speaking of, does Giuliani appear if you say 9/11 three times, like Beetlejuice?). Our foreign policies, our military presence in so many foreign countries, our lust for oil all contribute to us treating other countries, particularly in the Middle East, as second- or third-class world citizens. Sound familiar? Think back to this country's struggles with civil rights and all the emotions and violence it created (Civil War anyone? KKK anyone). Why do we find it so shocking that we treat foreign governments in much the same way blacks were treated, and the people of those governments lash out at us much the same way the African-Americans lashed out at the establishment for the last 150 years? Fortunately there were voices like MLK to calm the violence and provide a peaceful plan to uplift society. Ron Paul speaks of this peace, on the global scale, and we need to heed that voice! A second issue, which, while just barely lower on my list than the war, probably is the most important issue our country is facing, and that issue is the economy. For too long the Federal Reserve (a private institution) has held our money supply in its clutches. The FR has gotten us so far away from the Gold Standard that our money is severely devalued. Talking about Nevada and its recent caucus, Dr. Paul wrote in his newsletter:

Nevada, by the way, is known as the Silver State for a reason-its great mining industry produced the precious metal for the beautiful silver dollars minted at the fabled Carson City mint. These constitutional coins, include .775 ounces of silver, in accord with the Coinage Act of 1792. Today these coins, worth $1 in my father's day, have about $14 in silver. That is, the dollar is worth 1/14th of what it was, thanks to the counterfeiting Federal Reserve.

1/14th of what they were! Economic theory is hard to swallow for most, I know, but this is a pretty clear example of the dire position our economy is in. To make matters worse, this was the situation before the housing bubble burst, and before the Iraq War. You toss those two economic clusterf@cks into the mix and its no wonder the word "recession" is tossed about so freely. From an economic standpoint, we're sending billions of dollars each year to Iraq, in the form of troops, aid, weapons, etc, and yet we are in the midst of a huge housing crisis, our dollar is severely devalued, and we are being loaned money at an alarming rate by China to finance the war. Do we really think China will not use our debt to them as leverage to get what they want? Since when did the United States put themselves in the pocket of a communist country? And from all the discussion, not a single candidate, aside from Dr. Paul, is seeing the connections and planning accordingly. They want to fix the effects, rather than address the causes, and it seems most want to print more money to assuage the economic crisis. It is clear to me that Dr. Paul is the guiding light that truly offers the right kind of change, a principled change, based on sound reasoning and policy, and brought to us by a principled man. No candidate can be one-size-fits-all to the American people; we are too diverse for that to ever be the case. However, I believe Dr. Paul's message to benefit most the common man, middle- and lower-income families, and the American image abroad. Isn't it time we had a president who actually had policies intended to let Americans live as they see fit and not as some bureaucrat in Washington sees fit? If so, read his thoughts on the issues and donate to Dr. Paul's campaign today! Join the REVOLUTION!