Sunday, November 22, 2009

Sasktel’s service is great, it’s a shame their hardware isn’t so…

Guess what? It’s another rant! (I seem to be very good at these, for some reason).

Okay, so I’m a Sasktel subscriber here in Regina – That means I use their ADSL2e service for internet and TV, as they have a nifty IPTV network. The IPTV part I love, as it works a dream with my MythTV DVR, but the Router they provide (And that you HAVE to use – because of the way it handles DHCP assignments for the set-top boxes, and talking to the DSLAM, you have no other option), a 2-Wire unit customised (slightly) for them, is very poor. It doesn’t support UPNP for port allocation, not that it’s THAT much of an issue – If you have more than around 100 ports forwarded, it slows access to a crawl. The internal DHCP server and DNS forwarder also slow down within hours of rebooting, and stop working after a few days of uptime. If you change your network settings (or, indeed, the handed-out settings) to use the upstream DNS servers, things work fine, unless (of course) you need to connect a “new” machine to the network. Then, as the DHCP server is timing out every time, you can’t.

I have a second router (What I was using before I signed up for Sasktel) that I am more than pleased with – It’s a Belkin router that’s been hacked to run DD-WRT. That makes for a great router (With working UPNP and QoS), and it’s fast enough, and has enough RAM that there are rarely issues with internal servers dying. It can even make “Hotspot” systems with a little setting up, though I have no need of that functionality. But, because of the way things work, I can’t use it, so it’s next to useless, and after a few days running, so is this Sasktel unit.

Friday, November 13, 2009

Another rant… This time about WLW! (Updated!)

WLW being Windows Live Writer.

I’m not saying it’s bad (It’s actually rather good, IMHO), but there seems to be some kind of funky interaction between it and Blogger.

The source for a post, when it’s inside WLW looks like this:

<p>WLW being Windows Live Writer.</p>
<p>I’m not saying it’s bad (It’s actually rather good, IMHO), 
but there seems to be some kind of funky interaction between it and Blogger.</p>
<p>The source for a post, when it’s inside WLW looks like this:</p>

But, when it’s posted to blogger, it comes out like this:

<p>WLW being Windows Live Writer.</p>
<br />
<br />
<p>I’m not saying it’s bad (It’s actually rather good, IMHO), 
but there seems to be some kind of funky interaction between it and Blogger.</p>
<br />
<br />
<p>The source for a post, when it’s inside WLW looks like this:</p>

Obviously, this isn’t right. It looks like blogger is replacing every newline character with a <br /> and a newline. This would be fine if I was composing in plain text, but the editor I’m using is already doing the work at making sure everything is nicely XHTML formatted – I don’t need the extra newlines.

This was, for a while, making everything look FAR too spaced out, until I tweaked my CSS like so:

.post-body br {
   display: none;
}
.post-body p > br {
   display: auto;
}

What does this do?

It tells browsers to not display any “BR” elements inside the “.post-body” div, and then overrides that to say DO display “BR”s that are directly inside “P” (Paragraph) elements.

This fixes the problem, but I have a feeling I’m going about this the wrong way. Anyone out there use WLW with a similar problem? How did you fix it?

[Update] Well, I found the problem. Hidden deep within the settings of Blogger, there is the option “Convert Line Breaks” that defaults to “Yes”, with the description:

If Yes is selected, single hard-returns entered in the Post Editor will be replaced with single <br /> tags in your blog, and two hard-returns will be replaced with two tags (<br /><br />).

The wording of this implies it’s only going to do it for items posted through the Blogger “Post Editor”, but it seems this enables this behaviour everywhere, including through the Blogger API.

Now that this is switched off, everything looks just right again.

So, my apologies WLW, it wasn’t your fault at all. Blogger: What were you thinking?

Python didn’t have it, anyway…

Now, however, it does. Kinda.

def Python_to_XML_String(inst, name):
   builder = "<" + name + ">"
   builder += Python_to_XML_String_Recursion(inst)
   builder += "</" + name + ">"
   return minidom.parseString(builder)
   
