sneakybits

...


3 years ago

Arduino & Node.js Make Love

Here’s how to get Node.js to read serial data from an Arduino.

First, install serialport:

npm insall serialport

Then:

var serialport = require('serialport')

const DEV = '/dev/ttyUSB0'
const BAUDRATE = 9600

sp = new serialport.SerialPort(DEV, { 
  baudrate: BAUDRATE,
  parser: serialport.parsers.readline("\n")
});

sp.on('data', function(data) {
  console.log(data)
})

(with Node 0.4.8 on Ubuntu 10.10)

3 years ago

Pest: a proper REST client for PHP

The people over at Zend, “The PHP Company”, don’t seem to understand what REST is. The so-called Zend_Rest_Client is not actually a REST client at all; more like RPC over HTTP or something.

There don’t really seem to be any alternatives, other than using the CURL library directly to make GET/POST/PUT/DELETE requests, so I wrote my own. Here’s the result:

http://github.com/educoder/pest

And here’s a usage example with the OpenStreetMap REST service:

<?php

/**
 * This PestXML usage example pulls data from the OpenStreetMap API.
 * (see http://wiki.openstreetmap.org/wiki/API_v0.6)
 **/

require_once '../PestXML.php';

$pest = new PestXML('http://api.openstreetmap.org/api/0.6');

// Retrieve map data for the University of Toronto campus
$map = $pest->get('/map?bbox=-79.39997,43.65827,-79.39344,43.66903');

// Print all of the street names in the map
$streets = $map->xpath('//way/tag[@k="name"]');
foreach ($streets as $s) {
  echo $s['v'] . "\n";
}

?>
3 years ago

This is what happens

This is what happens when you spend too much time coding in statically typed languages

http://www.diaspora-news.net/2010/11/29/im-dropping-diaspora-this-site-is-now-closed/

3 years ago

James Blake - Limit to Your Love

4 years ago

from Washed Out - Life of Leisure

4 years ago

How to recover deleted text files on a Mac

Yesterday an accidental rm -rf * cost me a good two days of work. I lost an entire directory of Ruby code…. haven’t done something like this to myself in years, and never before on a Mac.

So I started googling for Mac file recovery software, only to find a crapload of expensive tools, none of which as it turns out are able to recover plain .rb text files. Anyway, long story short, here’s how to recover deleted (i.e. unlinked) text files on a Mac — I couldn’t find this info anywhere else, so I figure I’d post it here for posterity:

  1. Download 0xED. It’s a free Hex editor for Mac OS.
  2. Once downloaded, you’ll have to run 0xED with root privileges:
    1. Open a Terminal, and cd into the directory where you put the 0xED app.
    2. Run sudo 0xED.app/Contents/MacOS/0xED
  3. 0xED should now be running with root access. Go to File -> Open By Path…
  4. This is the tricky part. You will now be “opening” the disk where your deleted files are still sitting, as if the disk were one giant file. In Mac OS X, disks are accessible as a block devices under /dev/rdisk#. If you only have one hard disk in your machine, then it’s probably /dev/rdisk0, as it was for me. You may have to do some digging around to figure out the correct disk number. Also, if you have multiple partitions (i.e. “volumes”), and you know which partition the files are on, you might want to open that partition rather than the entire disk. For me this was the second partition, so I entered /dev/rdisk0s2 into the “Open By Path” dialog in 0xED.
  5. If you’re still with me, you should now be looking at the raw contents of your hard disk in 0xED. Next, in order to find your lost data, you’ll have to locate it on the disk. This is pretty much impossible unless you can remember something of what was in your lost data, and preferably it should be something that was unique. In my case, I remembered a particular line of code in one of the missing files that I knew I hadn’t used anywhere else (Neo4j.start).
  6. In the top right of the 0xED window there’s a “Text search” field. Enter the text you want to search for, press enter, cross your fingers, and wait…. and wait… and wait. This part can take a very long time. You’re doing a text search on your entire drive. What do you expect?
  7. For me, it took about half an hour, but eventually 0xED located my missing code. Yay! You should now be able to highlight the text you want to recover, and copy and paste into a new file.

0xED rescuing

4 years ago

Node.js »

This caught my eye today: http://nodejs.org

Essentially it’s an event-driven framework for server-side (as opposed to browser-side) JavaScript.

Looking through the docs and examples this smells really really good to me.

Lately I’ve been working on a little daemon that bridges RESTful HTTP on one end with an Arduino controller on the other (basically so I can talk to my Arduino sketches from a web browser, an android phone, etc.) So far I’ve been writing it in Ruby + Sinatra, but this is proving kind of awkward. The code that talks to the Arduino controller (via serial IO) will probably have to run separately from the Sinatra server, and I don’t really have a good plan for communication between the two.

