The OaF was originally inspired by the Ambient Orb, a nice little pager network driven indicator which gave the promise of telling you how things are going. It seems to me that it’s most successful application was in the power industry where companies issued them to consumers to help guide their power conservation efforts.

When I saw this in the early 2000s I had a different take on it. My thought was that I wanted one indicator that just said “everything is ok” maybe with a few other states like “your process is running,” “warning,” or “error.”  This required two features first a hierarchy of aggregated statuses so warnings could be overlapped and managed in terms of importance and second powerful networking support which I got from twisted.
Implementation wise OaF has support for inputs from web forms, xmlrpc, email monitoring, and http ping. Outputs include the original Ambient Orb, the system tray, Second Life objects, Arduino on the serial port, and a web page. At this point I’m releasing as is and will work on making sure all this works on the next pass.

  1. Grab the code from SVN and post it into GitHub:  DONE https://github.com/Ciemaar/oaf
  2. Write up an introductory blog post:  DONE, this post here.
  3. Make the code work:  IN PROGRESS, as posted it sort of works.
  4. Attach the code to Codacy to run analysis:  DELAYED, Codacy is asking for rights to all my repositories and I can’t give them.
  5. Build a deployment package of some sort:  IN PROGRESS, setup.py is included, but not fully tested.
  6. Put up another post here with more details and an open source license:  NOT STARTED

Long Delayed Releases

December 21, 2016

I’ve decided that it’s time, well past time to get a bunch of my old releases so, over the next few weeks I’m going to be going through some of my old code and just getting it out there.  I’m also going to be grabbing my old projects–even the unfinished and bad ideas–from SVN and dumping them into GitHub.  Here’s the process I plan to follow:

  1. Grab the code from SVN and post it into GitHub.  I’m not going to keep any history here, just check to make sure I’ve got the passwords out.  Moving passwords to config files is going to be the main part of my work.  At this point I won’t apply a proper open source license, but I’ll be glad to take requests if anyone sees a use for the code right away.
  2. Write up an introductory blog post here explaining what the code is supposed to be doing and why.
  3. Make the code work, in many cases this is very old code so it’ll have to account for new versions of twisted, Python, and webservices.
  4. Attach the code to Codacy to run analysis.
  5. Build a deployment package of some sort, probably pushing code to pypi and/or dockerhub.
  6. Put up another post here with more details and an open source license.

So, the next few posts on this blog should follow in this line–at least as much as I can over an otherwise plenty busy holiday.

porter-lounge-300x224

On my most recent flight back from Toronto I got to witness a modern airline functioning with none of their automated systems.  I was flying the generally excellent Porter Airlines when one of their vendors apparently did a mid-morning patch.  Of course it was not supposed to impact anything, but it did.

Continued on the Risk Focus Cloud Solutions Blog

Building on my thoughts from Handling Types in Python – Ignore it, Convert it, or Check it, I’m continuing to build up to my talk at PyCaribbean in Santa Domingo Dominican Republic. My title will be “Python: As much typing as you want,” obviously this means that I’ve been doing some thinking quite a bit about Python typing of late.

Previously I looked at the three basic strategies Python has for dealing with types; ignoring them, converting them, or checking types. All of these are very practical in their own right, but basically limited to working inside a given function call. However Python is an object oriented language and we do have the option to work with that and create an object attribute which has a type enforced on it.

Getters and Setters

Getters and setters are a common way to handle this. We could write these in Python, it would look something like this:

def get_age(self):
    return self.__age
def set_age(self, age):
    self.__age = int(age)
norm.set_age('23')
assert norm.get_age() == 23

Of course this is combining with a converting strategy to ensure that age is always an integer, set_age(‘Green’) will cause a ValueError, obviously we could do type check instead.

Properties via @property

Of course in Python we don’t do it that way. In Python we can create a property using the @property decorator like this:

@property
def name(self):
    return self.__dict__['name']
@name.setter
def name(self, value):
    self.__dict__['name'] = str(value)

norm.name = "Andy"
assert norm.name == "Andy"
norm.name = 42
assert norm.name == "42"

Again we can enforce any amount of typecasting either within the getter or the setter

Properties via property()

Since decorators were added to Python in 2.4 this has been by far the preferred way to declare properties. However, before decorators we already had properties the syntax we used then is still usable and for enforcing types it’s really handy. Combining our getter and setter from the age with the alternate syntax we can create an age property:

age = property(get_age,set_age)
norm.age = '28'
assert norm.age == 28

in and of itself the age property is like any other. This will however allow us to get some much better code reuse. Let’s assume we want to have a few properties with the same constraint, we’ll enforce them as Decimals so we can store money. Let’s write a function that creates a set of getter, setter, and deleter for this purpose:

def create_gsd_convert_Decimal(name):
   def getter(self):
       return self.__dict__[name]
   def setter(self, value):
       self.__dict__[name] = Decimal(value)
   def deleter(self):
       del self.__dict__[name]
   return getter, setter, deleter

