Wednesday, December 31, 2014

Swift File Manipulation

When you start writing in a new language it is always an adventure.

When your code starts to work it can be thrilling and when you can't seem to get something to work it can be very frustrating.

But as you dig in deeper there are occasions when you try to do something and it works, but you're not sure why.

This can happen when you start following advice but use Cargo Cult logic to find the "right" syntax.

This is exactly what I have done so far with Swift.

I found that it was difficult to get the answer to the question: how do I read & write to a file in the UNIX file system?

It actually took a considerable amount of digging and experimentation to accomplish what I take for granted as a very common thing that I do with perl, Java or Python on a daily basis.

That all being said I actually got it working on a rudimentary level.  I can read and write to a specific file in a predetermined location.

But that's all that I understand so far.  I very much feel like a neolithic man poking an obelisk from space with a bone since there is a LOT going on here that I do not understand.

You will note for example the use of dirs and dirz (distinct var names) which I resorted to while debugging example code from someone else.

So I figured that I would share my source code since this is just something I have running in a Playground file:

// Playground - noun: a place where people can play

import Cocoa

let file = "test.txt"

let dirs: [String]? = 
        true) as? [String]


if (dirs != nil) {
    let directories:[String] = dirs!

    let dirz = directories[0]
    let path = dirz.stringByAppendingPathComponent(file)
    println("I usually fiddle with this string to force a page recompile")
    var error:NSError?
    let readText = String(contentsOfFile: path, 
                          error: &error)
    if let theError = error {
    let text = readText! + 
               "this is added to the file every time we run\n"
                     atomically: false, 
                     encoding: NSUTF8StringEncoding, 
                     error: nil);

Tuesday, December 30, 2014

Swift Kick

I have been "tirekicking" Swift.

I have been using a loaner mac from work which somehow allowed me to download & install XCode without a Developer License.

So I have already written Swift code & created an OS/X application.  Whee!

That being said, I have begun to plumb the documentation & learn some syntax.

I hate to admit it but I'm starting to like it.

They have successfully lifted many of the best features of Python, Java and C#.  I actually find the -> notation used to denote a function's output somewhat elegant.

It tickles that literature-minded-Unix-geek nerve just the right way.

So I have XCode, which is a utlititarian bear, to build my apps for me & I have a REPL interface now, in the form of the "playground".

Once thing about playgrounds that it actually very nice is that you can save them as-is & share them with each other as documentation with the added ability to play with the examples right there in front of you.

I still have a LOT to learn - not the least of which is my way around the supporting libraries.

But one thing at a time...

Monday, December 29, 2014

Not Too Swift

I am an idiot.

After programming for >32 years I have become rigid in my pattern of thinking.

I had reservations about Objective C and I stupidly assumed that everyone else would too.

Now that's over.  So the dusty books I bought planning to learn that language will now be a Bridge Too Far and a bitter reminder of what might have been.

But here's the thing:

This Swift nonsense really rubs me the wrong way.  Apple is going out of their way to behave badly.  Just as .NET was only ever intended to run on the Windows platform Swift, by design, only runs on iOS and OS/X.  (And of those, only on the Post-Steve flavors)

Being a parent, I digest news at the Speed of Dark.  So it took me - what has it been, 6 months? - to even notice Swift.  By then all of the hype-cycle analysis should have boiled down to a more reasonable level... "should have"..

Just like everything else there is no online debate.  You are either a zealot or a hater.  No one has time for wishy-washy-fence-sitters.  In the public space of opinions you are All-In or you have no peer group.  Any sort of "debate" is really just the two main camps lobbing petrol-bomb-grade-hyperbole at each other.  There's nothing worthwhile to be learned.

So after having an even stronger visceral reaction than last time I asked myself if I was making the same mistake.  The honest answer I gave myself was "Probably".

So this presents a problem.  I don't have a new mac.  I don't have a new iPhone nor iPad.  All of my gear is roughly 4 years old & thus has fallen off of the supported platform.  The OS/X version that I run at home is four major revisions out of date.  (Because I got sick of chasing the upgrade dragon & froze everything in a working state)

So even if I wanted  to program in Swift - WTF am I going to use?  I would have to do what Apple wants you to do - go out & buy all new stuff...

So I'm learning Swift now - with nothing to run it on. 

And I'm looking into buying a new laptop...

Like I said, I am an idiot.

Monday, September 15, 2014

Flooding the Market

Now that the Raspberry Pi has created a loyal following & the market is thriving, a number of other players have been introducing new products.

So far there is only one that has stood out - and I would like to tell you about it - but apparently that is all that I can do.
For some reason they have this absolutely crazy Intellectual Property policy that doesn't even allow people to link to their site.  Since this is completely unenforceable and insane, here is a link to that policy which would seem to be included in the list of things to which I am not allowed to link.

The product line is called Udoo.  I can't show you a picture or provide you a link so I will have to just create a workaround

What is interesting about Udoo is that they have a quad-core version that comes with an embedded Arduinio chipset and has gigabit ethernet.  While it might cost as much as 3 Beaglebone Blacks - in terms of value for money - they are densely packed.

However the one thing that really kills it for me is that it is not an open source design.  Given their inherent attitude about Intellectual Property for simple information on a web site, I can't say that I trust them to 'do the right thing' by their customer-base.  For that reason, I am still focusing on the BeagleBoneBlackRevC for my server farm design.

Given that the Arduino itself is a proprietary platform - it should come as no surprise.

If anyone out there responds to wishes as design challenges then I wish I wish I wish for 2 BeagleBoard capes to Come To Be:
1. Gigabit Ethernet
2. A cape devoted to mounting an Arduino as a daughterboard - thus isolating the proprietary components from the rest of the design.

Having those would make any call for the Udoo unnecessary.

Friday, September 12, 2014

Fun with BeagleBone Black revC

This is a picture of my BeagleBone Black revC.

I included a nickel & a sharpie for scale.

There's probably ~$100 of Adafruit gear there including the BBB itself, miniHDMI-HDMI adapter cable, the miniUSB-USB cable, the case, the USB flash programming cable, the microSD & SD card adapter and the 5v2A DC power supply.

But another way to look at this is to round it up to $60.  I will do that because if you were to get 10 of these & connect a network switch, that would probably be about $600.

Now let's assume that we have 10 in a row all connected up.  Now let's add 9 more rows.  We are in about $6,000 now and we have network backbone and power distribution hardware in place.

Now, mount that in a rack cabinet as a tray....and build 9 more such trays.  We will need more power management, cable routing guides, and further network switching.

But now we are looking at a fully populated rack cabinet in a data center that contains 1,000 core processors & ~4Tb of flash RAM at a price of ~US$60,000.

Mind you - there are serious problems with this plan:
1. You currently can't buy >1 BBBrevC at a time due to supply constraints
2. BBBrevC has 100BaseT networking
3. All of the breakout headers and microHDMI ports will go unused
4. 4Gb flash RAM per unit - hard limit
5. There are no standard racks for any of this, so they will have to be custom fabricated.
6. Power distribution to 1,000 components will be a Challenge.
7. Will only run applications that can compile on ARM processors

However, there are benefits also:
1. Zero Noise - with no moving parts the entire enclosure is silent.
2. Less power consumption - 5v ~200mA each
3. Less heat generated - with little power consumed, not much to convert to heat.  On board LED's can be disabled to further reduce consumption/heat generated.
4. Very low component cost - a unit actually fails?  Throw it away & replace it!
5. Open Source Software - zero licensing costs
6. Open Source Hardware - when you can no longer buy them - you can send out & have them fabricated for you

When you look at what Google is doing in their own data centers now, this makes more & more sense.

Wednesday, September 3, 2014

Ride the snake!

As previously mentioned on ye-olde-blog, I am tripping-the-n00b-fantasic on Python.

And just to keep things fresh-n-funky and to prove that I have completely lost my mind I have even set up a GitHub account.

Stick a fork in me or something before I hurt myself.

In the meantime I find that as a programmer fluent in both Java and perl when I muck about with Python it all looks familiar, just with a really relaxed attitude..  (Though I suspect code style is a Shibboleth) 

To be honest, as I have said before, I just wish there were a lot more actual Monty Python references.

All of this being said - there are reasons why I am delving into all of this nonsensical whimsy.  Many of them will become more obvious soon I think.

Old Fashioned But New ~ Welcome!

So here we are again.

This is a not-so brand-new blog.

The short story is that I use gregor42 all over the place & have for entirely too long.

In the past I tried to secure this name and failed.  Things changed, it became available and I eventually noticed.

So here I am!  And here I will stay..

... at least until I find a home on anyway