Grunter

Editor’s Note: This is a slightly revised version of a post written in 2012 for a now defunct website. By using the “editor’s note” prefix and talking in third person, it is obvious I am not the author of this blog, but it’s editor. In no way are we the same person.

grunterThe Overview
Grunter is more than a new social network communication API web 3.0 paradigm template. Grunter is the new. The sun is setting on Twitter, and Grunter is the force of gravity directing that sun to crash into it. Grunter changes what it means to change – then it changes. Grunter redefines language, communication, society, civilization, and redefinitions. Forever. Like a glorious raging phoenix violently re-birthing from the ashes of Twitter’s cremation, Grunter soars through the digital skies inspiring awe. The world is a hollow and bleak reflection of itself without Grunter. Grunter simply is.

The Question
Everyone agrees Twitter is great, but the messages can be SO long to type and read and they have all kinds of words and stuff. Why can’t it be simpler to share my inane thoughts?”

The Answer
Now it is.

The Basics
Using any one of our soon-to-be-award-winning apps you can send a “grunt” to your “trough”. Grunts can be public or directed to specific users. For convenience you can subscribe to other troughs, in the Grunter parlance this is called “bellying-up”. This allows you to see all the grunts you care about in one combi-trough. You can control who can belly-up to your trough and limit access to specific grunts. Grunted messages can be up to ten characters long, with no spaces.

The Technical Sounding Shit
Grunter leverages distributed systems running on scalable enterprise technologies to provide an unparalleled application framework platform in the cloud. We use a ton of cloud, seriously. Our software ecosystem lays a comprehensive groundwork for a myriad of rich user interface interaction vectors. By mashing up cutting edge engineering methodologies into a single test driven development pattern, we have invented a new process for creating software that combines the best aspects of waterfall, agile, and scrum approaches. We call it Scragifall (TM) and using it guarantees rapidly produced bug-free code even when working with untrained monkeys. Grunter is written in Haskell, then compiled to bytecode, de-compiled to Ruby, and finally run in a VM built in node.js.

The Proof
The best way to convince your frontal lobe that Grunter is superior to all social networking available today is to feed it some examples. Here are some common tweets converted to grunts to give you the idea:

tweet: I’m an idiot who thinks you care about what I put on my bagel
grunt: unggg??!

tweet: I am so going to kick the shit out of you
grunt: Grrrrr!

tweet: I forgot my bib and drooled on my new shirt
grunt: ehhrrm…

tweet: OMG that video was like so cool LOL
grunt: drrrrrpp

The Pudding

“I have never even heard of twit her or whatever, but I do make a lot of guttural noises throughout the day. Grunter was a natural fit for me and it makes communicating online comfortable and fun.”

“I loved using Twitter and the little blue bird was cute, but everybody kept tweeting WAY too much text at a time, I’m talking like information overload! One time I even missed the first act on a new episode of Idol because I was reading some long-ass tweet. Now that I’m on Grunter all that has changed. I can still keep in touch with random strangers AND I never miss a minute of my favorite show! Grrrr!!!”

“I’m not a speed reader, so it can take me a whole day to get through four or five tweets. By the time I finish reading what’s new in the morning I have twice as many stacked up to go through in the afternoon! With Grunter I can quickly read my messages and get on with my day. Thanks to Grunter I have a life again.”

Cypht: New Open Source Webmail

I suck at product announcements, probably because I have no perceptible marketing skills. Usually I just whip out a list of technical details that even I can’t edit because I fall asleep by the third bullet point – A list that significantly limits the number of people who care one iota about what I’m blathering on about. What was I blathering on about? That’s right, sucky product announcements. Let’s pile another one on the heap, shall we?

This is the official wiz-bang super exciting announcement for a NEW shiny NEW Open Source webmail program called “Cypht” (pronounced “sift”). Did I mention it was NEW? New does not necessarily mean better you say? Well, I had not thought about that before deciding to emphasize it. Seriously however, in the world of Open Source webmail, new is actually exciting (and subjective I guess since I have been working on this for like a year already).

Will this software disrupt the E-mail paradigm while streamlining workflow to maximize interpersonal communication channels using a ground breaking application stack and development process? Nope. From a user perspective it’s like a lot of web-based E-mail programs you are already familiar with. From a developer perspective the code is experimental, with a focus on a smart overall design that offsets some of the downfalls of building a complex program in PHP.

