| Andrew Cooke | Contents | RSS | Twitter | Previous
Welcome to my blog, which was once a mailing list of the same name and is still generated by mail. Please reply via the "comment" links.
Always interested in offers/projects/new ideas. Eclectic experience in fields like: numerical computing; Python web; Java enterprise; functional languages; GPGPU; SQL databases; etc. Based in Santiago, Chile; telecommute worldwide. CV; email.
Lepl parser for Python.
Photography around Santiago.
SVG experiment.
Calibration of seismometers.
Data access via web services.
Cache rewrite.
Extending OpenSSH.
Wiggle The Mouse To Pass The Test
Python Enums on Crack, Part II
Those little tab things on the side of jet engines
Printing binary trees sideways
Python's sad, unimaginative Enum
VirtualBox with Centos 6.3 to 6.4, client
Matasano - Programming Lessons Learned
Using Coroutines In Protocol Simulations
Pure Python SHA1 and MD4 Implementations
The back-wards compatibility fallacy
Re: Python's sad, unimaginative Enum
© 2006-2013 Andrew Cooke (site) / post authors (content).
From: andrew cooke <andrew@...>
Date: Fri, 7 Jun 2013 18:28:21 -0400
The Verizon order requested "information on all calls" - basically, all metadata (not voice records). http://www.guardian.co.uk/world/2013/jun/06/nsa-phone-records-verizon-court-order Denials from Google and Facebook are, presumably, worded very carefully to present the best possible version while remaining "legally true". They admit to complying with "legal requests" but deny "direct access" (that exact phrase is common to both below) or requests on the scale of the Verizon order. https://www.facebook.com/zuck/posts/10100828955847631 http://googleblog.blogspot.com/2013/06/what.html But if the NSA only requries metadata then they don't need to demand direct access from Facebook or Google. It's sufficient to use the data from ISPs (like Verizon). In fact, it would be pointless - they would simply be duplicating data. Traffic analysis (which seems to be what Prism is) does not require the cooperation of the companies that provide the endpoints. Because of the way the internet works, it's sufficient to take the information from the people who connect the servers to the clients. Now things may be complicated by big companies like Google owning their own CDNs, but it's not clear to me that invalidates the general argument (the NSA still know if someone is "connecting to Google", no matter which of Google's endpoints they use). After doing traffic analysis, the NSA will presumably want to investigate some conversations in more depth. And that will be done in a manner consistent with the statements by Google, Facebook et al - legal, targetted requests. This is consistent with the different historical attitudes from the two industries. Remember how AT&T bent over backwards to support monitoring, while Google and Twitter have a good record of questioning and resisting requests. BUT it doesn't convincingly explain this http://cdn.theatlantic.com/static/mt/assets/science/assets_c/2013/06/prism-slide-5-thumb-570x427-123899.jpg (you'd have to argue that this diagram is simply showing when they started making the legal requests; it seems to be claiming something more). Andrew
From: andrew cooke <andrew@...>
Date: Fri, 7 Jun 2013 20:02:39 -0400
http://www.dailydot.com/news/how-prism-works-fisa-courts-nsa/ Andrew
From: andrew cooke <andrew@...>
Date: Fri, 7 Jun 2013 22:33:50 -0400
The suggestion here https://plus.google.com/+YonatanZunger/posts/huwQsphBron (search for "suspicions") seems to be that NSA are advertising (and providing) low cost routes for data. Credit https://news.ycombinator.com/item?id=5843380 Andrew
From: andrew cooke <andrew@...>
Date: Fri, 7 Jun 2013 22:34:57 -0400
So when did Google introduce SSL? And how much do we trust that? Andrew
From: andrew cooke <andrew@...>
Date: Fri, 7 Jun 2013 23:40:34 -0400
More details starting to emerge about how the companies co-operated to streamline targetted requests (as suggested by the dailydot link above; nothing to do with the low cost route idea). http://www.nytimes.com/2013/06/08/technology/tech-companies-bristling-concede-to-government-surveillance-efforts.html?_r=0 Andrew
Permalink | Comment on this post
For comments, see relevant pages (permalinks).
From: andrew cooke <andrew@...>
Date: Wed, 5 Jun 2013 21:40:39 -0400
http://www.last.fm/about/jobs - 3 positions. I had assumed for some time they were dying. I guess not? Cool. Andrew
From: andrew cooke <andrew@...>
Date: Wed, 5 Jun 2013 19:44:09 -0400
[Mainly a personal note, on MS. Please skip...] This is a follow-up to http://www.acooke.org/cute/HowIAm0.html - every 3 months I am planning to record my current state. Now 7 months from being diagnosed, 6 months on Betaferon, and 4.5 months since the last corticoids wore off (so 4.5 months when I could have had an outbreak, but apparently haven't). So, where am I now? The right hand is significantly better (it improved in the last month). It still has PN (pins + needles) when I touch something, but I can kind-of sense textures. There's much less pain on a morning and it's not as stiff. Left hand as before - almost normal, some PN in two fingers. Below the ribs I very rarely have PN now, and the discomfort when lying on my front is less. But the "affected zone" seems to have moved upwards (or perhaps this is additional damage from the second outbreak) - I have felt some PN under my chest muscles a couple of times. Indigestion gone; anus AOK. Legs are strange, in that they are generally fine for walking, but continued to have issues as different nerves / muscles fix themselves (see below). I had no idea there was so much damage (so many different places). A major breakthrough happened a few weeks ago, that I guess is somehow leg-related - I was able to run for more than 15 minutes - http://www.acooke.org/cute/ImaMACHIII0.html . But I can still feel "sausages" in my thighs when I lie face down on the bed, so there is more to fix. There's a patch of mild, permanent PN underneath my left foot! My back no longer has "sausages" (and I seem to be able to feel things like the rattanwork chair), but often has muscle aches. The sides can be uncomfortable to lie on, but that seems to be getting better. Sometimes I can raise my arms fully (eg washing hair) with no issues; other times it feels restricted or aches. My understanding of what is happening in my body hasn't really changed. The re-mylinization appears to be cyclical, with a period of 3 days - 2 weeks, so I have a series of good days or bad days (time in Europe was good, thankfully). On good days, pretty much everything is OK except for some random PN and the right hand. On bad days I have "exploding head" and muscular aches and/or twitching muscles. Twitching is very small scale and not at all a problem. Feels quite reassuring actually - that something is getting better. I am not taking Ibuprofen (second Dr was pretty surprised by how much I was knocking back when I went for tge GES-related 6 month check) and no longer seem to need it anyway (except one pill on injection nights to avoid fever). Today I went to see the main Dr. He was happy with everything (I felt like I was presenting a successful science project at school!). I have prescriptions for two MRIs (neck and head) in case there's asymptomatic damage and he suggests that I use the MRI at Davila rather than Integra Medica (both much cheaper for me than Clinica Alemana - at Davila I could even use GES). OK, end of brain dump. Hello to future self. Keep on rockin' Andrew
From: andrew cooke <andrew@...>
Date: Tue, 4 Jun 2013 09:26:23 -0400
I should have guessed why, but I didn't. Can you? http://blog.existentialize.com/wiggle-the-mouse-to-fix-the-test.html Andrew
From: andrew cooke <andrew@...>
Date: Tue, 4 Jun 2013 08:50:28 -0400
Just under a month ago I wrote a disappointed rant[1] about the new Enum for
Python 3.
Since then I spent time extending the existing code[2] (to produce bnum[3]),
before changing direction and writing my own, alternative Enum from
scratch[4]. I've also swapped a few emails with various kind people.
While all that doesn't make me an expert, I do now have a better understanding
of the design and some of the choices it embodies. So I thought I'd revisit
the points I made earlier and try explain why things work that way, where I
can, and what space for change still remains.
Implicit Values
---------------
In the original article I said that my first example -
class Colour(Enum):
red
green
- was illegal syntax. I was wrong.
When Python parses the class definition it looks for values in the dict of the
class that it is building. Python 3's metaclass protocol allows us to provide
that dict, so we can use a subclass that assigns default values to unknown
names (and provide values from 'red' and 'green' instead of triggering an
error).
I use this trick in simple-enum[4], and the above is a valid declaration when
using that package. But it's not a risk-free solution: there's the
possibility of very confusing errors / bugs.
The problem is that elsewhere in the code we may refer to a name in the global
scope. The class dict will, incorrectly, provide a default value for that
name too. And while you can reduce the effect[5], I am not (yet) convinced
that you can remove the risk entirely.
Implicit Values 2 (Strange Syntaxes)
------------------------------------
But all is not lost. The PEP 0435 test code includes support for:
class Colour(Enum):
red = ...
green = ...
which, although uglier, avoids the issues with "magic values". This is not in
the default implementation, but it can be added by providing an alternate
metaclass).
Duplicate Values
----------------
Python 3's metaclass support includes keyword arguments. Here's an example
from simple-enum:
class WithAliases(Enum, implicit=False, allow_aliases=True):
one = 1
another_one = 1
Please ignore the 'implicit=False' (it does what you'd expect; it's needed
because of the shadowing issue I discussed earlier) - I am showing this
example because the 'allow_aliases' flag seems like a good solution to whether
or not duplicate values should be flagged: duplicates are errors by default,
but can be enabled if required.
Unfortunately I don't see anything likle this in the PEP 0345 code. There's
no such flag (no metaclass keyword args are used at all) and no related tests.
But it is fairly easy to add - I included it in bnum[3].
Inheritance
-----------
The PEP Enum code is complicated by the need to support inheritance -
something that is used mainly (in the tests) to allow Enums to "be" integers.
In case the above is not clear, this is valid with PEP 0435:
# PEP 0435
class Number(int, Enum):
one = 1
two = 2
> Number.one + Number.two
3
> isinstance(Number.one, Number)
True
> isinstance(Number.one, int)
True
In contrast, the simple-enum implementation is, well, simpler, treating all
enumerations as named tuples (with name and value components), so equivalent
code would read:
# simple-enum
> Number.one.value + Number.two.value
3
Now, after that long introduction, the question is: why does PEP 0435 have
this emphasis? I chose the simple (but more verbose) solution because it
seemed easier to understand, simplified the implementation, and allowed me to
present enumerations in terms of both dicts and tuples (something I haven't
explained here, since I'm focussing on PEP 0435, but see [4] if you're
curious).
Nick Coghlan explained this to me, and it shone a completely new light on the
design: the PEP is designed to be backwards compatible with existing Python
library code.
For example, the socket module is full of constants like TIPC_ADDR_NAME and
AF_BLUETOOTH. Existing code *expects* them to evaluate to whatever their
current value is. Changing all that existing code to TIPC_ADDR_NAME.value is
impossible. So the PEP Enum *must* "be" an int (or a str, or whatever the
original design chose) if these constants are going to be replaced by Enums.
Hence the inheritance.
Alternate Implcit Values
------------------------
I mentioned this in my rant, and support it in simple-enum with metaclass
keyword arguments (eg. 'values=from_zero'), but implicit values currently play
a very small part in the PEP 0435 Enum (they are available only through the
"functional API").
Language Changes
----------------
While the "names in a class" syntax is possible, it's something of a hack (see
above). Since support for such a syntax might also help named tuples it's
interesting to ask whether the language could be extended in some way to
support this. I don't have a concrete suggestion, but it seems like an
interesting avenue to explore.
A simpler change, which I stumbled across while considering alternatives, is
to extend matching to infinite sequences. This would allow a syntax like:
class SequenceBased(Enum):
one, two, three, ... = count()
Summary
-------
Much of the design of the PEP 0435 Enum is driven by the requirement that it
be applied retroactively to existing classes (without changing existing code).
Honestly, to me, that seems a bit "too clever", but I understand the
temptation.
The "clean" syntax (names in a class) is possible in Python, but concerns
about opaque errors / bugs from name shadowing have excluded it from the PEP.
Alternative syntaxes (like 'name = ...') exist in the tests, but are not
enabled by default.
Duplicate values could be enabled by a named argument to the metaclass. I
don't understand why this issue is missing from the code (even in the tests,
which otherwise do a good job of exploring alternative ideas).
[1] rant - http://www.acooke.org/cute/Pythonssad0.html
[2] PEP 0435 code - https://bitbucket.org/stoneleaf/ref435
[3] mod of [2] - https://github.com/andrewcooke/bnum
[4] new start - https://github.com/andrewcooke/simple-enum
[5] magic values - https://github.com/andrewcooke/simple-enum#the-danger-of-magic
From: andrew cooke <andrew@...>
Date: Sun, 2 Jun 2013 23:06:24 -0400
This may be obvious to everyone else, but it wasn't to me: graphics cards handle multiple monitors by TIME-SLICING. So you don't need to worry about the available resolution being enough to cover the "sum" of all displays. This is particularly non-obvious with the KDE config tool - at least the version in an old OpenSuse 12.1 that I was using this evening. For some reason, that defaults to configuring both monitors at absolute positions. YOU DO NOT WANT ABSOLUTE POSITIONS because that implies constructing a single display and then "windowing" each monitor onto that. Instead, configure one display to be RELATIVE (left or right, probably) to the other. Then you get time-slicing. Another way of saying the same thing: If you are not concerned about frame rates (ie if you are not playing games) then a graphic card will support as many monitors as it has outputs, providing no single monitor exceeds the supported resolution. Because it generates the display for each monitor in turn (provided the positions are relative). Anyway, Paulina now has a very nice pair of HD IPS monitors running off a pretty ancient Nvidia (static cooled) card.... Yay. Andrew
From: andrew cooke <andrew@...>
Date: Sun, 2 Jun 2013 21:46:22 -0400
Good general explanation (much more than just teh social media angle) http://technosociology.org/?p=1255 Andrew
From: andrew cooke <andrew@...>
Date: Sun, 2 Jun 2013 00:23:27 -0400
After 3 weeks I gave up on the better enum and decided to write a simpler version. Which took a day. https://github.com/andrewcooke/simple-enum Tomorrow I hope to document the code and publish on PyPI, but it's a busy day, so I may run out of time... Andrew
From: andrew cooke <andrew@...>
Date: Wed, 29 May 2013 18:10:24 -0400
This just way better than normal for Reddit + famous people - http://www.reddit.com/r/IAmA/comments/1fa3ed/i_am_john_fogerty_singer_songwriter_and_former/ Andrew
From: andrew cooke <andrew@...>
Date: Tue, 28 May 2013 21:20:09 -0400
i am not completely sure i know what i am doing - blundering around
metaclasses and protocols, breaking things everywhere - but i just got the
following tests to run:
class QuickStartTest(TestCase):
def test_colour(self):
class Colour(ImplicitBnum):
red
green
blue
assert Colour.red != Colour.blue
assert Colour.red == Colour.red
assert isinstance(Colour.red, Colour), type(Colour.red)
assert Colour.red.name == 'red', Colour.red.name
assert str(Colour.red) == 'red'
assert repr(Colour.red) == "Colour('red')", repr(Colour.red)
assert str(list(map(str, Colour))) == "['blue', 'green', 'red']",
str(list(map(str, Colour)))
assert Colour.red in Colour
def test_number(self):
class Number(int, ExplicitBnum, values=from_one):
with implicit:
one
two
three = one + two
assert isinstance(Number.two, int), type(Number.two)
assert Number.three == 3, Number.three
assert repr(Number.three) == "Number(value=3, name='three')"
(and all credit to ethan furman - i would be nowhere without his code to
modify).
andrew
From: andrew cooke <andrew@...>
Date: Sun, 26 May 2013 18:52:10 -0400
A fucking running machine! For the last couple of months I've been hitting a wall after just 15min running. I've been running (or jogging) for over half my life, and I am pretty sure I know myself - that wall was something else. That something being, of course, MS. But the last few weeks I've had weird shit in my thighs and backside - pains and twitching muscles - that I have learnt to interpret as recovering nerves. And, finally, it seems to be paying off. The last few runs didn't end with the same strange feeling of complete exhaustion (not unlike the feeling that forces me to nap at random times). So today I increased my distance by a block... ...no problemo :o) OK, a block may not seem much, but after months of being stuck, it's a sign. Yay. Andrew
From: andrew cooke <andrew@...>
Date: Fri, 24 May 2013 20:25:10 -0400
Maybe you've not noticed, but turbofans have a little winglet thing on the side nearest the fuselage. Here's a picture: http://farm6.staticflickr.com/5165/5299645391_afdc8004a4.jpg It turns out that these things are called "nacelle strakes" (and "jet engines" are turbofans). They're needed because at low speeds and high angles of attack the engine gets in the way of the airflow over the wing. These make a vortex that helps keep the air "stuck" and avoids stalling. More here: http://www.airliners.net/aviation-forums/tech_ops/read.main/271056 And yes, that took me about an hour of googling... next, is it true that windows directly aligned with the turbofan blades are blocked off to avoid dead passangers if it flies apart? It certainly seems like that in several planes I used last week... Andrew