Importing a tab delimited file with sqlite

I thought I’d share my experience with importing the a tab delimited file into an sqlite db as documentation on how to do so is not that easy to find on the web.

In my example I will be importing the US Census ZIP Code Tabulation Area file for 2010. Once you’ve downloaded the file unzip then create the sqlite db and then you’re ready to perform data import. The code block below contains the series of commands which I perform.


unzip Gaz_zcta_national.zip
cat Gaz_zcta_national.txt | tail -n +2 > Gaz_zcta_national.csv
sqlite3 zcta.db
CREATE TABLE IF NOT EXISTS zcta(geoid text primary key, population integer, housingunitcnt integer, land_area_metric real, water_area_metric real, land_area_eng real, water_area_eng real, lat real, lng real);
.mode csv
.separator "\t"
.import Gaz_zcta_national.txt zcta
select * from zcta;
.quit

That modern “green thing”

Got the following in a forwarded email. Usually don’t share but I found this one very interesting. Enjoy…

Worth a few moments of reading…

That modern “green thing”

A somewhat “older” woman was at a checkout stand in a supermarket The helpful, young cashier suggested that the older woman should bring her own grocery bags, because plastic bags weren’t good for the environment.

The older woman apologized and explained, “We didn’t have this “green thing” back in my earlier days.”

The clerk responded, “That’s our problem today. Your generation did not care enough to save our environment for future generations.”
She was right — our generation didn’t have the green thing in its day.

Back then, we returned milk bottles, soda bottles and beer bottles to the store. The store sent them back to the plant to be washed and sterilized and refilled, so the same bottles could be used hundreds of times. So they really were recycled. But we didn’t have the green thing back in our day.

Stores bagged our groceries in brown paper bags, which we reused for numerous things. Most memorable besides household garbage bags, was the use of brown paper bags as covers for our school books. This was to ensure that public property, (the books provided for our use by the school) was not defaced by our graffiti. Then we were able to personalize our books without vandalizing them. Too bad we didn’t do the green thing back then.

We walked up stairs, because we didn’t have an escalator in every store and office building. We walked to the grocery store and didn’t climb into a 300-horsepower machine every time we had to go two blocks. But she was right. We didn’t have the green thing in our day.

Back then, we washed the baby’s diapers because we didn’t have the throw-away kind. We dried clothes on a line, not in an energy-gobbling 240-volt machine. Wind and solar power really did dry our clothes back in our early days. Kids got hand-me-down clothes from their brothers or sisters, not always brand-new clothing. But that young lady is right; we didn’t have the green thing back in our day.

Back then, we had one TV, or radio, in the house — not a TV in every room. And the TV had a small screen the size of a handkerchief (remember them?), not a screen the size of the state of Montana. In the kitchen, we blended and stirred by hand because we didn’t have electric machines to do everything for us.

When we packaged a fragile item to send in the mail, we used wadded up old newspapers to cushion it, not Styrofoam or plastic bubble wrap. Back then, we didn’t fire up an engine and burn gasoline just to cut the lawn. We used a push mower that ran on human power. We exercised by working, so we didn’t need to go to a health club to run on treadmills that operate on electricity. But she’s right – we didn’t have the green thing back then.

We drank from a fountain when we were thirsty instead of using a cup or a plastic bottle every time we had a drink of water. We refilled writing pens with ink instead of buying a new pen, and we replaced the razor blades in a razor instead of throwing away the whole razor just because the blade got dull. But we didn’t have the green thing back then.

Back then, people took the streetcar or a bus, and kids rode their bikes to school or walked, instead of turning their moms into a 24-hour taxi service. We had one electrical outlet in each room, not an entire bank of sockets to power a dozen appliances. And we didn’t need a computerized gadget to receive a signal beamed from satellites in outer space, in order to find the nearest burger joint.

But isn’t it sad that the current generation laments how wasteful we old folks were, just because we didn’t have the green thing back then?

Please forward this on to another selfish old person who needs a lesson in conservation from smartass young people.

We don’t like being old in the first place, so it doesn’t take much to piss us off.

How to create a Hibernate unidirectional many-to-one association using a join table

