Posts

Date Dimension Table Definition

A few weeks ago I found this definition of a date dimension table, created by a smart person named  Nicholas Duffy . I'm placing it here so I can find it easily. DROP TABLE IF EXISTS dim_date; CREATE TABLE dim_date ( date_dim_id INT NOT NULL, date_actual DATE NOT NULL, epoch BIGINT NOT NULL, day_suffix VARCHAR(4) NOT NULL, day_name VARCHAR(9) NOT NULL, day_of_week INT NOT NULL, day_of_month INT NOT NULL, day_of_quarter INT NOT NULL, day_of_year INT NOT NULL, week_of_month INT NOT NULL, week_of_year INT NOT NULL, week_of_year_iso CHAR(10) NOT NULL, month_actual INT NOT NULL, month_name VARCHAR(9) NOT NULL, month_name_abbreviated CHAR(3) NOT NULL, quarter_actual INT NOT NULL, quarter_name VARCHAR(9) NOT NULL, year_actual INT NOT ...

Kingsville, Ontario Lies to the South of Uxbridge, Massachusetts, and West

While looking at Google Maps for the umpteenth time, I finally noticed that Canada comes very far south near Detroit. It appeared to lie further south than my town, Uxbridge, Massachusetts, which is on the border between Massachusetts and Rhode Island, which is not an island. I looked it up. Sure enough, it's true. The uninhabited Pelee Island in Lake Erie, not far north of Sandusky, Ohio is, as I learned, the southernmost point in Canada. Leaving that aside, though,  one can see on a map that Kingsville, Ontario is the southernmost town in Canada, at 42° 2' 10.68" N 82° 44' 20.4" W. The location of Uxbridge is 42° 4' 37.92" N 71° 37' 49.08" W. That puts Uxbridge 2 minutes, 27 seconds north of the southernmost town in Canada. That means I can get in my car and head southwest to Canada. And I might.

tomoptamist

to-mop-ta-mist  \ tǝ-'mäp-tǝ-mǝst \ n  [fr. tomato + optimist] : one who is optimistic about tomatoes -  to-mop-ta-mis-tic  adj  - to-mop-ta-mis-ti-cal adj - to-mop-ta-mis-ti-cal-ly adv Sample usage: 1. Of some leftover tomato : "I'll leave it on the counter for now. Someone might want it. I'm a tomoptamist.' 2. Of a tomato of unknown quality : I'll just try it. I like to think tomoptamistically.' Origin: I just made it up.

Creating a PostgreSQL Database, the Use of Database Templates, and Simple Command Line Tool Commands

A PostgreSQL server installation includes database templates. These are used when creating new databases. By default, template1 is copied when you create a new database. This makes it easy to create copies of a customized database design. You can customize template1, and then easily make as many copies as you like, and they will all start out with the same objects, such as tables, languages, etc. Specify template0 to create a standard, out-of-the-box database with no custom additions that may have been added to your server installation. Make sure that you do not make any changes to template0. Create a database using template0, from a command line A database can be created in various ways. Here we will create one from the command line, using the tool PostgreSQL createdb. By default, the logged in user will be the owner of a newly created database. While logged in as user postgres, from a command line, create a database named exampledb, using template0: bash-4.2$ createdb...

Python and PostgreSQL: Create a PostgreSQL Database Connection Using a Config File

