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!

Portland is fun

While the weather has not cooperated and given me many sunny days yet, I have been enjoying exploring the cyber-presence Portland has, in particular the Craigslist offerings. Today, however, brings a new entry in the NW Nerdery: a movement to rename 42nd Ave to Douglas Adams Blvd. The site, rename42nd.org, is making a serious effort to have the 42nd Ave renamed in honor of Douglas Adams, most notable for authoring the Hitchhiker's Guide to the Galaxy series. My inner geek smiles wide for this effort and hope they succeed. If you are a Portlander, support the movement. I know I am…

7 Days, 7 Nights, 7 Minutes

One of the projects I've been helping get off the ground is I Live Inspired, an inspirational text-messaging service. The site is good, and the concept is great. One can never have too much inspiration. The founders, Rob and Chris, are on a mission. They are seeking an audience with the Dalai Lama in Indiana and are walking 7 days in hopes of getting a 7 minute audience. They are also keeping a blog of their adventures. These guys are not much older than me and are trying to get a positive service off the ground. Whether they have audience with the Dalai Lama or not, the experience of the walk, the people they've met thus far, and the people they've yet to meet, will change their lives. And we get to share in that through their writing. So take a minute, read up on what the future of America is up to, and if you want some extra inspiration delivered to your phone daily, consider signing up for one of the many great communities at I Live Inspired. * Disclaimer: While I have helped create the site, I do not receive any compensation for spreading the word. I think its a great service and deserves notice.

Pambiche

While highlights abound on the Portland tour, one in particular deserves mention. I've dined at some pretty sweet places and eaten some fairly exotic foods. While they've all been good and memorable, I found that a little Cuban place in Portland has taken the top spot in my dining history. What's amazing about Pambiche is the unassuming atmosphere surrounding the restaurant. Walking up to, I had no idea what I was about to experience. Sadly, I was only able to eat there once while in the city, so I can only speak to one dish, Ajiaco. Described as a "one pot meal that comes brimming with a variety of tropical roots and vegetables, corn dumplings, creole seasoned pork and beef", this tasty meal was unlike any other food I'd tasted. Very subtle flavors and aromas with each spoonful pleased my tastebuds and tummy. And while Cuban food is not traditionally spicy, Pambiche had a homemade spicy sauce which complimented the dish wonderfully. I am not a food critic so it's hard to do the experience justice. Next time Portland dining is available, head over to 2811 NE Glisan and taste it firsthand. I plan on doing just that!

Don't call this number

Telemarketers suck. Soon they will be getting your mobile number. To prevent unsolicited phone calls, give a ringy dingy to 888-382-1222 and take a minute of your time to get on the national Do Not Call list. Make sure you are calling from the phone with the number you are registering. This public service announcement brought to you by the number 15, the number 17, and the letters C and D.

August 27th Emails

I just received an email about August 27th and the proximity of Mars to the Earth. The email claims that Mars will be close to 34 million miles from Earth, the closest it will get for another 2000 years, a distance which will cause it to appear as bright as the moon in the night sky. While the claim is valid, it is what the email leaves out that makes it annoying: the year. This event occurred in 2003, and while Mars was the 4th brightest object in the sky (behind the sun, moon, and Venus), it was still just a small point of light. You can read more at NASA's page concerning the hoax. It is dated from 2005, but explains the email hoax (which has been circulating since 2004) and what is true and misleading about it. So if you get the email, please don't forward it on. It's so 2003…

Portland Gets Greener

I admit, I was hesitant to believe I was actually going to relieve myself of my car when I moved to Portland. St. Louis definitely requires the car to get to almost anywhere I wanted to go. Plus when I need to haul stuff…you can only carry so much on your back and in your arms. So it was with great relief that I found Flexcar via EcoGeek. From Flexcar's site:

Welcome to a new era in personal transportation. It's called car-sharing and it's incredibly easy! You share access to hundreds of Flexcar vehicles, often within a five-minute walk of your home or work. You reserve a car online or by phone; you drive - to a meeting, to run errands, or to hit the lumber yard; and you return to the car's designated parking space, all for one hourly rate that covers gas, premium insurance and 150 free miles. All you pay for is the drive. How simple is that? Plus, Flexcar is convenient, affordable, reliable, and great for the planet. Join the transportation revolution that washingtonpost.com called the "wave of the future."

I looked at their monthly savings calculator and found the numbers quite pleasant: My average cost of ownership is about $550 per month, mostly depending on the number of miles (which affects gallons of gas purchased and oil changes needed) I drive per month. The cost of Flexcar, based on the number of hours per month, broke down like this: 5 hours per/month 45.00 10 hours per/month 85.00 25 hours per/month 200.00 50 hours per/month 375.00 So even at a high volume clip, I'm still saving $200-$300 a month. Plus, if I reduce my driving to almost none (which is my intention), that's $500 or so a month I get to keep in my account. Granted, there will be other costs, like bus passes and the like, but by and large, I'll be saving $6,000 a year, and that's nothing to scoff at.

Greener Communities

Given the buzz around a new site that ranks your location according to its "walk score", I thought I'd take a look at how the various places I've lived over my lifetime are stacking up today. The general idea is that a community with a higher score is easier to get around in on foot, there by reducing or removing the need for a car. I have to say, my upcoming move is highly motivated by the desire to be rid of my car for a while.

  • Strasburg, VA: 51
  • St. Louis, MO (High School): 26
  • Elsah, IL (College): 9
  • First house (STL): 54
  • First townhome (STL): 35
  • Second house (STL): 57
  • Upcoming move to Portland area: 82

Definitely moving up the score ladder. I'd like to think that in a couple years I'll be able to get car that plugs into the grid rather than into a gas station pump. At the least I'd like a car that can run on ethanol (a great cellulosic ethanol infrastructure would be great) or biodiesel. But who knows, Portland may be destination forever, and public transportation, biking, and walking may meet my transportation needs. At any rate, I'm looking forward to the move on many different levels.

Eat local

It's no secret that to the best fresh fruit and veggies are the ones that travel the least to get to your kitchen. That's why it is so important to spend your time and money at your area farmer's markets. The benefits, short and long term, far outweigh the negatives. Sure, I can get corn 4/$1 at my local supermarket, but its pretty blah on its own and needs help. Conversely, locally grown corn purchased at the farmer's market near me is delicious without any help from seasonings. With that in mind, it is sometimes hard to know where these purveyors of fresh, local produce can be found. Fortunately there a plenty of websites that can get you started on your search. Two that I have found recently and like the cut of their gib include:

These only open the door to the possibilities near you. One thing to remember…it's perfectly okay to eat seasonal food in season and leave it when the item is out of season. Abstaining from out-of-season foods will liven up your menu by exposing you to a wider array of choices and who doesn't like variety? And sure, this all takes effort, but I think this is effort well spent. Enjoy your local markets!