now we can use it like this:

price = property(*create_gsd_convert_Decimal('price'))
price = 380.23
norm.price = price
assert isinstance(price, float)
assert not isinstance(price, Decimal)
assert isinstance(norm.price, Decimal)
assert not isinstance(norm.price, float)

using a function to return a tuple is a bit clunky, so lets clean that up a touch, I’ll continue to use the function creator function above adding only the call to property:

def enforce_Decimal(name):
   return property(*create_gsd_convert_Decimal(name))

much cleaner to use now

tax = enforce_Decimal('tax')

The interface here is pretty much as clean as it’s going to get without introducing a metaclass, but in my talk and a future blog post I’m going to explore how to use the descriptor protocol to simplify the mechanics behind this.

Next month I’ll be speaking about Python types at PyCaribbean in Santa Domingo Dominican Republic. My title will be “Python: As much typing as you want,” obviously this means that I’ve been doing some thinking quite a bit about Python typing of late.

Sometimes we think of Python and other scripting languages as devoid of types. Of course this is not true, almost every language since Assembly has included types to a greater or lesser extent. Even features like Perl’s coercion are just built on top of and intended to convert types—not based on ignoring types.

In the case of Python all of our variables are actually a single type, reference. They are all references to objects and those objects are typed. You can assign any reference to point to any object, but those objects have a class, which is their type and controls their behavior. You can see Python’s types at work if you do something like 2 + ‘2’ which of course equals TypeError. We can check the types with type(3j) or isinstance(42,(int,float)). But how do we deal with these types in Python? Python has 3 common strategies.

Ignore it

One very common strategy in Python is to leverage the fact that all of our variables are references, your code may not care what it was fed. If your code doesn’t do anything where the type matters maybe it doesn’t care. For example:

print(self.x)
print(self.right > self.left)
return pickle.dumps(self)

In all cases here it doesn’t matter what the type is: it will be printable, it will be comparable, it will be possible to turn it into a pickle.

Convert it

Our next strategy is to convert to the type we want, just to be sure that the type works as we need it to. This also has a few variations:

self.x = int(self.x)
self.array = list(seq_or_list)
self.value = value*1.0
return self.x * self.array

These techniques are often working on the convention that python constructors return a new object of the same type, making them safe to run on an object that’s already the right type.

Check it

A less favored strategy in Python is to check the type of data explicitly. We can of course do this, but this is by far not the norm. As soon as we start doing type checks—no matter how obvious the need—we break the Python norm of duck typing. Nonetheless there are a few cases where we do exactly this.

assert isinstance(self.x, str)
if not isinstance(self.left, self.right.__class__):
    raise TypeError('Left and right must be matching types')
if not all(isinstance(x, (str, int, float, bool, None)) for x in vals):
    raise TypeError('Unable to convert to json')
return 'OK'

Python is even doing this itself. Consider what happens in Python 3 when we compare two different types.

>>> 1 > ‘2’

Traceback (most recent call last):

File “<stdin>”, line 1, in <module>

TypeError: unorderable types: int() > str()

What else?

There is another category of techniques, more common to developers in other languages. We can convert or check the types when they are set as a field on an object. In other languages this would be getters and setters, but I’ll explore the Python equivalent in another post.

image

I finally got time to hack together the prototype for the class project for my class this weekend. We’re going to be using the RaspberryPi to connect to Plivo and make phone calls, nominally to our Mom’s. I thought one button was boring so our call Mom Button class will actually have 4 buttons suggested as:

* Call Mom
* Call Dad
* Text Mom “I love you”
* Mother’s day special

For more details or to sign up see Meetup.

Cross posted on MakerBar Blog.

Last January one of my friends, Bert Hartmann, approached me saying it was that it was time to finally found a Hackerspace in Hoboken.  He’d already gathered a half dozen people and thought I should be in on it.  Having been a long time admirer of hackerspaces without ever having one close enough to join I was in.

We met through the spring looking for how to do it, what to call it, where to put it, how long to wait,and how to do it legally..  There were a lot of options, the easiest of which would be to become a for profit company, that just doesn’t make any money–that would be really easy.  We are not doing that, instead a year later and with the MakerBar well established we are filing to become a true, legally recognized,  charitable educational organization. This will cost us about a thousand dollars in filing fees, but it’s the right thing to do legally and simplifies our future taxes and donations.  Still this is a thousand dollars we’d rather spend on new kits, power tools, publicity, and other things that support our mission and what’s worse it’s a thousand dollars we need now–before the taxes are due.

So we’re having a fundraiser.  We’ve teamed up with The Melting Pot in Hoboken to have a charity auction and happy hour.  We’ll be selling some projects that we’ve treasured through the year and some that we build specially for this event, sharing our love of hacking with the community, and enjoying a chocolate fondues contributed by the Melting Pot.

More details are on the the MakerBar Blog here and tickets are for sale on our Meetup here.