Hibernate does not recommend doing a one-to-many unidirectional association. But suggest that if you do then you should use a join table.

http://docs.jboss.org/hibernate/stable/annotations/reference/en/html_single/#entity-mapping-association-collections. In the event that you find yourself needing to create a one-to-many hibernate mapping through a join table using configured using an hbm file then below you can see an example of how you may do so.

 


<hibernate-mapping>
<class name="example.Dog" table="dog"
lazy="false">
<id name="id" type="int" column="id">
<generator class="sequence">
<param name="sequence">dogseq</param>
</generator>
</id>
<property name="birthDate" type="java.util.Date" column="dob"
length="8">
<meta attribute="use-in-tostring">true</meta>
</property>
<property name="deceased" type="java.util.Date" column="dod"
length="8">
<meta attribute="use-in-tostring">true</meta>
</property>
<set name="offsprings" table="dog_offspring">
<key column="fkparentid" unique="true"/>
<many-to-many class="Dog" column="fkchildid" unique="true"/>
</set>
</class>
</hibernate-mapping>

Problem Solving FlowChart

A coworker of mine shared this helpful chart with. Thought it might be useful to others trying to solve their software development issues.

Problem Solving Flowchart

Weather men risk it all to save our lives

On CNN’s Piers Morgan Tonight it’s host was put on the spot by his guest Michael Moore to defend the news network’s decision to send it’s news reporters out into the path of Super Storm Sandy to cover the “News”.  Moore an Academy Award Winning Filmmaker, spoke specifically about Ali Velshi who stood in the middle of a New Jersey street as flood water rose and Sandy’s winds blew him around, risking his life for the greater good of telling the news. At the same time that was happening a entire neighborhood was being burnt to the ground. Morgan claimed that Ali’s covering of the storm was necessary to keeping people informed and ensure that lives were saved even if it was just one.

To the defense of CNN there was a lot of chaos during Sandy and covering everything act of destruction  by the storm was certainly not possible. At the same time however I think something has to be said about the trend of weather reporters  – or just reporters as some don’t even know a cumulonimbus from a cirrus cloud – risking life and limb to bring us the news. I would even venture to say that they put more lives at risk than they save. If a guy who gives financial advice as his day job can go out and weather the storm why can’t some other guy. Or if there is news camera just down the street why shouldn’t someone just run down there to get their 15 mins of fame. While Ali was covering the storm several as many as three guys showed up from nowhere dancing in the background. So yeah Piers, one life may be saved bu many more put in danger. How do you rationalize that?

I think you would have those who test the elements. But in this day and ages where we can send a drone half way around the world there is absolute no reason for us to send any out into a storm to cover the news other than ratings.

Say it ain’t so Foxconn!!

It appears the cat is out of the bag. According to China Labor Watch Foxconn the Taiwanese electronics manufacturer famous for producing Apple’s iPhone now admits it used minor at some of its factories in China. The company released and apology and threatened to terminate the employment of anyone involved in violation of China’s labor laws and it’s own company policies. This will probably be seen publicly as an attempt to save face as the company is trying to recover from bad press about labor conditions at it’s factories in China.

In my humble opinion apology or no apology, as long as the company keeps pumping out iPhone, iPad or iWhateva it is very unlikely that their business will be affected.

Add some splash to your Romantic life

Looking to add a big SPLASH to your romantic life. Then you may want to check this link out.

Android powered ASUS PadPhone 2 unveiled

Gizmag writes that ASUS has just unveiled the PadFone2 powered by Google Andriod (Ice Cream Sandwich). In general I have to say I really like the concept of having one primary device and just using an auxiliary device to take advantage of a large screen when the situation calls for it. Such scenarios might include reading a book or watching a video or movie. The problem I have with this device however is that instead of finding a way to utilize two screens at the same time like an extended desktop or something similar they made the device to only work with one screen at a time.

Red Bull gives you Wings!!

Red Bull gives you Wings a parachute!!!

Apple woes continue

As if the IOS 6 maps debacle wasn’t enough embarrassment for the infamous fruit company new reports are surfacing Apple’s customers are experiencing issues with it’s new super phone.