This technique can easily be applied to other databases. 1. pip install two packages if you do not already have them in your Python environment. (Search the internet for ‘python pip install’ if you need help.) A. psycopg2: To interact with PostgreSQL databases B. configparser: To interact with config files 2. Create a config file named config.ini. Paste in the text below: [ default] host = localhost db_name = your_database_name postgres_user = postgres_username postgres_password = your_password Edit the details to match your environment. 3. Create a Python file named main.py. Paste in the text below: from configparser import SafeConfigParser import psycopg2 parser = SafeConfigParser() parser.read('config.ini') host = parser.get('default', 'host') db_name = parser.get('default', 'db_name') postgres_user = parser.get('default', 'postgres_user') postgres_password = parser.get('default', 'po...

Convert a wav file to mp3 with FFmpeg, pydub, and three lines of Python

Ten minutes ago I played a song I had not heard before and said, that was a good song! I should send it to Sam. But it's in WAV format so it's really big. Wouldn't it be nice if Python could convert it to mp3 to make it smaller? Ten minutes later it was done. Amazing. Here are the easy steps to follow if you would like to try it. 1. Search the internet for 'python convert wav mp3'. 2. Download FFmpeg and add it to your system path: http://adaptivesamples.com/how-to-install-ffmpeg-on-windows/ 3. 'pip install pydub', then copy some sample code from here and make slight adjustments to match your file paths and song file name: https://github.com/jiaaro/pydub 4. Run the script: from pydub import AudioSegment song = AudioSegment.from_wav("G:/Music/Rock/The I Don't Cares/Wild Stab/Sorry for Tomorrow Night.wav") song.export("Sorry for Tomorrow Night.mp3", format="mp3") 5. Email the mp3 file to Sam. And do...

The Use of Views Has No Impact on Query Performance in PostgreSQL

More evidence that PostgreSQL is the best database. The documentation supports one of my strongest beliefs about database design: Making liberal use of views is a key aspect of good SQL database design. Views allow you to encapsulate the details of the structure of your tables, which might change as your application evolves, behind consistent interfaces. Views can be used in almost any place a real table can be used. Building views upon other views is not uncommon. Source: https://www.postgresql.org/docs/10/static/tutorial-views.html In answer to a question about the impact of views on query performance, veteran PostgreSQL core developer Bruce Momjian gave the following answer: They have no impact whatsoever. The parser thinks the view is a real table. The query structure gets passed to the re-writer and the re-writer wipes out the view and substitutes the underlying tables. And that re-write is what gets passed to the query optimizer. The optimizer doesn't see the v...

The Internet Can Be Useful If Used Properly

This post is here because I had not added one for two-and-a-half years. In the interim, the world has not suffered from the lack of my posting. (It has suffered for other reasons, but let's not get into that. The idea here is not to be depressing, no, far from it.) Nonetheless, I feel compelled to put something here, if only to be able to say to myself, "Good job, Pete. You have done it. Let this be a start, and soon you will add many fabulous things to your blog. It will be part of a personal Renaissance. Let many flowers bloom." Or something along those lines. Something very positive and good. Anyway, music continues to be really good. You only need to look for it. One of the best ways is via YouTube. Being a reasonably intelligent person, I find a visit to the front page of YouTube demoralizing. I really don't want to even know what is popular. Knowing about popular things is a great way for me to get really discouraged. However, if you search for so...

The Three Acts of the Mind

The acts of the mind, wherein it exerts its power over simple ideas, are chiefly these three: 1. Combining several simple ideas into one compound one, and thus all complex ideas are made. 2. The second is bringing two ideas, whether simple or complex, together, and setting them by one another so as to take a view of them at once, without uniting them into one, by which it gets all its ideas of relations. 3. The third is separating them from all other ideas that accompany them in their real existence: this is called abstraction, and thus all its general ideas are made. -- John Locke, An Essay Concerning Human Understanding (1690)

97 Things Every Programmer Should Know

This collection of short articles about programming best practices is well worth perusing. Courtesy of O'Reilly Media.

In Appreciation of Procedural Programming

I think the lack of reusability comes in object-oriented languages.... [T]he problem with object-oriented languages is they've got all this implicit environment that they carry around with them. You wanted a banana but what you got was a gorilla holding the banana and the entire jungle. -- Joe Armstrong

Beatiful Day, Sox @ Yankees Tonight

Beautiful day today, and the Sox play their first game of the 2014 season against the Yankees tonight in the Bronx. Birds are chirping outside, and I can hear the last touches being put on a new bridge over the creek down the hill. An excellent day indeed.

Your Opinion May Not Be Helping Things

Science is not designed to support your opinion. Instead, it is designed to reveal facts derived from empirical evidence. It is not the responsibility of facts to agree with what you might think. If you have placed yourself in a position to be bereft of them, facts do not care. They have no ability to care. They are only facts. If facts make you uncomfortable, try to figure out why this is so. This may not be your fault. Indeed, it is most likely that you have been misled about the illuminating qualities of facts. Perhaps your father did not embrace reason. That would be discouraging. Perhaps your mother didn't know how to show that she loved you. She did. It's okay. You can do better. You can start to learn about the way things work in the actual universe. There is much data available. And if you can read, you need only start reading. I wish you the best of luck.

Install the JDK Development Version on CentOS

If you want access to Java tools like jar and javac, install the development version of the JDK. # yum install java-1.7.0-openjdk-devel Add the bin directory to your PATH so you can run the Java programs from anywhere. # PATH=$PATH:/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.25.x86_64/bin View the classes in a jar file. # jar tvf dt.jar      0 Mon Jul 01 09:51:04 EDT 2013 META-INF/     71 Mon Jul 01 09:51:04 EDT 2013 META-INF/MANIFEST.MF      0 Mon Jul 01 09:51:00 EDT 2013 javax/      0 Mon Jul 01 09:51:04 EDT 2013 javax/swing/   4486 Mon Jul 01 09:51:04 EDT 2013 javax/swing/JSliderBeanInfo.class   3342 Mon Jul 01 09:51:04 EDT 2013 javax/swing/JFormattedTextFieldBeanInfo.class   3025 Mon Jul 01 09:51:04 EDT 2013 javax/swing/JMenuBarBeanInfo.class

Climate-Gate Scientist Cleared Over and Over Again

James Fallows, who is an excellent veteran writer for The Atlantic , published a post today about "climate-gate" scientist Michael Mann being cleared of all wrongdoing yet again, this time by the National Science Foundation. As is often the case, Mr. Fallows raises a lot of good points using a small number of words, and provides some nice links. One of the points is the amazing and disturbing rejection of well-established science by nearly the entire Republican party. As I once heard Chris Matthews say to Pat Buchanan, these guys "would have been great in the Dark Ages." What would Abe Lincoln be thinking right now if he could see this?

Tripoli Falls to Rebels, Earthquake in Virgina

After months of fighting to end Qaddafi's forty years of lunatic despotic rule in Libya, rebel fighters now control most of Tripoli, the capitol city, and today breached the walls of the presidential compound, where thousands celebrated and carried off booty and weapons. And on the same day, I felt my tenth floor cubicle in South Boston begin to sway at around two this afternoon, the result of a 5.8 earthquake all the way down in Virginia.

Economic Stimulus and the English Language

I just heard Orioles Hall of Famer Cal Ripken mispronounce the word "peripheral" as "periphial" on the MLB Network. This is one of the most commonly bungled English words, in my experience. A small way to stimulate the economy while improving English usage would be to create signs that teach proper spelling, pronunciation and usage of commonly botched words, and place them in public spaces.

Grizzly Bear's "While You Wait For The Others" on KCRW

This 2008 performance of "While You Wait For The Others," by the band Grizzly Bear, is mellow and trippy, with a muddy, popping guitar sound, a pleasing melody, sweet harmonies, and a rhythm section featuring nice snare work, quiet organ, interesting bass fills, and I say that this is a doggone pretty song. Recorded live for the show Morning Becomes Eclectic in the studios of KCRW, my old beloved Santa Monica Community College radio station. I drove many a mile around Southern California soaking up the musical and spoken sounds of this fine outlet. Long live KCRW.

How Algorithms Shape Our World

Check out this video by Kevin Slavin at a recent TED talk.

What Ails the Field of Economics, by Mark_BC

I'm mighty impressed by this explanation of what ails the field of economics. It's not what you expect, whatever it is that you expect. This is very good: http://www.amazon.com/review/R1FRA5LD2PG6HT/ So now I'm going to read this at his blog: http://markbc.wordpress.com/thermodynamics-for-economists/ Do what I did and read the first thing first, though. It's well worth it.