Archive for the ‘Uncategorized’ Category.

Review “The Wasp Factory”

The Wasp FactoryThe Wasp Factory by Iain Banks
My rating: 4 of 5 stars

Very well written. First-person account of a psychopath or maybe a sociopath living deep inside a metaphor in Scotland. Very unsettling, with a narrator who’s clearly unreliable, so one is always wondering if incidents or even entire characters are imaginary. Although certain twists were heavily foreshadowed, the denoument was still quite tense. My only qualm is that I think the final few pages spelled out too much — it would have been more haunting if the narrator didnt become suddenly insightful and deconstruct the metaphor.

Havent been so compelled to turn pages in a while.

View all my reviews

via Goodreads | Larry Obrien Kailua Kona, HIs review of The Wasp Factory.

Accessing the Android Barometer using Xamarin.Android

Easily:

< ![CDATA[
[Activity (Label = "HelloBarometer", MainLauncher = true)]
public class Activity1 : Activity, ISensorEventListener
{
    TextView mainLabel;  

    protected override void OnCreate(Bundle bundle)
    {
        base.OnCreate(bundle);
        // Set our view from the "main" layout resource
        SetContentView(Resource.Layout.Main);
        //Detect the barometer
        var sm = (SensorManager) this.GetSystemService(Context.SensorService);
        var barry = sm.GetDefaultSensor(SensorType.Pressure);
        //Subscribe to it
        sm.RegisterListener(this, barry, SensorDelay.Normal);
        // Get our button from the layout resource,
        // and attach an event to it
        mainLabel = FindViewById<textview>(Resource.Id.myText);
    }

    public void OnAccuracyChanged(Sensor sensor, SensorStatus accuracy)
    {
        Console.WriteLine("Things have changed");
    }

    public void OnSensorChanged(SensorEvent pressureEvent)
    {
        Console.WriteLine("Under pressure " + pressureEvent);
        var hPAs = pressureEvent.Values[0];
        var msg = string.Format("Current pressure: {0} hPA!", hPAs);
        mainLabel.Text = msg;
        var calcedAltitude = calculateAltitudeInFeet(hPAs);
        FindViewById<TextView>(Resource.Id.altitudeText).Text = string.Format("Calculated altitude is {0} ft", calcedAltitude);
    }

    double calculateAltitudeInFeet(float hPAs)
    {
        var pstd = 1013.25;
        var altpress =  (1 - Math.Pow((hPAs/pstd), 0.190284)) * 145366.45;
        return altpress;
    } 
}
]]

I mean, I know I work for the guys, but this is just *ridiculously* easy. An hour ago I was installing the SDK...

And, yes, I live high on the side of an active volcano.

Tap 7 Times to Enable Developer Options in Android Jelly Bean

How to enable developer settings on Android 4.2 | Android Central.

I just got myself a Nexus 4 for cross-platform development, but it didn’t initially appear as a device in Xamarin Studio. Initial Googling and SO’ing indicated a non-existent “Settings->Application->Developer” route to enable debugging on the phone.

Instead, the correct sequence is “Settings->About phone->{tap 7 times} Settings->Developer Options”

The Governor vs. Boyd Crowder

The Justified finale had a scene that summed up one of it’s greatest strengths: Raylan, the putative hero, and Boyd, the putative villain, demonstrate how parallel they are to each other: Raylan points to Boyd’s career and sneers at the thought that Boyd imagines himself anything other than “the bad guy.” Boyd points to Raylan’s actions and sneers that Raylan thinks he’s any different. Perfect: They are different, and make different choices, but both focus on different aspects, highlighting the ambiguity of the moral dilemmas that, taken one way, lead to acclaim and promotion in the US Marshall’s Service and, taken another, lead to universal contempt and jail.

