johnk's blog

Django, forcing a specific migration

Migrations are awesome magic, until the magic fails. Then it's an awesomely frightening engine of change that threatens to wipe out your entire database.

So, before doing what I say, backup your database.

I had to enforce a "unique=True" constraint on a model. Migrations are supposed to automatically create a constraint in SQL, as well as its implied index. A quick look at the indexes (SHOW INDEXES FROM Model) didn't show the index.

Battle of the Naming Conventions (how to avoid them in Django REST Framework)

Python and Django like snake_case.

AngularJS feels like Java, and likes camelCase.

HTML likes dashed-words.

MySQL docs like snake_case, but I see more PascalCase used in databases. It's case-sensitive, too.

Parse.com uses PascalCase for tables/classes, and camelCase for columns/properties/fields. That's like Java OOP.

Django likes to append _id to your primary keys.

So... the problems start to happen when one piece of named data is passed from one layer of the system to another. It's just a good policy to use the same names at all layers, if possible.

Fun/Annoying Social Media Buttons

Just something I was working on this weekend. Just a draft. I can't tell if this is playful, or annoying.

<html>
<body>
<style type="text/css">
#socialbuttons {
  font-family: Oswald;
  font-size: 18px;
  color: white;
  box-shadow: 0px 1px 3px #ddd;
}
#socialbuttons td.button {
  height: 27px;
  width: 130px;
  padding: 9px;
  opacity: 0.5;
  cursor: pointer;
}
#socialbuttons td.button:hover {
  opacity: 1.0;
}
#socialbuttons td img {
  height: 18px;
  vertical-align: baseline;
  filter: grayscale(100%);

Buttons vs. Links, and how to make buttons that look like links, and act like links, but aren't links.

This is a common UI element that hovers between "pattern" and "anti-pattern", but it's one I've seen in Drupal, WordPress, and a few other places. It's the button next to a link, where the link acts just like a button:

Technically, it's a violation of UI principles, to have a link that does something to the server's state. Anthony at uxmovement thinks so, but I disagree with him, because the way the link is next to the button, it's obvious that it complements the button.

File Sync and Share and File Server Terminology Clashes

I was thinking about file sync issues, and realized there are some problems discussing or describing problems, because the terms "share" and "open" mean different things in different situations.

Some applications share data by opening a file in a shared folder on the server. They are all working in the same file, and the server's operating system mediates the process.

No Wonder My PulseAudio Stopped Working

The microphone stopped working on my computer. Based on my reading, the problem, I think, is that I'm using an older motherboard from around 2010s, an add-on card that does TV, and Ubuntu with PulseAudio. The mic input on the sound card just stopped appearing in PulseAudio.

It's still visible in ALSA.

A Django REST Framework Technique for more Detailed Related Records

This is a nice way to deal with building lists of objects to display in tables. It's kind of hidden in there, but in your serializer, you can specify that a field is represented by another serializer.

The result is a list of objects instead of a list of URLs or PKs.

Now, going with that, you can save on data transfer by serializing only a few fields.

Free Political Ad Template

Simple and short. No graphics. Banner ad for websites.

The AngularJS File Upload Blues

I've got the angular file upload blues. It's hard to upload files in Angular JS. Who was to know?

One solution.

A nice module called angular-file-upload.

Quadrennial Linux Install (and what I installed)

Once upon a time, it was Windows that required a biennial install. Today, Windows seems to run for five years or more without a reinstall.

Linux, on the other hand, which used to go for years with only package updates, now requires reinstalls. I'm doing one after nearly five years without a clean install. That's a pretty long time.

Intermittent Django REST Framework glitch examined with Apache Benchmark

While programming in the rest framework, I hit this error, intermittently, but over and over, along with others:

Could not resolve URL for hyperlinked relationship using view name "parseuser-detail". You may have failed to include the related model in your API, or incorrectly configured the `lookup_field` attribute on this field.

Being a noob, I hit the books (documentation) again, and again, and thought I had it right, or close. (Don't start out creating Django models for non-Django-managed tables. It's pretty hard. It's better to learn the vanilla Django way first, if possible.)

Instant CORS in PHP

Here's a snippet of code that will make your PHP REST API work cross-domain, through the magic of CORS:

/**
 * CORS is a way to allow scripts from other domains to post to this URL.
 */
if ($_SERVER['REQUEST_METHOD']=='OPTIONS') {
    header('Access-Control-Allow-Origin: *');
    header('Access-Control-Allow-Methods: POST, OPTIONS');
    header('Access-Control-Allow-Headers: Content-Type');
    exit();
}
header('Access-Control-Allow-Origin: *');

Django Rest Tutorial, Inverted

[I hesitate to post this, because it makes me look like I'm a slow learner... but, oh well. I hope someone finds this interesting.]

Studying Docker.io is a little easier with this Linux Containers Tutorial

I was getting through the docker.io docs, and not quite getting it, and learned it was based on Linux Containers. Followed a link to a series of tutorials by one of the committers, and it's really good so far.

LXC is basically "chroot[1] on steroids" with a isolated networking and processes in addition to isolated files. It allows you to create software within what looks like a lean Linux environment.

North Carolina Judge Expands definition of "Computer Professional" to Include Admins

North Carolina Judge Upholds Employer Classification of Employee as Exempt Computer Professional

This is a big loss for net admins. The exemption was intended for programmers (and even that might be considered a loss).

Syndicate content