johnk's blog

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).

Semantics

So I'm reading this computer stuff, and come across:

"What separates a mixin from multiple inheritance? Is it just a matter of semantics?"

"Yes. The difference between a mixin and standard multiple inheritance is just a matter of semantics;"

What the heck did that mean? Different words, same meaning... or different words, different meaning? I am pretty sure they meant the former, but I had to double check, because "semantic" means "meaning", and in technical reading, I tend toward the literal interpretation over traditional or colloquial one.

Craiglist Free Stuff

materials/minerals
	dirt
	rocks
	manure/fertilizer
	metal
	bricks
	broken concrete	
wood
	firewood
	hardwoods
	living trees
furniture
	sofa
	computer desk
	entertainment center
	chairs
	table
	bookshelves
boxes
toys
food
clothes
books/magazines/video
electronics
	television
	computer stuff
	phone
	ewaste
big batches
	curb alerts
	all the stuff in my storage

Operations on a Remote MySQL Server

A demo of how to incorporate SSH tunnels into a Python system administration script.

Like all sysadmins, I write scripts to automate routine operations. Lately, though, I have needed to write scripts that automate routine operations on a remote system, and we need the security barriers to be a little higher than in the "old days".

We're accessing our database through an SSH tunnel, rather than via a regular encrypted socket. (The SSH connection will eventually require key pairs, and disallow regular passwords.)

WSGI, PSGI, Rack - learning some new backend stuff

(This is one of those articles I sometimes fear writing, because it reveals a vast gap in my knowledge. I've spend most of the past decade in PHP programming, with numerous forays into other langauges and frameworks, but mostly in the app dev end. I have to deploy my code and that's made me take forays lower into the stack.)

Two Big Monitors, Justified

I was never one to think I *needed* two monitors after the HD monitors came out, but having used two for a couple months, I think it's totally worth it. I don't even have the second monitor on all the time, but when you're coding and testing interactively, it helps a lot.

I set it up to show four regions: editing, reference, interaction, and debugging. I keep a terminal underneath the editing window, too. Click the image to enlarge.

Python str.split, annoying design.

Even after a year of diddling, I'm still a python newb, and things like str.split(None) are why.

Everyone knows split splits strings on a character (or in the civilized world, a regex). str.split(None) splits on whitespace and then trims leading and trailing whitespace. It's a great feature, but why not call it str.split_whitespace?

'a b'.split(None) returns ['a','b'].

'a,,,b'.split(',') does not return ['a','b']. It returns ['a','','','b'].

Los Angeles Rent Increases

I just got a rent increase, and the text of the letter is pretty unclear about when the rent increase goes into effect. I got the notice around the 20th, so the California law says I need 35 days notice by mail, or 30 days notice in person.

CA department of consumer affairs, rent increases.

Angular JS Doesn't Suck

So I read this somewhat legendary rant about how JQuery is better than AngularJS, and AngularJS will fail. It's not going to fail.

It's just hard to learn. It's also verbose. You could say the same about any of the OO descendents of C. The difficulty generally comes from learning where your code should reside in the framework. Verbosity is just part of writing larger programs, and Angular is about writing larger programs. Maybe not large programs, but larger than a thousand lines.

Security Logic

Came up with this comment to help me think through end-user security.


	/*
	 * Security logic is based roughly on NTFS style allow and deny.
	 *
	 * The logic is as follows, in order:
	 * 1. If a specific role or user is in the deny list, they are denied.
	 * 2. If a specific role or user is in the allow list, they are allowed.
	 * 3. Otherwise, they are denied.
	 *
	 * There are three special values.  Anonymous is a user who is not logged in.
	 * All refers to all roles and users.
	 * None refers to no roles and no users.
	 *

Working at Night is Kind of Lame

So, after writing the big promotional article justifying TDD, I was doing some more Angular programming, and totally not having an easy time writing tests, so I gave up. The dependency injection framework makes it kind of hard. It'll make sense, eventually.

Test Driven Development (a cynical view)

So I'm trying to encourage a coding friend to do some unit testing. According to this blogger, testing isn't so popular in ObjC. Yeah, I can understand. It's a pain in the butt to learn the testing framework, and it's also a pain to write tests.

Then there's the intellectual conundrum: how do you write a good test suite that's likely to find your programming errors?

That's the kind of thinking that will send you down the rabbit-hole of computer (pseudo)science. The short answer is: you cannot. Stop contemplating.

Don't even try.

Syndicate content