Which they’d similarly set up with the Governor and Rick in The Walking Dead. Rick crazily hung on to the voice and visions of his dead wife while making the fateful decisions necessary for survival, the Governor hung on to the physical body of his dead daughter while doing the same. While the hard truth is that both are in the business of ordering the brutal actions that are necessary to make their group survive, Rick soothes himself by wallowing in guilt based on pre-zompocalypse morality. The Governor steels himself by sitting and staring at decapitated heads in fishtanks that are still gnawing to get at him. But why do people dwell on things? To bolster their weak spots: Rick’s belly-aching about morality implies that he needs to remind himself to not let it disappear, while the Governor’s zombiequarium implies that he needs to remind himself to never let himself relax. A similar point was made when the Governor said that, had he acted forcefully from the beginning, his daughter would fear him, but be alive. Meanwhile, we saw that Rick’s son is a little disdainful of his Dad’s morality.

But instead of developing the theme of parallelism between Rick and the Governor, they just put the Governor on the crazy train. Oh, he wasn’t just brutal, he was a sadist. He wasn’t just committed to pre-emptive murder, he was a psychopath. And most frustratingly of all, in the finale, he wasn’t a competent leader. And not only wasn’t he a competent leader in his assault on the jail, he apparently had never been competent in training his people to have the proper level of paranoia and response to deal with sneak attacks.

And just at a basic dramatic level, they cheated us of a final confrontation between the Governor and one of our protagonists. Instead, he slunk off with his A-team baddies and will now be a possible occasional appearance. Very disappointing for a show whose greatest strength is its willingness to kill off established characters.

Hungarian Monadic Notation: Call Me Maybe

Update: this is an April Fool’s joke. It’s the most incoherent, illogical thing I could think of. It’s a bad idea, it wouldn’t work, and it misses the point of everything.

Hungarian Monadic Notation: Call Me Maybe()

Update: This was an April Fool’s joke. If you are interested in monads and are a C# or Java programmer, I strongly suggest this series of posts by Eric Lippert, which explains monads in a very pragmatic way.

If you follow the world of software development at all, you know that there has been a big uptick in discussion about “functional programming languages,” a type of language that emphasizes immutability and composition of functions to achieve higher reliability and, arguably, higher productivity.

On the other hand, functional programming languages look like Klingon, but with math:

instance Monad[] where
   return x = [x]
   xs >>= f = concat (map f xs)
   fail _ = []

WTF, ammiright? (And for extra points, it’s not a right-shift, it’s “bind.” Because arcana.)

The most laughable claim of the functionistas is that functional code is easy to comprehend and debug. Lemme’ tell ya, bud, I’ve been a dozen lambdas deep trying to figure out behavior and this whole “functional code is stateless,” is more full of crap than an Oklahoma feedlot at slaughter time.

Functional programs have every flutter of state that an imperative program has, just not in any convenient stackframe. Or — and this is awesome to debug — it’s not yet in the stack frame — what’s in the stack frame is a bunch of goddamn function pointers and not-yet-enough parameters to call them. Sometimes the thing you’re stuck on is a dozen lambdas down and it’s building a goddamn function pointer that will calculate the parameters (Excuse me! I mean calculate exactly one parameter!) to another goddamn function pointer. Thank heavens you don’t have to struggle with the mind-numbing complexity of an if branch (“Oh my God! The code could go this way or it might go that way! What kind of cephalopodic mind could comprehend this tangle‽”).

And don’t get me started on compilation speed. I love this idea that the “compiler finds certain errors.” What they don’t say “And it does this in a mere several minutes. So don’t worry about missing one of those show-stopping narrowing conversions! We’ll take a look at it every goddamn time you want to fix a typo in a different source file.”

But, nonetheless, there are a few things that the FP world does that actually make sense once you machete away all the obfuscatory mathematical rigor.

Maybe Something Functional Does Right

The biggest practical thing, on a day-to-day basis, is that functional code doesn’t have to deal with null values. If you have some complex object that may-or-may-not initialize properly (let’s say a camera which may or may not be available on your phone), you are probably used to writing code that looks more or less like this:

