Celebrating a milestone

This will be followed by a proper update, I promise. Meanwhile, I wanted to share what I think is a pretty good achievement. My OpenBSD box just reached 365 days of uptime (that’s days without being restarted, for the non-geeks). Its on its own dinky little UPS which I didn’t even think would kick in during the snow storm.

Say hi, Pudding!

Say hi, Pudding!

That’s Pudding sitting on top. There’s a story behind him (and his name), which I’ll share later ;)

I’m about to upgrade that to 5.2 so it will probably be another year until this happens again. I’m going to be hosting a couple of additional sites so PHP and Nginx need to be upgraded as well.

Dear David Cramer: You’re not the internet

Yesterday, David Cramer and a bunch of other people, who may go on to teach their children how to end civilization, decided to be an ass for no particular reason other than… well, it’s what all the cool kids do. Also, if you’re not needlessly rude about other people’s work you’re not a programmer… or a man, apparently.

Because grep and sed fit into every concievable situation. Situations inconcievable by David, don't exist.

Because grep and sed fit into every concievable situation. Situations inconcievable by David, don’t exist.

Mind you, these folks had no idea what that particular bit of code was for, where it was being used, how it was being used and any of the other million reasons why it exists. Granted, considering the medium of Twitter, it’s hard to be detailed on exactly why or what’s wrong with the said bit of code, but it would have been nice if he and the others bothered at the time.

Now this wouldn’t be so bad except the others, which IMO went quite a bit far and were in fact worse, have already apologized. Quite the opposite in fact, David became the Internet.

I'm not an ass. I am the Internet!

I’m not an ass. I am the Internet!

I’m sure she’s not mad people disagree with her. If David had read her post, he would have known this. This is about how you say it, not what you say.

Freedom of speech, David — I’m sure you’re thinking of right now — is not freedom from consequence of that speech. I.E. You can be an ass all you want and say things (short of unprotected speech) all day and night, however that means everyone else gets to call you an ass for being one.

Welcome to the New P̶l̶a̶g̶u̶e̶ Year

Hope everyone’s New Year went well. Normally, this would be an auspicious time for new endavors and adventures, but there’s bad news just two weeks in. Aaron Swarts, as many would know by now, has passed.  A lot of us have known for a long time, brilliance often comes packaged with turmoil and Aaron’s case was particularly tragic as he was particularly brilliant with a great deal left to contribute to this world.

The world is a lesser place without his presence. We’ll ponder what that means to the rest of us forced to suffer through life without him for quite some time.

For those who didn’t know who he was, here’s a very, very, very brief insight into the man that was. For those disturbed by the allegations of what he had done, here are some words from people who knew exactly what he did and how the government responded.

In less upsetting news

I have the flu. Well, less upsetting than Aaron passing since I’m not quite sure how to absorb that at the moment.

It’s also the reason I’ve been sticking to Twitter for the past few days instead of posting here. I knew I was getting sick, but chalked it out to the common cold. Since I have the immune system of a newborn infant, I get sick quite often, but the flu is a bigger issue since I can’t get the flu shot. I’m not allergic to eggs, it’s just my immune system is just that… weird. The shot or the nasal spray will invariably make me just as sick as the flu.

Now writing this still on my bed where I’ve resided for the past six hours after waking up and I’m about to go stir crazy. I hate doing nothing, but nothing is what I’ve been ordered to do.

Meanwhile, before I got sick, I started work in a small side-project that I hope to launch by the end of next week (aiming for 19th or 20th). Not sure if I’ll maintain that timeline now, but we’ll see. I’ll post news of that soon.

Why Linus sucks and is awesome at the same time

Warning, naughty language.

Behold :

On Sun, Dec 23, 2012 at 6:08 AM, Mauro Carvalho Chehab
<mchehab@redhat.com> wrote:
>
> Are you saying that pulseaudio is entering on some weird loop if the
> returned value is not -EINVAL? That seems a bug at pulseaudio.

Mauro, SHUT THE FUCK UP!

It's a bug alright - in the kernel. How long have you been a
maintainer? And you *still* haven't learnt the first rule of kernel
maintenance?

If a change results in user programs breaking, it's a bug in the
kernel. We never EVER blame the user programs. How hard can this be to
understand?