Wait, don’t go just because I said PHP. It’s not like the other PHP based webmail programs I have worked on, but it’s also not just another vanilla web-based E-mail client. One of the core ideas and most interesting features is the concept of viewing aggregated E-mail from multiple sources, without actually forwarding the messages to a central account. Let me esplain:

I have a few Gmail accounts. An old Yahoo E-mail. Throw in a few other domains I own and I have about 5 or so accounts I want to keep up with (to varying degrees). I don’t want to auto-forward them all to a single account, I like keeping my work E-mail separate from my personal messages. So I said to myself,

“Self, why not build a webmail application that does that? One that could give self fast access to a list of all the unread messages in all self’s inboxes from the last 2 days. Or something like that. Oh and search and stuff.”

And so it came to pass, that said webmail was created and continues to be tinkered with. I have droned on endlessly about this software on this blog in the past, so if you are one of the people who came here for the “Linux on a Macbook Pro” post (which is why most people come here) and clicked on the wrong link, this probably sounds familiar.

Since this is not really new, not even new to this blog, why the awful product announcement? Is it just an excuse to rehash old post material until someone pays attention to your stupid program? Maybe, but I think we are getting a little off-track, and for the record its my blog so I will be the one asking the questions around here partner.

Did I mention I like lists of technical details? Here comes one!

  • Really small page sizes, like the entire page + JS + CSS + Ajax requests is less than the Google home page. With normal browser caching and HTML5 local session storage the data transferred is reduced to a stupifyingly small amount.
  • An extra emphasis on security and privacy throughout the application. This is an Open Source program meant to be safe and useful, not an ad generating machine mining your E-mail.
  • It’s not your dad’s webmail! Unless you are one of my daughters in which case it is your dad’s webmail.
  • Valid HTML5 pages with accessibility friendly markup and mobile views.
  • A module system that is like a plugin system on crank. It’s all friggen modules!
  • At this point in development, Cypht is a decent E-mail and news reader with limited outbound message support (in this context limited means don’t use it).
  • A huge following on Github of 1, combined with a large developer base of 1. This thing is taking off I tell you!
  • A website with tons of impressive sounding acronyms like IMAP, POP3, SMTP, HHVM, RSS, SSL, PHP, 2FA, PBKDF2, AES, and more!
  • Other stuff!

Still here? I’m as surprised as you are. This concludes today’s craptacular product announcement. This blog will now return to its irregular schedule of posts about video games or goats or whatever.

More Multiple Monitor Gaming On Linux

My affinity for using multiple monitors started when I was working in finance as a software developer. One of the many things I learned from that experience is that you can’t get any work done if you don’t have at least 3 monitors on your desk. When I’m not working, I like to put all those extra pixels to use by tweaking games on Linux to run at a 5760×1080 resolution across 3 displays. It’s a weird hobby I know, and until the last few years a pretty unproductive one as well. Lately Steam has been releasing games for Linux like crazy, and quite a few work with this setup. This is a follow-up to my original post on the topic, and includes an additional 12 games you might find interesting.

Civilization 5
http://www.civilization5.com/

civ5This is a great simulation game. Sid Meier’s Alpha Centauri is one of my all time favorites. I still have a Windows XP VM just for playing it floating around somewhere. Civ 5 is all that Alpha Centauri was and so much more. Really loving this game so far. It basically works flawlessly across 3 screens, the only annoyance being textures sometimes are slow to update if you pan around really fast.

Bioshock Infinite
https://www.bioshockinfinite.com/?RET=&ag=true bioshockThis is my first Bioshock title and I’m impressed. The story line is engrossing, and weird as heck. It won’t run full screen at this resolution, but it does support a “windowed full screen mode” that is part full screen, part windowed, and works great across 3 screens. Performance would be better with real full screen support, but with a single Nvidia 980GTX the game plays pretty smoothly with high (but not ultra high) settings.

Deadfall Adventures
http://deadfall-game.com/ deadfallThis game has incredible graphics, but it’s been hard to progress very far because of frequent lock ups and crashes. Hopefully things will continue to improve since it’s a good-looking first person adventure game. Keeping my fingers crossed!

Dying Light
http://dyinglightgame.com/?lang=en_US dying_lightThis game is a very cool first person zombie shooter parkour adventure thing. The graphics are amazing, so much so that I have to turn all the knobs to low in order for it to be playable – and even then the frame-rate is barely passable. I may have to dig into the configuration manually to see what I can do to improve performance over what the in-game options provide.