var theCamera = AttemptCameraInitialization();
if(theCamera == null){ 
   DealWithNoCamera(); 
}else{ 
   var aPhoto = theCamera.TakePhoto();
   if(aPhoto == null)
   {
      DealWithNoPhoto();
   }
   …etc…
}

Or maybe:

try{
    var theCamera = AttemptCameraInitialization()
    var aPhoto = theCamera.TakePhoto();
}catch(npe){
    DealWithNullPointerException(npe);
}

And while the try-catch style isn’t nearly as wordy as the constant-error-checking style, it’s a little harder to debug and good coding style says that one ought not to rely on exceptions to deal with common alternatives. Contrast this with what one might see in the functional world (exact names and syntax differ between functional languages, so I’ll use Scala, whose Klingon-y parts can be swept under the rug, and can actually be comprehended by humans):

 val theCamera = AttemptCameraInitialization();
 val thePhoto = theCamera.TakePhoto();

And even if there was a problem during AttemptCameraInitialization(), no exception would be thrown. Instead, theCamera would be represented by a None object and, when a function is called on a None object, that None object simply returns another None.

So this may look like no big deal with a couple lines of code, but if you have an A that has a B() function that returns a B that has a C() function that returns a C that…a Y that has a Z() function that returns a Z, you can write code like:

var myZ = a.B().C().D().….X().Y().Z(); 

Which is much more readable than putting a bunch of checks-for-null between every method. And in this situation, you just are ploughing along nicely through your functions until one returns a None, in which case every function subsequent to that returns a None. (So how much fun is it when you’ve stepped your debugger up to that one line of code? But put that aside for now…)

So, talk to a functional guy about what’s going on and BOOM he drops the “M” word. Of all the gatekeeper-words in the mystical arcana that guard the entrance to the D&D den where all the cool functional kids are hanging, none has the power of “Monad.” It evens sounds like something that Gandalf would warn you about: “Beware the realm of endofunctors, for there, monoids become monads!”

Lemme’ tell ya’, I’ve been There and Back Again and monads are no big deal. They’re just goddamned parameterized types with a handful of easy semantic rules. Seriously. That’s it. The reason that they’re confusing is that the semantics are so stupidly underwhelming that you keep thinking “Yeah, okay, but what else?” It’s like the gate to your vast underground treasure-city being guarded by the word “friend,” a fact which is conveniently documented on the transom.

Anything Monads Can Do, Inheritance Can Do Better

So how are we gonna’ do this? Easy! Let’s say we start with a couple classes that look like this:

class Camera 
{
    Photo TakePhoto() { … etc…}
}

class Photo
{
    Bitmap GetImage() { … etc… }
    Exposure GetExposure() { …etc… }
   …etc…
}

All you have to do is define the interface to these objects, so that we can implement simple alternative “None” classes. But to help future maintenance programmers, we’re going to use a little invention of mine called “Hungarian Monadic Notation” to indicate our intent:

interface MMaybeCamera 
{
    MMaybePhoto TakePhoto();
}

interface MMaybePhoto
{
    Bitmap GetImage();
    MMaybeExposure GetExposure();
}

The way this works is that we indicate that a class or interface has this monadic intention by prefixing it’s name with an “M”. But because there are a lot of different monad patterns, you specify which monad in particular you’re talking about as the next part of the name. So in this case we have MMaybeCamera indicating that we’re looking at this particular pattern. Ditto for MMaybePhoto but you could also have, like, MEitherPhoto or MStateCamera etc. The possibilities are endless! And it’s super-easy to do and doesn’t introduce any of those stupid compilation errors!

Now that you’ve used HMN to name your interfaces, you just change your original implementations to implement the HMN interface:

class Camera : MMaybeCamera{ … original code… }

class Photo : MMaybePhoto { …original… }

But in addition, you also implement the alternative “empty” objects:

