Blog

Sometimes I write, sometimes it's worth reading. Check it out below.

Migrating a Django Project from SQLite to MySQL

I have several Django apps which are hosted on a Digital Ocean droplet, with development being done on my local Mac. For the most part, the initial SQLite setup works well, but for one of my larger projects I wanted to incorporate the use of MySQL. Here's how I went about the migration process:

Pre-Requisites

Recommended

  • A thorough unit-testing framework for validating data integrity post-migration.

Setup the MySQL Database

The Digital Ocean tutorial How to Create a Django App and Connect it to a Database was very helpful helpful here. In a nutshell:

Open the my.cnf file for editing: vim ~/.my.cnf and add the following:

[client]
user = USERNAME
password = PASSWORD
detault-character-set = utf8

A couple of notes here:

First of all, the possible locations of the my.cnf file can be found via the following comand: mysql --help | grep "Default options" -A 1. Since this is for development purposes only, and to avoid any permission issues, I've chosen the simplest location within the user home directory.

Second, the setting default-character-set value in the tutorial was actually utf-8, not utf8. For whatever reason that tutorial value was causing "invalid character set" exceptions to be thrown when attempting to connect (though the alias in the Index.xml file should have sufficed). Regardless, the workaround was to use the exact name, utf8

Third, the tutorial indicates to set the database within the my.cnf file. This caused issues with running mysqldump later, so I found it better to remove it from the my.cnf file, and add it within the name property of the DATABASES setting with Django.

Install mysqlclient Package

Next we'll need to install the mysqlclient package. You can do this via pip individually, or via requirements file:

# requirements.txt
...
mysqlclient==2.1.0

Then install via pip:

(venv) $ pip install --upgrade pip
(venv) $ pip install -r requirements.txt

When doing this initially however, I ran into what seemed to be an egg issue which resulted in a "No matching distribution found for mysqlclient" exception. What ended up being the issue was a lack of Python 3 headers for the install mysql version, and this was resolved by following the "Install" instructions within the PyPi mysqlclient page. After that, the pip install worked fine.

Update Django DATABASES Settings within settings.py

Next we'll take the existing default database Django settings and re-define them as legacy so we can continue to reference them, while defining MySQL as our new default database. Note that we add the 'NAME' attribute for the database, since we didn't define it within my.cnf. Also note that the username segment of the read_default_file value needs to be changed to reflect the actual user directory on your computer.

DATABASES = {
    'legacy': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': BASE_DIR / 'db.sqlite3',
    },
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'DATABASE',
        'OPTIONS': {
            'read_default_file': '/Users/username/my.cnf',
        },
    },
}

Run Database Migrations Against MySQL Database

Run the following to build out the database tables within the newly created "default" MySQL database: (venv) $ python manage.py migrate --settings path.to.settings --database default

Dump Existing Data

To transfer the from one datbase to the other, I used the dumpdata and loaddata commands from Django fixtures.

To dump the existing SQLite data:

(venv) $ python manage.py dumpdata --settings path.to.settings --database legacy -o data.json --exclude contenttypes

Note that I excluded contenttypes here, as including that data was causing integrity errors later with loaddata.

Then, load the data into the "default" MySQL database:

(venv) $ python manage.py loaddata data.json --settings path.to.settings --database default

If all went well, you should be able to startup a development server and browse around your site. Be sure to run tests to ensure everything migrated properly. When all looks good, it's probably also a good idea to remove the legacy database settings and file.

Links:

Streaming Synology Diskstation Video Through Apple TV With Plex

My wife's been shaking her head at me the past few months as I was slowly but surely converting our DVD collection to our home Synology Diskstation NAS. This was particularly because we had a super old Apple TV, and could only stream them via Airplay. The quality and interface was.. not so great.

However, for our anniversary I bought the latest generation Apple TV, installed Plex (on both the Apple TV and NAS), and via the below tutorial, was able to setup a streaming interface of our DVD collection better than I could have imagined:

https://www.youtube.com/watch?v=Z7LfXVVfYhI