Euro Truck Simulator 2
http://www.eurotrucksimulator2.com/ eurotruckWho hasn’t dreamed of one day driving an 18 wheeler across Europe? Not me. Surprisingly this game is actually a lot more fun than it sounds. Just trying to keep the truck on the road is a challenge, never mind trying to back up to a loading dock. You can see how adept I am at this game in the screenshot as I calmly plow down the wrong lane of a road at 60 KPH into an oncoming semi.

Space Hulk Ascension
http://www.spacehulk-ascension.com/ hulkHonestly I have only played this game for a few minutes, but I have read really good things about it, and look forward to checking it out more. It’s sort of turn based tactical game from what I have gleaned so far. Works perfectly across 3 screens without any tweaking.

Nekro
http://www.darkforgegames.com/ nekroThis screenshot doesn’t really do this game justice. It’s a fun sort of top down action game in which you use dark magic to conquer your enemies and consume their blood to increase your power. I’m confidant it’s unlike anything else you may have played. Game play can be a bit redundant, but it’s an odd title that is still being developed and worth a look.

NeonXSZ
http://www.neonxsz.com/ neonThis is another game I have not spent a lot of time playing. It’s a 3D spaceship flying game with easy controls and some pretty cool dog fighting type scenarios. The graphics are decent, it runs very smoothly, and it “just works” on all 3 screens without extra effort.

Serious Sam 3
http://www.croteam.com/serious-sam-3-bfe/ SS3An older title but one that provides mind numbing waves of enemies to shred. It’s just good old shoot-anything-that-4moves fun. Be on the lookout for the guy in the screenshot, he may look like just a normal suicidal cyborg enemy whose hands were replaced with active bombs who runs directly toward you with all his buddies until close enough to detonate himself but … well actually that’s exactly what he is. And you really don’t have to look out for him since he screams at the top of his lungs from the moment he spawns to the moment he gives you a big hug.

Infinity Runner
http://www.walesinteractive.com/#!infinity-runner/c1g7s runnerA runner style game with a sci-fi style and a twist. Not only must you jump, slide, and turn to stay alive, you also have to fight enemies occasionally. While running. I have not quite figured that part out yet, my strategy of mashing the keys randomly has not paid off. It’s also apparently really dark, which I did not realize until I uploaded that screenshot.

The Talos Principle
http://www.croteam.com/talosprinciple/ talosA first person puzzler with nice graphics. I had to use windowed mode to get it to run on all screens, but performance is great even with everything maxed out. The graphics are Serious Sam-ish, but this is a puzzle game requiring problem-solving skills and not shoot-bad-guys-in-the-face skills. So far I’m enjoying it.

Ziggurat
http://ziggurat.wikia.com/wiki/Ziggurat zigguratThis is a cool RPG/action first person shooter mash-up. The game play is extremely fast and furious. With a huge variety of upgrades, magical attacks, and bad guys to conquer, this is a fun game with better than good (but not quite great) graphics. The game play makes up for any graphical short fall in my opinion, and it is one of the more enjoyable titles on this list.

I really wanted to include Borderlands 2 and Left For Dead 2 on this post, unfortunately I have yet to figure out how to make them place nice with my setup. I still have some tricks up my sleeve left to try, so hopefully they will be on the next installment!

The Best Job In The World

I have had a lot of jobs. I started working full-time during the summer when I was 14 in the very odd family business of transistor fabrication. I also spent a few summers in the highly esteemed position of hospital kitchen lackey. When I was 19, I had the good judgement to prioritize partying above scholastic endeavors, and consequently dropped out of college. I have been working full-time ever since. Except for a year during my hippie phase when I stuck it to The Man by being an unwashed leaching bum. Take that, The Man!

I have had jobs that felt like indentured servitude. Jobs the weigh you down and crush your spirit, all the while screwing you with low pay and crappy benefits. Conversely, I have had jobs that shower you with gold bullion for doing hardly more than showing up for work. Ok, maybe not gold bullion, but you get the idea. I even spent a few years running my own software development company. And by “running” I mean running it into the ground so deeply in debt that it would never resurface. My shortest employment was with a telemarketing company for a total of 4 hours. I decided not to return after lunch on the first day because my reading of the sales shtick made an elderly woman on the phone cry.