class NoneCamera : MMaybeCamera 
{
    MMaybePhoto TakePhoto()
    {
        return new NonePhoto();
    }
}

class NonePhoto : MMaybePhoto
{
    MMaybeExposure()
    {
       return new NoneExposure();
    }

    Bitmap GetImage() 
    {
       throw new MonadException("This is a none,son.");
    }
}

Isn’t that inspiringly clean code? When you call a function on a None{x} class, it just returns another new None{y} object! Or, when you need to break out a real class, you just throw a MonadException. (The details of MonadException are left as an exercise.)

Naturally, you kick this all off with a MMaybeCameraFactory to initialize your original MMaybeCamera.

Future Work

Although Hungarian Monadic Notation and it’s implementation patterns are agile best practices worthy of the enterprise, it’s true that there’s a certain amount of boilerplate code that’s associated with implementing each of the functions in the base interface.

In a future post, we’ll cover the answer:

Reflux: The Monadic Reflection Dependency Injection Framework

Literate Programming from HTML

OK, let’s see if this works…

This is the basic structure of the “Hello, World!” program in C#:

using System;

class Hello
{
   <getchunk id="Main"/>
}

where the Main chunk is defined as :

static void Main()
{
   Console.WriteLine("Hello, World!");
}

C# Command-Line Extraction

And if you clone my Github repository, you can:

$ mono mtangle.exe MyWordPressPage.html HelloWorld

using System;

class Hello
{

static void Main()
{
   Console.WriteLine("Hello, World!");
}

}


You can read a poorly-written bootstrapping explanation here.

The Gray

Spoiler alert.

Not that you care. Scientists at UCSD have shown that people actually prefer stories when they have advance knowledge of the plot twists. Maybe movie companies have figured this out, because the trailer for The Gray has the final two shots of the movie in it. Not, mind you, the final stunt, like in “Mission: Impossible” where the trailer featured (SPOILER ALERT!) Tom Cruise being flung from the exploding helicopter onto the train, which I always thought was the ultimate in bad-faith — but the final two shots of the movie. So (SPOILER ALERT!) you never see Liam Neeson go mano-a-mano with the alpha wolf. You know, like was promised in the damn trailer when they showed Liam Neeson with the mini booze bottles strapped to his knuckles and growling. CUT TO BLACK, ROLL CREDITS. Yeah, that’s the end of the damned movie.

No pata-a-bottelo fight between Liam Neeson and the Wolf King. Which isn’t gray. It’s black. Wait! The Gray isn’t the wolf! It’s Liam! He’s morally ambiguous! Or middle-aged! Or, subsequent to standing against the wolf-king, will return as Liam the White! No, that’s not it. Let’s go for morally ambiguous. Yeah, that’s it. “The Gray” isn’t about the battle out there, or out there, it’s about in here (point at head)… And the battle in here (point at heart).

It’s also about how very, very ominous coughing is. Maybe the whole movie is a dream of a man dying in a tuberculosis ward. That would make about as much sense as the purported plot, which is that Liam is a wolf-sniper for a let’s-say-oil-company on Alaska’s North Field. Liam dreams of lying beside his wife, who died of let’s-say-cancer, and who tells him not to be afraid. But Liam is afraid, as he tells Diaz-The-Hard-Case. Liam says “Any man who isn’t afraid is a liar, or a damn fool.” Actually John Wayne said that in “Sands of Iwo Jima” but Liam says something awfully similar. And then he alpha-rolls Diaz-the-Hard-Case, pisses on him, and the Wolf King realizes that there are two Wolf Kings afoot North of the Wall. And There Can Be Only One!

Or maybe there are, like, dozens of Wolf Kings. Because after Liam survives falling out a jet (soft snow) and puts together a rag-tag band of misfit survivors (a hard case, a philosopher, a couple guys in red shirts, and a token black dude) Liam explains that they can’t stay at the wreck site, what with its shelter, supplies, and attraction to rescuers. No, they must “wait until sunrise, figure out which way is South, and walk to help.” Which makes sense because, obviously, if you’re so deep in the Alaska backcountry that the company just writes off jet crashes (they actually say that — “What do they care? Do you know how much payroll they save by letting us die?”) then obviously the smart thing to do is hike to Anchorage.