To make matters worse, commit f0ed2ce840b3 is clearly total and utter
CRAP even if it didn't break applications. ENOENT is not a valid error
return from an ioctl. Never has been, never will be. ENOENT means "No
such file and directory", and is for path operations. ioctl's are done
on files that have already been opened, there's no way in hell that
ENOENT would ever be valid.

> So, on a first glance, this doesn't sound like a regression,
> but, instead, it looks tha pulseaudio/tumbleweed has some serious
> bugs and/or regressions.

Shut up, Mauro. And I don't _ever_ want to hear that kind of obvious
garbage and idiocy from a kernel maintainer again. Seriously.

I'd wait for Rafael's patch to go through you, but I have another
error report in my mailbox of all KDE media applications being broken
by v3.8-rc1, and I bet it's the same kernel bug. And you've shown
yourself to not be competent in this issue, so I'll apply it directly
and immediately myself.

WE DO NOT BREAK USERSPACE!

Seriously. How hard is this rule to understand? We particularly don't
break user space with TOTAL CRAP. I'm angry, because your whole email
was so _horribly_ wrong, and the patch that broke things was so
obviously crap. The whole patch is incredibly broken shit. It adds an
insane error code (ENOENT), and then because it's so insane, it adds a
few places to fix it up ("ret == -ENOENT ? -EINVAL : ret").

The fact that you then try to make *excuses* for breaking user space,
and blaming some external program that *used* to work, is just
shameful. It's not how we work.

Fix your f*cking "compliance tool", because it is obviously broken.
And fix your approach to kernel programming.

             Linus

ID Obfuscation Part II

Last week, I wrote a simple function for obfuscating a string that can be used to shorten URLs. I got a few emails from people who would actually like to obfuscate an ID key (E.G. a numeric primary key) of a large size (E.G. a PostgreSQL ‘bigserial’ type which can go up to 231). So many examples out there, but they seem convert the input to integers first, which can lead to loss of precision, especially in PHP.

I use Postgres too and I’ve moved around the big number problem by appending a random digit or two to the front and then encoding the whole thing. So when I need the original, I just decode it and remove the front digit(s). This does two things: It obfuscates the ID (no one needs to know 10001 and 10002 are neighbors) and makes sure each one is unique as long as the key given to it is unique. Of course if it’s a primary key from a database, you won’t have to worry too much about uniqueness; it already is. And since I’m always appending the same number of digits as I’ll remove when decoding, it doesn’t matter how large the number gets.

So here’s a function that will create a shortened ID from a given numeric key in PHP :

public function ConvertKey( $k, $create = false ) {
	
	$range = str_split( '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' );
	$il = strlen( $k );
	$cl = 62; // count( $range ) is redundant;
	$out = '';
	
	// Get number from key
	if( $create ) {
		
		$out = 0;
		
		// Letter/number to array key swap
		$a = array_flip( $range );
		for( $i = 0; $i < $il; $i++ ) {
			
			$c = $k[$i];
			$n = bcpow( $cl, $il - $i - 1 );
			$out = bcadd( $out, bcmul( $a[$c], $n ) );
		}
		
		// Strip front two random digits (appended below)
		$out = substr( $out, 2 );
		
	} else {
		
		// Append two random digits to the front
		// (NOT added, just attached to the front)
		$k = mt_rand( 10, 99 ) . $k . '.0';
		
		do {
			$c = bcmod( $k, $cl );
			$out .= $range[$c];
			$k = bcdiv( bcsub( $k, $c ), $cl );
			
		} while( bccomp( $k, 0 ) > 0 );
		
		// We worked from back to front
		$out = strrev( $out );
		
	}
	
	return $out;
}

You can test this out by sticking it in a loop :

for( $i = 5000; $i < 6000; $i++ ) {
	
	$kConverted = ConvertKey( $i );
	$kOriginal = ConvertKey( $kConverted, true );
	echo $i . ' - ' . $kConverted . ' - ' . $kOriginal . '<br />';
}

Of course, you’ll need to keep in mind that the generated key will be different each time you run it, however the end result after decoding will be the same.

I also wrote a post on encryption with… *ahem*… colorful comments and, thankfully, most people stuck to the actual code itself when contacting me about it. Yes, I did change the encryption mode from CFB to CBC. CFB doesn’t need padding so I wasn’t lying about the sleep-deprivation. Thanks to those who wrote to me about it.