There was only one wrinkle in my setup however: I wanted to keep our videos under /Volume1/video/* as opposed to /Volume1/Plex/Library/*, especially because keeping them in the former location allowed us to continue to stream videos on our phones and iPad via DS File, while Plex allows only free streaming to Apple TV.

So the obvious solution was to create symlinks from video/* to Library/*. However when doing so, Plex could see the directory but not access it. Searching Google showed various hacks to enable Plex access, but the actual solution was quite simple: the plex user on the Synology Diskstation simply needed read access to the video/* directory.

Super simple, and worked like a charm. Happy streaming!

Installing and Configuring MySQL

This article is more of a cheat-sheet for myself, and less of a public facing post, but hopefully it can help someone else out.

Install and Start MySQL

Install MySQL using Homebrew: brew install mysql

If MySQL has not been added to the system path, run the following: export PATH=$PATH:/usr/local/mysql/bin

Create a User, Privileges and Password

Login to mysql as root: mysql -u root

Create user: mysql> CREATE USER 'username'@'localhost';

Grant all privileges: mysql> GRANT ALL PRIVILEGES ON *.* TO 'username'@'localhost';

Run the following:

mysql> USE mysql; 
mysql> UPDATE user SET authentication_string='password' WHERE User='username'; 
mysql> FLUSH PRIVILEGES; 
mysql> quit; 

Alternatively (as of version 8.0.15), the password can be updated:

mysql> USE mysql; 
mysql> ALTER USER 'username'@'localhost' IDENTIFIED BY 'password'; 
mysql> FLUSH PRIVILEGES; 
mysql> quit;

You now should be good to create a local database connection for the newly created username.

Create Database

mysql> CREATE DATABASE databasename;

Delete Database

mysql> DROP DATABASE databasename;

Why Django, Why?

One year ago, I was riding pretty high. Well, at least website wise. I'd successfully migrated my old Wordpress site from Bluehost to my Synology Diskstation. It was a little painful at first, but eventually I was able to successfully serve my own website from my own home.

There were some initial tradeoffs during that initial process of course. I wasn't able to peform a total rebuild in Django as I'd intended, due to the NAS being more configured for Wordpress hosting and any alterations to the serving configs could be wiped out by an update. So I settled for Wordpress for my own site, and was still able to install and use Python/Django for some side projects. Things were pretty great.

Then one morning, I was greeted in my office with the dreaded "System Crash" beeps. My volume had crashed, and I'd lost all my site data on the NAS. And I thought, "Aha, lesson learned: always backup your ish." Thankfully I had my Bluehost Wordpress backup, as well as some project stuff in git and was able to rebuild with minimal data loss. And I conigured a pretty thorough redundant backup system to prevent another such loss.

I did say *pretty* thorough, because of course it happened again. And I found I hadn't redundantly back-ed up everything. So my next lesson was, "Just because you can serve things on from a home NAS doesn't mean you should." It's simply not optimized for web hosting, installing packages was a pain, and I suppose there's no telling whether the crashes were just fate, or malicious. In any event, I swam for the open waters of Digital Ocean.

And it's been pretty good so far. Setting up a Django site was a breeze, and it sure feels nice to be free from the structures of Synology and bloat of Wordpress. Obviously it's a work in progress: the design so far is bare HTML and restoring and re-routing my old posts will be a bit of an adventure. But I'm looking forward to it!

 

Santa Claus According to George Hinke

George Hinke - Baking Cookies

Every December for as long as I can remember, we’d eagerly retrieve our Christmas decorations from their long-boxed-up slumber. Probably the most prized of which were our Santa Claus dinner placemats, which depicted various scenes of St. Nick, Mrs. Claus, elves and reindeer all prepping for their Yuletide escapades. A little internet sleuthing revealed that these scenes were actually illustrations commissioned for a children’s book by the name of “Jolly Old Santa Claus,” painted by German/American artist George Hinke.

George Hinke - Confectionery

From the Museum of Wisconsin Art Website:

George Hinke was born in Berlin, Germany, in 1883 and schooled in a classic style of painting. Mr. Hinke came to Milwaukee, Wisconsin, in 1923, where he worked at a printing shop until he opened his own studio. From 1944 until Mr. Hinke’s death in 1953, Ideals commissioned him to create many works of art. In addition to Santa Claus, Mr. Hinke’s subjects included American small-town life, American flags, and religious scenes – all in his classic, nostalgic style. The paintings in the 1961 Ideals Magazine Collector’s Edition of Jolly Old Santa Claus are rendered in oil on stretched canvas. The influence of Mr. Hinke’s German background is evident in the Santa Claus series: from Santa’s castle, which resembles the castles of Bavarian King Ludwig, to the Black Forest clock on the wall of Santa’s workshop to the elves themselves, who are reminiscent of those characters in stone that decorate many German gardens.

George Hinke - Christmas Tree

For me, these placemats provided the archetypal representation of what Santa Claus looked like — er, I mean — looks like, and all the little details were so fun and interesting to us as children. We still use them at mom and dad’s every year, and though the book can still be found easily enough through retailers like Amazon and Thriftbooks, actual full prints of the scenes are difficult to find. Thus I wanted to share them here for everyone to enjoy.

George Hinke - Reindeer and Sleigh

I’ve uploaded them here as HD photos taken with my iPhone 6 and cropped in GIMP. At some point perhaps I will use my limited photo-editing skills to restore some of the color and hide some of the placemat defects. But for now: Merry Christmas to all, and to all a good night!

UPDATE: Just a quick note that I had these photos (without any further editing) made into place mats via Snapfish. The process was super simple and the results were fantastic. I highly recommend it! Just be sure to use the Honey app or some other promo code provider to avoid paying the steep full price. I had 8 made for $65.

Georgetown

US News' D.C. office is located on Thomas Jefferson Street NW in what is known as the Georgetown historical district. Georgetown predates the rest of the capital by about 50 years, and while its mostly known for embassy's, retail, and films such as The Exorcist and Wedding Crashers, it's also a really really cool place to work. The office is right next to the C&O Canal trail: Washington Harbor waterfront to the left, M street to the right. I gotta tell ya it's pretty awesome grabbing a sandwich and just strolling down to the waterfront for lunch. So if you work in DC, or are just passing through sometime - give me a call, e-mail or text, and let's grab some lunch or a beer!

star dot ico

It's a tiny, seemingly insignificant, sixteen by sixteen pixel image. But let's be honest: it's the first thing site visitors will notice when your site loads, and the only thing that will differentiate you from pretty much every other Bluehost Wordpress site out there. And with how so very simple it is to change, let's get a new favicon up there, shall we? For those of you who don't know what I'm talking about, a "favicon" is that square image thingy you notice in the left-hand corner of your browser tab when you visit a site. Standards provide you with the ability to define an individual one for your own site - but if you don't, a default one will be used. The following steps are for this site (which is Wordpress), but it should be easy enough to replicate for all. It's a simple as:
  1. Using an image editor (cheap, Windows junkie I am, I use GIMP), create an image 64px x 64px.
  2. Design your image, but remember it's going to have to look great as 16px x 16px. Less it more. Mine is the letter "b". I am also not a designer.
  3. Scale the image to 16px by 16px.
  4. Save or export your image as a "favicon.ico". If that extension is not possible with your image editor, you can either (a) get a plugin, or (b) save it as a GIF, JPG or PNG and Google any number of favicon generators out there... those can be hit or miss though.
  5. Upload the "favicon.ico" image to your site. Often, this will be the root directory. But in my case, Wordpress was looking for the image elsewhere based on a link tag with the attribute of "shortcut icon". In that case, I'd rename the existing image to archive it, and upload your new image there.
  6. Ensure the aforementioned link tag is in fact pointing to your new image. If the tag does not exist, it's not a terrible idea to add it to the <head> block: <link rel="shortcut icon" href="favicon.ico" />
  7. You may need to flush your browser's cache in order to get it to show up properly.
And you're done! Now was worth sixty seconds of your time, wasn't it?

Back From Bristol

March 11 was my last day working at ESPN. After nearly three and a half years working for "The Worldwide Leader," I've accepted a very exciting Senior Web Developer position at "US News and World Report" for their Travel and Auto vertical, located in the Georgetown sector of Washington D.C. There have been so many memories from ESPN through those few years: From Magical Unicorns to Deadspin announcing layoffs during the summer of 2013. From crazy "Reply-All" e-mail threads to the annual NCAA tournament pot-luck. From the Ooyala Video Migration to Jim Abbot pitching batting practice. Trying to "steal" Rita LeBlanc's Super Bowl Ring... [caption id="attachment_244" align="aligncenter" width="300"] Rita LeBlanc's Super Bowl Ring.[/caption] Conquering the Mt. Snow with the Tough Mudder Crew... [caption id="attachment_243" align="aligncenter" width="300"] ESPN's EXT Team: Tough Mudder, 2011.[/caption] Shark attacks... [caption id="attachment_248" align="aligncenter" width="300"] We're gonna need a bigger boat.[/caption] The Stanley Cup... [caption id="attachment_250" align="aligncenter" width="224"] The Stanley Cup comes to visit ESPN.[/caption] Imperial entanglements... [caption id="attachment_249" align="aligncenter" width="300"] You do not know the power of the Dark Side... we have cookies.[/caption] [caption id="attachment_247" align="alignright" width="300"] Blizzard of February, 2013.[/caption] Through hard times like numerous blizzards, two earthquakes, two hurricanes, the "Franken-Storm", Newtown and the Boston Marathon Bombing... Through three reorganizations... Through working with all the various groups at ESPN: Sports Production, API group, X-Games, International, Editorial and WatchESPN... It was a blast working with such talented and fun people. [caption id="attachment_246" align="alignleft" width="300"] My brother Matty and I on the ESPN News set.[/caption] My only regret is that I never got into a "This is Sportsceneter" spot like Lucas and Wong. Though is that really Wong in the green shirt? Now I'm not so sure... Oh well, there are days when this might as well be me. So as honestly as I can, to all those that I had the pleasure of working with or knowing, I'd like to say: thanks. Please keep in touch!

Quieres construir un muñeco de nieve?

[caption id="attachment_187" align="alignleft" width="300"] The Marian statue atop the "Panecillo" in the background.[/caption] Last week, my brother Matthew, my sister Lisa, her husband (Tim), their two daughters (Evangeline and Audrey) and I were fortunate enough to visit my sister Michelle and her family in Quito, Ecuador. Quito is the world's highest capital city, and you notice the altitude right off the bat - with an elevation of 9,350, it's almost twice as high as Denver, CO. Simply walking up the stairs becomes no easy task, much less chasing the nieces and nephews up and down. [caption id="attachment_189" align="alignright" width="300"] Flowers along "Seven Crosses Road".[/caption] Though it's on the equator, Quito's temperature rarely ranges outside of a 70-50 degree zone, and its only seasons are "Dry" and "Rainy" (it rained nearly every day). That fact that they use a similar enough electrical voltage as the US was handy for charging mobile devices, as well as the fact they are also on the US dollar - though be aware that because of a "change shortage," bills as large as a twenty were all but useless because many vendors would not accept them. [caption id="attachment_182" align="alignright" width="300"] Evangeline's all set for the tour of Quito.[/caption] [caption id="attachment_184" align="alignleft" width="300"] Basílica del Voto Nacional, Quito[/caption] At any rate, the first day out and about was spent on a bus tour that took us through the city, it's historical sector, and "el Panecillo", a central hill at about the center of the city that sports a statue of the Blessed Mother and a 360° degree view of the city, its surrounding hills and dormant volcano. [caption id="attachment_177" align="alignleft" width="225"] Malia getting one of the butterflies to land on her finger.[/caption] Next stop was the remote town of Mindo, about 2 hours northeast of Quito - easily the most remote place I've ever been. While rumbling along the road of mud, you half expect a pack of Velociraptors to rush from the bush. Our destination was the Mariposas Butterfly Garden, where they raise over 40 species of butterfly within a netted, walking environment. After a long St. Patrick's day lunch at El Quetzal De Mindo (where they make their own chocolate and beer amongst other things), we made our way back to casa Hilleary for dinner and a traditional viewing of "Darby O'Gill" via the projector. There are two equator museums in proximity to Quito: one on the equator itself, and one - more picturesque - that sits about about 250 yards from 0'0". Not exactly sure how they screwed that one up, but regardless we visited the former - and I'm glad we did. One of the features of the real museum is that there's all sorts of cool experiments you can do such as balance eggs and drain water straight down (even six feet to the right or left causes the water to spiral). Also cool were the native american exhibits, specimen of the local fauna such as the "Goliath birdeater" tarantula, and even the ancient shrunken head of a 12 year old boy... hmm. In between all the action out and about, hanging out with the fam at "Casa Hilleary" was a blast. The movie "Frozen" was definitely the feature of the week with two showings and daily soundtrack plays - I especially enjoyed screwing up the lyrics to annoy the kids. Shay was able to construct a Duplo tower to the ceiling of the play room, and the compound's trampoline was a big hit for all, especially Evangeline. All in all, just a great country to visit, with such gracious and generous hosts. [caption id="attachment_181" align="alignleft" width="225"] That's a load-bearing pillar now, Shay.[/caption] [caption id="attachment_196" align="alignright" width="225"] Evangeline "fishing" for Koi.[/caption]

RE: Reply All

Since it's Friday, figured I'd repost an oldie but goodie: This past Friday some unfortunate employee accidentally sent an e-mail to the wrong distribution list. Not all that uncommon really, except that this particular list was comprised of 800 employees, including the television talent. Even then the damage should have been minimal. Until the reply-all’s began. “Why am I on this list?”, “Please remove me from this thread” the wildfire began, the senders either too hasty or ignorant to realize that every response would only exacerbate the situation and be forwarded to hundreds of other employees. How they didn't realize this is beyond me, but it was totally awesome. We spent the next half-hour watching the responses roll in. Some ballsy employees even began to chime in: “GO BILLS!”, “So who does everybody like in Rays-Rangers tonight?”. I can now honestly say in one day I received e-mails from Jay Harris, Scott Van Pelt and Michelle Beadle. But how was your Friday? Alas, all good things must end. John Skipper laid the hammer down with a thunderous cease and desist e-mail. Six replies later, that was that. My favorite of the afternoon? ‘What a great way to close out the week! I love EMAIL.’

Let the Madness Begin

Well it's March again, and for the VOD and WatchESPN teams at the four letter, it only means one thing: Basketball (insert obligatory 4 game shot of screens). In all fairness, it's a well deserved reward for all of the hard work the teams put into their NCAA Basketball products before the mandatory tournament "code freeze" goes into effect. As well, this year we had quite pot-luck spread: wings, dips, meatballs, chips, cookies, veggies, fruit... and best of all, pizza. Almost takes the sting from my busted bracket. But I'm having a conundrum: with VCU and Georgetown now out of the mix, I really don't have a horse in this race. So who to root for... Coach Larranaga and Miami (gasp)? Gonzaga?? Michigan??? Or maybe it's just time to throw my attention towards Baseball and  warm thoughts of Spring and Summer to come. Hmm... Let's go O's!

September 8th, 2008

Figured I would re-post my entry from backtobristol.blogspot.com on a very good, humble and wise man that I had the honor of knowing: "In my scant 29 years, I’ve found that there are really only a handful of days that stick with you for the rest of your life. On as similar a Monday as 9/11, September 8th 2008 began ordinarily enough: I made my morning commute from Annandale to Nokesville, grabbed some coffee and retired to my desk. Aaron Rodgers was making his pro-football debut that night, and all I wanted in the world was to get home and watch the Packers clobber the Vikings. The only indication that today might be memorable was when my boss and coworker, Peter and Pablo, took me outside to commemorate the Blessed Mother's birthday. They left flowers in front of her statue, while I (maybe slightly embarrassedly) sang along to "Happy Birthday," then turned back inside to work. A couple hours later, Peter came through the door again, but this time with a more grave countenance: Tom and his son Joseph "Josie" Vander Woude had fallen into a sewer, and Tom had died. Details were sketchy but he thought I should know, since my sister Katy is married to Chris, another of Tom's sons. Deciding that Katy should hear from the family first and since I did not know all the details, I sat back down and just waited. I had known the Vander Woude’s since attending World Youth Day in Denver with them in 1993. In addition to being a family friend, Tom had been my high school basketball coach, my college athletic director and the head of the career development office when I graduated. He had been present throughout my young adult life, quietly strong, positive and supportive to everyone he worked with and influential in more ways than I could hope to write down here. Not long after I'd heard the news, Facebook began to explode with status updates and instant messages. People were looking for news, details - anything. In particular I remember relaying what I had finally pieced together to my friend, Ben: Josie (who has down-syndrome) had been standing on an old septic tank lid when it gave way. Unable to pull him out, Tom had pushed himself into the muck underneath and held Josie up for air until help could arrive. Josie survived. Tom drowned. Ben replied: "That's the most heroic thing I've ever heard." And so it is. There are infinitely more details regarding that day and those that followed than I could hope to relate here. More tributes than I could hope to chronicle about the influence that Tom had on my life or the thousands that packed Holy Trinity for his funeral. But a few days later I pulled into my driveway to the voice of Mark Levin reading the Washington Post over AM radio: "'Tom had been a pilot in Vietnam... he worked as a commercial airline pilot... Farmer, athletic director, volunteer coach, parishioner, handy neighbor, grandfather of 24, husband of 43 years... his eldest son became a priest. Five others all married.' No one told me to read you this story. But I saw it and could not let it pass by. Because every American man needs to know this story. Because this is a man that every man should try to be." And so they should. Rest in peace, Mr. Vander Woude." UPDATE: Focus on the Family also released a short interview-style video about Tom's sacrifice back in 2014. Well worth a watch.