Node.js seems much better suited for this. For one, I can keep the HTTP and Arduino code together. But more importantly, the conceptual base unit for Node.js being the ‘event’, this feels very right for writing code that’s supposed to be directly interacting with the real world. This way I can deal with incoming data pulses from the Arduino and incoming HTTP requests from the cloud in the same way.

We’ll see how it goes.

4 years ago

HTML5 - keep dreaming

HTML5 is turning out to be a pretty disgusting mess. I mean, HTML has always been a questionably ambiguous language… but things are getting ridiculous.

See, for me, a better place is a world where HTML finally sheds its SGML vestiges and grows up into true XML. Don’t get me wrong, XML is an ugly, unwieldy language, but it does hold the promise of a kind of universality — a standardized, predictable way of serializing data. That kind of standardization makes working with a lot of different kinds of content a whole lot easier (from a programmer’s point of view anyway). The rest of the world realizes this too. This is why just about everyone is switching to XML-based formats. Even Microsoft — the perennial violator of standards — has embraced XML, with the Office suite now using OOXML as its native file format.

Imagine a world where the same set of base tools (XPath, XSL, and a host of abstraction libraries and GUI utilities) can parse, manipulate, and transform just about any kind of content — web pages, vector graphics, spreadsheets, scientific datasets, 3D models…. Sounds nice, right?

So, here we are, well into the 21st century, at the cusp of the emergence of a (nearly) universal data serialization format, and what does the W3 do? They kill off XHTML — the XML-compatible version of HTML.

What we’re left with is the monstrosity that is HTML5 — a language straight out of the 1990’s, with a bunch of shitty new tags, like <canvas>, which nobody will use because 1) we already have Flash and 2) <canvas> offers little if any improvement over Flash (why isn’t <canvas> SVG? … now that would be something), and <section>, whose distinction from <div> is dubious at best.

As for the dream — consistent, XML-compliant HTML? Sure, no problem. The W3’s answer is that some HTML5 will be XML-compliant. But some won’t. And how do you tell if some piece of HTML5 is XML-parsable? You can’t. It might all look like XML, but in their wisdom, the W3 (or was it the WHATWG?) announced that only the mime type will differentiate the XML-compliant stuff from the unparsable SGML-based HTML5 mess. Want to validate your XHTML5 using the standard XML validation systems (DTD, etc.)? Too bad. No DTD/XSD/RNG/Schematron has been published, and since HTML5 is not really XML, it’s not clear if XML validation will ever be supported.

Lovely.

4 years ago

Ambling Alp

Ambling Alp This is so balls-out good. I can’t stop listening to it. There’s some Animal Collective here, but warmer, and some The Knife, but less alien. I’m really looking forward to the full album.

Yeasayer were looking a bit on the sickly side in recent footage… I was starting to worry this band was headed for rehab or worse, but hearing the goodness in this single is reassuring.

4 years ago

Nerdemøte!

What I learned in California:

Pajaro River Sunrise

Also —> Educoder.org

4 years ago

http://matt.zukowski.ca »

New portfolio site, done.

4 years ago

Document annotation, online

Why is there still no good online service for document annotation? I want to upload a PDF, highlight a few passages, add some comments, and send off a link to the annotated version for someone else to look at.

This seems like a no-brainer, yet no one seems to be able to do this, at least not very well.

Did I miss anything? I’d be surprised if the people at Scribd (and maybe Google too) weren’t already working on adding annotation functionality. If not, this may be a rich niche just waiting to be filled.

4 years ago

The XX

The XX Stuff like this doesn’t come around too often. This is a brilliant album through and through. Maybe it’s just planets aligning — right place, right time, never to be repeated — but I can’t wait to see where these people go next.

4 years ago

Wittgenstein

Wittgenstein Started reading Severin Schroeder’s Wittgenstein.

Regarding the Viennese outlook on life:

Towards the end of the First World War in Berlin the situation was described as ‘serious, but not hopeless’; in Vienna they called it ‘hopeless, but not serious’.

Schroeder makes Vienna (during Wittgenstein’s formative years) sound like Huxley’s Brave New World, with a society subdued and disenfranchised by “light opera and pleasant conversation”:

… the Viennese public, genial, fun-loving and fond of make-belief … [sought only] to avoid unpleasantness, to take life easily, sceptically, and to get out of it as much thoughtless enjoyment as possible. … In Vienna everybody seemed to be able to spend hours each day sitting in a coffee-house reading the papers, playing chess or in leisurely conversation.

Maybe hyperbole but doesn’t sound too bad does it.

4 years ago

Switched to Tumblr

Blogger was painful at best.

… but options for posting code samples with syntax highlighting don’t appear any better here.



Powered by Tumblr.