Goodbye, GitHub.

GitHub was great.  It got me started on git, proving a context for learning the ropes.  I’ve had a paid account for the last 10 months to host my private repos.  After playing around with gitphp, I’m beginning to see that there’s a lot of potential that I’ve yet to tap into.  So I finally bit the bullet and got a remote git repository environment set up on my Slicehost dev server.

I’ll still use GitHub for Open Source project work.  I think that’s where it really shines.  But for now I’m planning to unsubscribe my paid account.

Thank you, GitHub.  Live long and prosper.

Code Literacy

It was not long ago that literacy was a profession. To be a scribe was to be amongst a small number of people capable of transmitting complex concepts through written words. Ideas encoded in the syntax of natural language. Seeing today that literacy is common place in any society with the means to educate its population, I wonder on the future of my profession. Will algorithmic literacy become common place in the coming generations? Synthetic languages taught alongside natural? English as core a subject to our education as UML? Grammar taught beside control flow?

As humans, our thoughts are subject to becoming twisted and munged. Informal scope lays the ground for false assumptions in a medium where emotion holds sway over our actions.

If natural language is a means by which to communicate our thoughts, then isn’t code but a similar means of communicating something which is closer to meaning?

In this way, a script might be seen as a sheet of music. Useful in its own right in the confides of a capable and accessible server, but more than that in its plasticity and symbolic representability. A sort of error-proof story to be told a thousand times a second by machines a world away.

Life is too short to submit to creating poorly constructed stories. Synthetic or natural.

A launch to alpha

Get first eyes on my newest project:

http://freenode.wircki.net/wircki

(comments please)

Simple Templating

I’ve seen a lot of code like this in the wild …

$a = <<<EOD
    <div>
    my name is $name
    blah blah blah....
    </div>
EOD;
call_api($a);

If this is the way you typically generate html for a page, I highly suggest you pull your head out of the sand and take a look around. Mahmud ahsan’s post outlines a basic example of output buffering and file inclusion …

ob_start();
include_once "html_markup.php";
$variable  = ob_get_contents();
ob_clean();
call_api($variable);

… and I’d like to take it a step further.

This sort of partial rendering is extremely common in any web application. A simple Template class with a static render method (a technique I learned from Sarfaraz Rydhan) is the quickest way to wrap this sort of functionality. Here’s what the class might look like :

class Template {
 
    static function render($tpl_name, $d = array())  {
        $tpl_dir = 'tpl/';
        $file_ext = '.tpl.php';
 
        $file = $tpl_dir . $tpl_name . $file_ext;
 
        if(file_exists($file)) {
            ob_start();
            include($file);
            $html = ob_get_contents();
            ob_clean();
        } else {
            $html = "Template ". $file ." Not Found."
        }
        return $html;
    }
 
}

Your template might look like this

<?php // [docroot]/tpl/user/greeting.tpl.php
    $name = $d['name'];
    $userid = $d['id'];
?>
<div class="user">Welcome back, <a href="/users/<?=$userid?>"><?=$name?></a></div>

To use this, you might say

echo Template::render('user/greeting', $user);

or

echo Template::render('user/greeting', array(
    'name' => $user_name,
    'id' => $user_id,
));

This would render the file tpl/user/greeting.tpl.php with an accessible mixed var $d which might represent a User model instance or an associative array (of key value pairs).

Using this sort of simple templating can encourage more thoughtful template file organization and a more granular template library.

Aptos post office sesh

File this under things I miss doing

 

Ayahuasca Documentary (early 70s?)

 

” What we have witnessed here is the survival of a tradition almost as old as man himself. It has survived in the unyielding spirit of a people deeply aware of the laws of nature and the place of man within her realm. “

GitHub PHP WebHook

So I just wrote my first webhook. Pretty exciting.

Here it is in all its glory. Post-commit from GitHub repo.

<?php
// Pseudo security.  REMOTE_ADDR could easily be faked.
if(gethostbyaddr($_SERVER['REMOTE_ADDR']) != 'github.com') 
    die("Get lost.");
 
// This function makes the requests.  
// http://netevil.org/blog/2006/nov/http-post-from-php-without-curl
function do_post_request($url, $data, $optional_headers = null) {
    $params = array('http' => array(
        'method' => 'POST',
        'content' => $data
    ));
    if ($optional_headers !== null) {
        $params['http']['header'] = $optional_headers;
    }
    $ctx = stream_context_create($params);
    $fp = @fopen($url, 'rb', false, $ctx);
    $response = @stream_get_contents($fp);
    return $response;
}
 
// Decode json payload
$payload = $_POST['payload'];
$data = json_decode(stripslashes($payload));
 
// Debug to postbin.org if you feel like it
/* do_post_request('http://www.postbin.org/q4wrg1', http_build_query(array(
    'referer' => gethostbyaddr($_SERVER['REMOTE_ADDR']),
    'payload' => stripslashes($paylaod),
    'data' => $data
))); */
 