Which is smart, too, because the plane crashed within the “kill radius” of a wolf den — the radius around a den in which wolves kill all living things…

OK, so at this point in the movie I told myself “OK, fine, it’s not Alaska. It’s Ice Planet Zebulon and they aren’t wolves, they’re Shark-Wolves. And, you know, I’m going to ignore the business about it being cold but no one putting their hood up or even zipping up their damn parkas. It’ll be fine. Trust in Liam.”

…So they walk. They walk miles and miles. They walk so far that Diaz-the-Hard-Case becomes Walt Whitman and accepts his fate as Meal #8 for… Well, apparently the Wolf King and his pack. Or maybe it’s another one, because not only have they walked miles and miles and left the “kill radius,” they’ve scaled a cliff separating them from the tundra.

Which brings us to the cliff scene. No, screw it. I can’t even try to back-project logic, physics, and continuity onto that sequence. There’s a cliff. They get down the cliff. They keep going. The wolves continue to attack. So apparently the wolves got down the cliff, too. Presumably also by jumping into trees and then climbing down them. Or maybe at the end they’re battling a different pack of shark-wolves.

But I’m going to assume they’re battling the same wolf pack and the same alpha Shark-Wolf. The movie doesn’t have the courage of its faux-Existentialist convictions to present “Well, actually it’s just shark-wolves all the way down.” No, no, there is an alpha Shark-Wolf King and eventually, eventually Liam must confront it.

Personally, I expected Liam to bottle-punch the Wolf King to death and then stand, bloodied and alone, in a ring of wolves who approach and slowly herd him into their den where they lick the blood off him and submit to him as the new Alpha Shark-Wolf. Now that would have been an ending.

But no. Cut to black, roll credits.

We don’t need to see the battle, apparently, because we already know all that we need to know: Liam has journeyed through the existential tundra and re-engaged with life. We know this because of the poem he recites before doing battle. “Just four lines,” he says. Written by his Da. Who stole the first line from Shakespeare and ran out of ideas on the third, so he just repeats it.

Once more into the fray.
Into the last good fight I’ll ever know.
Live and die on this day.
Live and die on this day.

What a piece of crap.

Devin says that “The Gray” is a movie to be compared to “Anaconda.” Slander. You want a poem? Here’s just an example of the treasures in Anaconda:

They strike, wrap around you;
Hold you tighter than
Your true love. And you
Get the privilege;
Of hearing your bones;
Break ‘fore the power;
Of the embrace;
Causes your veins to ‘xplode.

And that’s way before the Anaconda pukes up Jon Voigt whole. And you can be damn sure they didn’t show that in the trailer.

Reviewed 4 Stars: Lost at Sea, The Jon Ronson Mysteries

Lost At Sea: The Jon Ronson MysteriesLost At Sea: The Jon Ronson Mysteries by Jon Ronson
My rating: 4 of 5 stars

Highly recommended. Ronson returns to the form of “Them,” and “The Men Who Stare At Goats,” in this collection of humorous journalistic essays. His last book, “The Psychopath Test,” was a little one-note and more judgmental, while this collection travels broadly and shows Ronson in a variety of moods. Ronson’s best book remains “Them,” but I enjoyed every essay in “Lost at Sea.” An easy-to-read book with bite-sized essays perfect for the treadmill/exercycle.

View all my reviews

How does Ravelry make money?

Ravelry is a profitable 4-person company, a “lifestyle business”. This model is of little interest to venture capitalists but is, I think, very appealing to most people dreaming about their own business:

Unraveled » Blog Archive » How does Ravelry make money?.

Geek Cred Milestone: Stack Overflow Top 9%

div>