I consider myself lucky to have worked in software development for the last 15 years. Liking what you do is a huge bonus, but I think it’s possible to be completely content with your job even if it’s not your hobby. 20 years ago when I ran the holy hell out of a box-making-machine to scrape a few extra bucks of performance bonus, I really did not give a crap about boxes per se, but I enjoyed the challenge of being the best box-making-machine operator I could be. I also enjoyed the challenge of leaving with the same amount of limbs I arrived with due to the overwhelming level of OSHA violations. The satisfaction of a job done right can be its own reward. But a few safety guards are nice too.

We all have different priorities for what is important in a job. Pay, hours, benefits, flexibility, not having to evade a noxious cloud created by a combination of the cleaning fluid in your mop bucket with a vapor leak from an atmospherically controlled wafer oven at a transistor factory. Surely I’m not the only one that has happened to? For me there is a simple metric that goes a long way to pushing a job from the “why must I endure this monotony of pointless existence” category to the “it’s not that bad” bucket. Bathroom cleanliness. Just kidding, it’s the people you work with (but who doesn’t like a clean bathroom?).

For me, the best job in the world is the one with the best people. I have a low tolerance for assholery. I don’t do drama. Unchecked egos make me wretch. Even disaffection gets my panties in a bunch. Maybe this is one of the reasons I like working from home – the additional layer insulating me from a potential personality conflict. Maybe it’s just my aversion to pants. And haircuts. And showering. I’m not suggesting work should be some sickly sweet love-fest, but working along-side motivated and friendly co-workers makes whatever you are doing inherently more enjoyable. Unless of course your arm gets ripped off by a box-making-machine.

Fun With PHPUnit

What is the first word that pops into your head when you think about unit-testing? I’m guessing “Fun”, amiright? Ok maybe not fun. Unless repeatedly slamming your head against a brick wall is your idea of fun. Trying to build comprehensive tests for existing code is an exercise in patience. Like the Olympics of patience. Sometimes when I come up for air and wipe the blood from my head (and wall), I realize that while I was toiling away in the unit-test dungeon, I stumbled on something useful. Maybe it’s a feature I had not explored before, or a solution to a tricky situation. Maybe it’s something that will help inject a little fun into your PHPUnit experience.

Before I start throwing out random ideas, let me say that I really like PHPUnit: lots of knobs, good documentation, active development. PHP is the Yoga instructor of programming languages, but that flexibility means it’s easy to write poor quality code. When code and unit-tests don’t get along, the right answer is to send the code to bed without dinner, and if it’s really bad, ground it for the rest of the week. We can blame the code all we want, but sometimes there is no choice but to tweak the system to find a way to make it all work.

One of the biggest obstacles in testing is state. Things like global variables, static values or class instances can easily create a situation in which a test passes when run alone, but fails when run as a part of a suite. There are other types of states to consider aside from just the disastrous PHP global namespace. Sessions for example. Or the state of data in a test db or on disk. Tests that fail intermittently are hard to debug, and usually it’s due to an overlooked state issue.

Tests should be as insulated and independent as possible, and PHPUnit has a feature called “runInSeperateProcess” that forces each test to run in its own PHP process. Using this feature is not as simple as it sounds. If you have a bootstrap file defined in your phpunit.xml file, and it includes any code that defines a constant, you will get an error about redefining said constant in your tests. What gives? I thought each test runs in its own process? It does, but from what I can determine (using the throw-it-against-the-wall method), only the test code itself is run per-process. Assuming that poorly substantiated statement to be true, here is a pattern that does work with process separation.

Process Separation

First the phpunit.xml file, WITHOUT a bootstrap

<phpunit strict="true" colors="true">
    <testsuite name="my_awesome_tests">
<file>./my_awesome_tests.php</file>

Then the my_awesome_tests.php file, with the bootstrap included in the setUp() method and the @runInSeperateProcess and @preserveGlobalState annotations.

<?php

class My_Awesome_Tests extends PHPUnit_Framework_TestCase {

    public function setUp() {
        require 'bootstrap.php';
    }

    /**
     * @preserveGlobalState disabled
     * @runInSeparateProcess
     */
    public function my_test_one() {
    }
    /**
     * @preserveGlobalState disabled
     * @runInSeparateProcess
     */
    public function my_test_two() {
    }
}
?>

Finally, the bootstrap looks something like this

<?php

/* all the things */
error_reporting(E_ALL | E_STRICT);

/* determine current absolute path used for require statements */
define('APP_PATH', dirname(dirname(__FILE__)).'/');

/* get mock objects */
require APP_PATH.'tests/mocks.php';

/* get the code we want to test */
require APP_PATH.'lib/framework.php';