// read commit messages and forward '# ...' messages to twitter clone
if(is_object($data) && is_array($data->commits)) {
    foreach($data->commits as $commit) {
        if($commit->author->name == 'KevBurnsJr' 
            && substr($commit->message, 0, 1) == '#') {
 
            $url = 'http://user:pass@tools.companyname.com/twitter_clone.php';
 
            // form fields
            $data = array(
                'headline' => substr($commit->message, 2),
                'hightlight' => 0,
                'workgroup' => 5,
                'submit' => 'Save',
                'userid' => 4
            );
 
            do_post_request($url, http_build_query($data));
        }
    } 
} else {
// $sample_payload_a = "{\"after\": \"0e2a75ac4434d110c3a1f03c53dda93f73bfcda9\", \"ref\": \"refs\/heads\/master\", \"commits\": [{\"added\": [], \"removed\": [], \"url\": \"http:\/\/github.com\/weareus\/core\/commit\/0e2a75ac4434d110c3a1f03c53dda93f73bfcda9\", \"modified\": [\"app\/views\/content\/_table.tpl.php\", \"app\/views\/question\/_table.tpl.php\"], \"timestamp\": \"2009-03-19T19:52:51-07:00\", \"message\": \"# Removing inaccurate table summaries\", \"author\": {\"name\": \"KevBurnsJr\", \"email\": \"kevburnsjr@gmail.com\"}, \"id\": \"0e2a75ac4434d110c3a1f03c53dda93f73bfcda9\"}], \"repository\": {\"owner\": {\"name\": \"weareus\", \"email\": \"info@weare.us\"}, \"description\": \"\", \"name\": \"core\", \"private\": true, \"forks\": 0, \"url\": \"http:\/\/github.com\/weareus\/core\", \"fork\": false, \"watchers\": 4, \"homepage\": \"http:\/\/weare.us\"}, \"before\": \"cd2fe2ef3c6f6aac4cabf34d6201635ada6d8033\"}";
// $sample_payload_b = "{\"after\": \"0e2a75ac4434d110c3a1f03c53dda93f73bfcda9\", \"ref\": \"refs\/heads\/master\", \"commits\": [{\"added\": [], \"removed\": [], \"url\": \"http:\/\/github.com\/weareus\/core\/commit\/0e2a75ac4434d110c3a1f03c53dda93f73bfcda9\", \"modified\": [\"app\/views\/content\/_table.tpl.php\", \"app\/views\/question\/_table.tpl.php\"], \"timestamp\": \"2009-03-19T19:52:51-07:00\", \"message\": \"Removing inaccurate table summaries\", \"author\": {\"name\": \"KevBurnsJr\", \"email\": \"kevburnsjr@gmail.com\"}, \"id\": \"0e2a75ac4434d110c3a1f03c53dda93f73bfcda9\"}], \"repository\": {\"owner\": {\"name\": \"weareus\", \"email\": \"info@weare.us\"}, \"description\": \"\", \"name\": \"core\", \"private\": true, \"forks\": 0, \"url\": \"http:\/\/github.com\/weareus\/core\", \"fork\": false, \"watchers\": 4, \"homepage\": \"http:\/\/weare.us\"}, \"before\": \"cd2fe2ef3c6f6aac4cabf34d6201635ada6d8033\"}";
/* ?>
    <form>
        <input type='submit'>
        <input type='hidden' name='payload' value='<?=stripslashes($sample_payload_a)?>'>
    </form>
<? */
    die('no data');
}

Illegal Links

Link to the wrong website in Australia and you could be fined $11,000 per day. http://is.gd/nDGe

We bitch about our antiquated bureaucracy here in the states, but hey, at least we’ve got free speech figured out.

Another weekend of hacking

This time I got some company from folks like @alienvenom at the Pi Day SuperHappyDevHouse

http://superhappydevhouse.org/

More hacking on Orbited’s IRC Demo
http://irc.hackyhack.net/

Cloned my hacked client to connect to SHDH on freenode
http://shdh.cloudbots.net/

Did some work on making my simple auth app for Recess! a little more generic in prep for modules.  Should have it up live on CloudBots soon.
http://cloudbots.net/

Doot dee doo, i guess that’s it.  Feels funny working on all this peripheral stuff without seeing how it’s all going to tie together.

Oh, I heard Mibbit may soon become the default IRC protocol web handler for irc:// and ircs:// in FireFox.  That’s pretty cool.  I wasn’t involved in the project, but I have been following it.  Axod’s obviously put a lot of work into it.  Interesting to see all the pieces required to bring a service like that together.  Congrats.

Abandoned Source

What happens when that open source library you’ve come to depend on loses momentum?  When the revisions stop being published and the lead developer goes dark?

You can either throw in the shovel and learn to use another library that doesn’t do quite what you want, quite as well, or pick up where the trail ends and try your hand at creating high quality software.

Unfortunately for us all, the former is often the path most followed.

Remember that open source software is not the result of free labor, it is the result of volunteer labor.

Be thankful that you don’t have to reverse engineer the obfuscated libraries.

WYMeditor now faces a similar fate.

Next Page »