def Python_to_XML_String_Recursion(inst):
   # Put entire object inside an elem w/ same name as the class.
   builder = ""
   for attr in inst:
      value = inst[attr]
      if type(value) == types.DictionaryType:
         # Recursively process subobjects
         builder += '<' + attr + '>'
         builder += Python_to_XML_String_Recursion(value)
         builder += '</' + attr + '>'
      elif type(value) == types.ListType:
         builder += '<' + attr + '>'
         for item in value:
            if type(item) == types.DictionaryType:
               builder += '<Item>'
               builder += Python_to_XML_String_Recursion(item)
               builder += '</Item>'
            else:
               builder += '<Item>'
               builder += str(item).replace("&","&amp;").replace("<","&lt;")
               builder += '</Item>'
         builder += '</' + attr + '>'
      else:
         # Convert anything else to string, put it in an element
         builder += '<' + attr + '>'
         builder += str(value).replace("&","&amp;").replace("<","&lt;")
         builder += '</' + attr + '>'
   return builder

(Note: I need a better source colouring plugin for WLW. Anyone know of one?)

This code is pretty limiting:

  • It’ll pretty much only work with generic type objects ({}, [] and primitives), but that’s all I need.
  • It also relies on the str() function to convert everything into a string, with no typing. This means that booleans (True, False) stay capitalised, which could cause some problems if your code is expecting lower-case values, and dates are unformatted.
  • It returns a minidom object (Which, obviously, has to be imported). You can output this with a .toxml() call.
  • It relies on the first object being passed in being a dictionary object, and that there will never be a list inside a list. This could be coded around, but it’ll take more work (and more helper functions, to fill in the “missing” information.
  • It takes an initial “name” argument to define the outer object.

To use it, call it like this:

Python_to_XML_String({'Thing': 'Value', 'Object', ['Thing 1', 'Thing 2']},'MyObject')

And it’ll return (for that example) an XML object looking like this:

<MyObject>
   <Thing>Value</Thing>
   <Object>
      <Item>Thing 1</Item>
      <Item>Thing 2</Item>
   </Object>
</MyObject>

I hope this is helpful to someone else out there…

Thursday, November 12, 2009

Wow. Python doesn’t have that? (Updated!)

This is going to be a rant, just so you are forewarned.

I have an object in Python that I’ve built that looks something like this:

Object = {
   'User': {
      'IsBanned': False, 
      'IsModerator': True, 
      'UserID': 'test@example.com', 
      'IsAdmin': True, 
      'LogoutURL': '/_ah/login?continue=http%3A//localhost%3A8080/CURRENT_URL&action=Logout', 
      'Location': u'Here.', 
      'Key': 'agVmb3J1bXIKCxIEVXNlchgCDA', 
      'UserLevel': 9L, 
      'NickName': u'Testing this works'
   }, 
   'Forum': [
      {
         'SubForums': [
            {
               'Threads': 0, 
               'Description': u'Test Three', 
               'Key': 'agVmb3J1bXILCxIFRm9ydW0YBQw', 
               'Title': u'Sub Forum'
            }
         ], 
         'Threads': 0, 
         'Description': u'Testing', 
         'Key': 'agVmb3J1bXILCxIFRm9ydW0YAww', 
         'Title': u'First Test'
      }, 
      {
         'Threads': 0, 
         'Description': u'Testing Two', 
         'Key': 'agVmb3J1bXILCxIFRm9ydW0YBAw', 
         'Title': u'Second Test'
      }, 
      {
         'SubForums': [
            {
               'SubForums': 
                  [
                     {'SubForums': 
                        [
                           {
                              'Threads': 0, 
                              'Description': u'Testing yet again', 
                              'Key': 'agVmb3J1bXILCxIFRm9ydW0YCQw', 
                              'Title': u'Another Forum'
                           }
                        ], 
                        'Threads': 0, 
                        'Description': u'Testing even more', 
                        'Key': 'agVmb3J1bXILCxIFRm9ydW0YCAw', 
                        'Title': u'Test Four'
                     }
                  ], 
                  'Threads': 0, 
                  'Description': u'Another test from JSON...', 
                  'Key': 'agVmb3J1bXILCxIFRm9ydW0YBww', 
                  'Title': u'Test Three'
               }
            ], 
            'Threads': 0, 
            'Description': u'Testing that JSON submitting a forum works...', 
            'Key': 'agVmb3J1bXILCxIFRm9ydW0YBgw', 
            'Title': u'test'
         }
      ]
   }

Taking advantage of the SimpleJSON library, I can serialise this into JSON with a single call. But I can’t find anything to serialise it into XML.

Well, technically speaking, I can. But all the libraries I have found want to do a LOT of massaging of the data structure, making it complex and unwieldy. What I want is a simple XML representation, like this:

<Object>
   <User>
      <IsBanned>False</IsBanned>
      <IsModerator>True</IsModerator>
      <UserID>test@example.com</UserID>
      <IsAdmin>True</IsAdmin>
      <LogoutURL>/_ah/login?continue=http%3A//localhost%3A8080/CURRENT_URL&action=Logout</LogoutURL>
      <Location>Here.</Location>
      <Key>agVmb3J1bXIKCxIEVXNlchgCDA</Key>
      <UserLevel>9</UserLevel>
      <NickName>Testing this works</NickName>
   </User>
   <Forum>
      <Item>
         <SubForums>
            <Item>
               <Threads>0</Thread>
               <Description>Test Three</Description>
               <Key>agVmb3J1bXILCxIFRm9ydW0YBQw</Key>
               <Title>Sub Forum</Title>
            </Item>
         </SubForums>
         <Threads>0</Threads>
         <Description>Testing</Description>
         <Key>agVmb3J1bXILCxIFRm9ydW0YAww</Key>
         <Title>First Test</Title>
      </Item>
      <Item>
         <Threads>0</Threads>
         <Description>Testing Two</Description>
         <Key>agVmb3J1bXILCxIFRm9ydW0YBAw</Key>
         <Title>Second Test</Title>
      </Item>
      <Item>
         <SubForums>
            <Item>
               <SubForums>
                  <Item>
                     <SubForums>
                        <Item>
                           <Threads>0</Threads>
                           <Description>Testing yet again</Description>
                           <Key>agVmb3J1bXILCxIFRm9ydW0YCQw</Key>
                           <Title>Another Forum</Title>
                        </Item>
                     </SubForums>
                     <Threads>0</Threads>
                     <Description>Testing even more</Description>
                     <Key>agVmb3J1bXILCxIFRm9ydW0YCAw</Key>
                     <Title>Test Four</Title>
                  </Item>
               </SubForums>
               <Threads>0</Threads>
               <Description>Another test from JSON...</Description>
               <Key>agVmb3J1bXILCxIFRm9ydW0YBww</Key>
               <Title>Test Three</Title>
            </Item>
         </SubForums>
         <Threads>0</Threads>
         <Description>Testing that JSON submitting a forum works...</Description>
         <Key>agVmb3J1bXILCxIFRm9ydW0YBgw</Key>
         <Title>test</Title>
      </Item>
   </Forum>
</Object>

It seems, however, that there is no Python library that can do that for me.

So why, I hear you asking, do I need such a thing?

Well, as you can probably tell from the listing(s) above, I’m writing an AJAX forum system. I’m doing it in Python so I can host it on Google App Engine (for free!), and can release it as open-source, but I’ve run into a pretty major snag.

I was using JSON to send data back and forth, which was working well. But I’ve found out that when you try and post using JSON to a different server (As the App Engine server will be, this is intended to be a “Widget” to use with Google Sites, among other things), an OPTIONS request is sent first to see if the cross-site request is allowed. I’ve grabbed the OPTIONS request, and replied with an “approved” message, but (even more to my consternation), the subsequent post from App Engine is empty. Oh, and cookies set before (on the GET) are not being sent with the POST, either. Thus I have decided to try switching to XML, and have run across the above roadblock.

I’m sure there are ways to do it, but searching across the ‘net has returned nothing. So I’m going to have to throw this open to the blogosphere, and hope something comes up. And soon.

[Update] As I found no-one had invented this particular wheel for me, I decided to roll my own, if you’ll excuse the pun(s).

Friday, July 17, 2009

What’s all the kerfuffle about “Universal Healthcare”?

Okay, I know I don’t post here often, but I have to say something here about this “Universal Healthcare” hoopla that’s going on in the US as they finally catch on to what the rest of the developed world has known for a LONG time now.

Universal Healthcare is a GOOD thing.

I will note here that my opinions here are primarily related to my experiences in the UK, under the NHS. That being said, let’s begin.

Everyone (And I do mean everyone) is eligible to receive care under the NHS. Poor? You’re covered. Student? You’re covered too. Unemployed? Yup, you’re fine. Working? Sure, you can still take advantage of the NHS. Multi-Millionaire? You can get it too. When we say “Universal”, we mean “Everyone”.

You want a doctor? Go pick one out of the phone book. Need to go to hospital? Call 999 (The UK equivalent of 911), and they’ll take you to the closest one, no charge. Need medicine? If it’s available OTC, just go to your local pharmacy and buy it. If it’s prescription only, go to your doctor. They’ll make sure you actually, medically, need it, and give you a scrip for it. Take that scrip to your pharmacy, pay £8.50 (Around $17), no matter what it is or how many there are, and pick up your drugs. Oh, and if you’re a full-time student, unemployed or retired, you pay nothing. Need to see the optician, or a dentist? That’ll set you back around £30 ($60), unless you’re a student, unemployed or retired, as above, then it’s free. Working with computers? Then your employer is legally required to pay for an eye check-up every 6 months. Need glasses? You can choose NHS-subsidised frames (Generally not the most stylish, but they will certainly do the job), or you can go with a brand-name pair, of which part of the cost may be subsidised.

If you have plenty of money, or if your employer offers it, you can (also) choose to have private medical insurance. So if you need a prescription and you’re working, the insurance takes care of it. If you need a procedure, and the wait time is too long on the NHS, you can choose to have the procedure done in a private hospital on your private medical insurance. And typically, if you elect to have a procedure on the NHS, the private insurance will pay you the equivalent of how much it would have cost to be treated privately.

Doctors on the NHS are incentivised to keep their patients healthy. They get a bonus for things like helping patients quit smoking. In fact, doctors are paid on the quality of life of their patients, not the turnover rate or the cost saved.

It does have to be said, waiting times on the NHS are longer for some non-critical procedures, but as you have the option of going private to avoid that queue, it is a reasonable choice, and certainly better than no care at all.

At no point have I ever had a bureaucrat say “No”. In fact, I have never been refused any kind of medical treatment on the NHS. I’ve never had to wait overlong for a procedure (though in fairness, I’ve never had a life-threatening ailment), and I’ve never had a problem with the care I received.

I know full well it was paid for from the income tax taken from my paycheque, but the amount was never onerous and never left me destitute, and wages were paid well in relation to the job done and the costs involved. Indeed, looking at US wages and the cost of US health plans, an equivalent health plan would cost many times the amount I was paying for the entirety of my income tax.

Universal Healthcare is not socialism, just as a universal police service, or universal fire coverage is not socialism, just like a universal civil defence force (the army/navy/marines/coastguard) is not socialism. It’s the fulfilment of a fundamental human right. It’s the very first one, in fact. “Life, liberty and the pursuit of happiness”. So, what’s the problem? And why don’t you have this already?

Friday, June 19, 2009

An opening post

I’ve already got an EV blog, but this one, I think, will be more personal, and/or perhaps related to other ideas that take my attention.

So, to start with, Audiobooks rock. I have an Audible account, but I’ve not bought anything from them for a LONG time. When I was living in Essex and working in London, commuting in by train, it was a very simple matter to load up my Diamond Rio 500 MP3 player (64MB storage! Supporting up to 256MB expansion via Smart Media card!), and listen to a book a week or so being read to me by talented readers, or indeed the author themselves, as I made the hour and a half commute into, and back from work each day.

Now, however, my Rio 500 is lost, along with the cables and the like for it even if I did have it, and I have no finances, nor particular “waste time” to spend listening to books on the go.

However, I have found I can listen to books when I have some downtime here. I can’t listen to books or podcasts and code at the same time (listening to the voice breaks my concentration, whereas music is more of a general surrounding that helps. Odd, I know.), but I can listen when I have to take a break for fresh eyes on a problem.

If I was working and commuting, perhaps I could justify an iPod of some description, or some other PMP that supports Audible format books. But I’m not working right now (Something to do with being an illegal alien), and even when I am working, commuting isn’t going to be that much of a problem, at least around Regina here. This city isn’t big enough to have a long commute to anywhere. Though I suppose if I got work in Moose Jaw, aside from having to have a car and a driver’s license, then I’d have a book-worthy commute.

So, that’s that. Not bad for an opening post, I suppose.