/* get the stubs */
require APP_PATH.'tests/stubs.php';

?>

mocks.php contains stand-in objects used as arguments to methods we want to test. The stubs.php file contains wrappers around abstract classes and traits so we can test them more easily. One advantage of this pattern is it makes it possible to pre-define constants in the setUp() method before the code being tested is loaded, so a test can exercise a code path that triggers on a non-default constant value (Assuming the code being tested checks for an already defined constant). Since mocks are loaded before the code being tested, we can also leverage this to override things unfriendly to testing.

Overriding Stuff

It’s good practice to limit mocking and overriding to a minimum. The more code that is mocked out, the less actual code that is being tested. There are however some built-in PHP functions that simply don’t play nice, like setcookie or header or session_start or error_log or die – you get the idea. Using the pattern as described above in “Process Separation”, we can easily add some override behavior to deal with these problems (sadly this does require changes to the code being tested).

In our mocks.php file we create a class of all static methods for built-in functions that don’t play well with others.

class BuiltIns {
    public static function php_header($header_str) { return true; }
    public static function php_die($msg) { return true; }
    public static function php_error_log($str) { return true; }
}

In the code to be tested, we setup a mirror image of this class that runs the actual built in functions, but only loads if the class is not yet defined.

if (!class_exists('BuiltIns')) {
    class BuiltIns {
        public static function php_header($header_str) {
            return header($header_str);
        }
        public static function php_die($msg=false) {
            return die($msg);
        }
        public static function php_error_log($str) {
            return error_log($str);
        }
    }
}

Then we replace occurrences of these built-in functions in the code to be tested. So this:

if ($error_str) {
   error_log($error_str);
}

Becomes this:

if ($error_str) {
   Builtins::php_error_log($error_str);
}

WOOT! Now we don’t have to worry about an errand error_log spoiling our unit-test party. We can even do something useful in the mocked out versions, maybe a fake session_start() call can populate $_SESSION or another constant in setUp can toggle success or failure from the mocked out function. The sky is the limit people!

Coverage

I have only recently started to look at PHPUnit’s coverage options. When I first tried it out, it bailed with a cryptic message and I was sad. Some head scratching and a few apt-get installs later, I was blown away. The HTML coverage report is incredibly useful. By default it sucks up other included files, so if you are dealing with a big code-base it can be handy to limit coverage to just code you are actively testing. I like to define these limits and enable the coverage report in my phpunit.xml file with something like this:

    <filter>
        <whitelist addUncoveredFilesFromWhitelist="false" processUncoveredFilesFromWhitelist="false">
            <directory suffix=".php">../lib</directory>
            <exclude>
            <file>../lib/not_tested.php</file>
            </exclude>
        </whitelist>
    </filter>
    <logging>
        <log type="coverage-html" target="./coverage.html" charset="UTF-8" highlight="false" lowUpperBound="35" highLowerBound="70"/>
    </logging>

The report is comprehensive. It has summary charts for coverage, complexity, risk analysis, and even line by line detail that makes it brain-dead easy to see what your tests are hitting, and more importantly, what they are missing. Coverage alone does not make a good unit test, but it’s a great tool to help improve your tests.

Extending PHPUnit_Framework_TestCase

This post is really dragging on so I will leave you with one additional trick I came across building unit-tests for a billing system. We wanted a test suite that we could run across a variety of products, but the tests code would be nearly identical. Duplicating the tests for each product was a maintenance nightmare. We needed a way to run virtually the same test code across multiple products. Here is what I came up with:

Start by extending the PHPUnit_Framework_TestCase class with an abstract class. This will be where the actual test code lives.

<?php

abstract class Base_Tests extends PHPUnit_Framework_TestCase {
    public function test_something() {
    /* your normal test code goes here */
    }
}
?>

Next extend that class for each product you want to test, and define the product as a member variable in the setUp() method so it can be accessed from the test method scope:

<?php
class Product_A_Tests extends Base_Tests {
    public function setUp() {
        $this->product = 'product a';
    }
}
?>

PHPUnit will not try to run the tests in the abstract class, but it will find and run the tests in the classes that extend it. For each product you want to test, just extend the base class and define the product details in setUp().

I’m hardly a PHPUnit expert, and there are surely improvements to these ideas or even completely better ways to accomplish the same thing. All of these examples minus the last one were taken from a unit-test suite for some Open Source software I’m working on. You can see the still-in-progress test code at Github, and an example of the coverage report from PHPUnit at jasonmunro.net.