johnk's blog

Web API Design book I'm reading

This is a few years old, but it's a good overview of APIs and some good design patterns. There's a signup page.

Web API Design - Crafting Interfaces that Developers Love

It's good advice and easy reading, but there's what I consider an error in there. Over on page 26, they suggest that it's OK to make a request like "GET /foo/123?method=delete" that will delete the resource.

Django error: Reverse for 'some-name' with arguments '(1,)' and keyword arguments '{}' not found. 0 pattern(s) tried: []

A nice feature of the URL matching rules is that even if you have named arguments in the url(), like so:

 url(r'^items/(?P<pk>[0-9]+)/$', ItemDetailView.as_view(), name='item_detail'),

the system will accept a positional parameter, like so:

{% url 'item_detail' %}

I was thinking that it was going to be particular about named parameters, and I was searching for information about passing named parameters to url, but it wasn't necessary. Once again, misdirected by an error message.

Python Performance Rabbithole

I was looking for Django podcasts, and being that it's a community within a community found only a couple, and they were both not in operation anymore. I started to worry - was the project waning? It looked like updates and significant improvements were coming out at a fast pace.

Was Node taking over? I had to "research". Off to craigslist - nope. Node is popular, but there are still plenty of references to Django.... more actually. Then, I started to worry about whether nonblocking I/O was an issue - I know all the big, intepreted app servers like Django and ROR are slow - but really?

DIY Fixing ic! Berlin glasses if you sat or stepped on them

So, when I had some money, I blew it on these "designer" ic! Berlin frames. They look really high tech and cool, and they allegedly avoid damage by having these hinges that pop apart under pressure.

Here's a video of how it's supposed to work:

Here's another one:

Too bad the ones I got don't actually pop apart under pressure. I'll explain how to fix them in this blog post.

def fn(arg1,x=arg2,y=10,*args,**kwargs): GO PYTHON!

def fn(arg1,x=arg2,y=10,*args,**kwargs):

That's kind of ugly, but the design is elegant. With that declaration, the function supports positional arguments, required named arguments, optional arguments, an arbitrary number of additional unnamed arguments, and additional arbitrary named arguments.

It allows function calls to be simpler and more readable than they would be without this flexibility.

Metro PCS contract, and an opt-out letter to preserve your right to a court trial.

I was getting an annoying update of the Metro PCS contract, and ended up reading it. Attached is a marked-up contract with interesting parts highlighted. The plain contract is available on their website - this is highlighted as a kind of commentary.

The most irritating part is where the company forces you into arbitration, and then into relinquishing a trial by jury. While I'm not that opposed to arbitration, it is not nice to give up the right to be seen in court.

Open Source as Marketing for SAAS

Probably not news to anyone, but the idea is that you run a hosting company that offers a specific hosted software, and also hires out people to modify the software. Then, you give some of the software away - the most feature rich part generally - as bait. Developers sell these features to clients. They find they cannot really charge what they need to for hosting, because it takes time to keep the software up-to-date and also to modify their add-ons to work with the changes, and also deal with security. They end up re-selling the hosting services.

Django URL Namespaces and Templates... kind of not pretty

So, I shouldn't admit it, but I'm a Django beginner. (I've done a lot of other frameworks, but Django is new to me.) It has a really nice feature to write URLs for you; you don't code URLs into the pages, but use a name to find a URL's associated pattern, and generate based on the pattern. It's really nice.

Python Operator Overloading

I was reading up on Django F() and Q(). I didn't know Python had operator overloading. They call it magic methods.

Magic Methods on Rafe Kettler

There's a pretty good tutorial at Treehouse.

But... a few memories of arguments about operator overloading surfaced, so I had to think about why Java rejected adding the feature to Java.

Are Doctests in Django 1.8 Failing to Run?

I don't know what's up, but I ran some old examples, and it looks like doctests aren't running when I do the " test" (or the one with a settings file).

Encrypted Data

--- This message has been encrypted using eComm Mozilla Firefox Extension
--- You need to have this extension installed in your browser to decrypt it


--- End of Encrypted Message


Manos procural iniquity scum detrital. Daces hopping snowcap. Recency
mystics, solvers miscuing. Rassling, rousseau, ruers kinglier musers

CORS, Angular JS, and, together, didn't let me login twice.

Things were going well with a re-architecting and re-factoring of a service to use Angular's awesome $request, and Django REST Frameworks' awesome ModelViewSet generics. As usual, when things are chugging along, you come across a weird bug that just sucks you in for a while. The bug I hit today involved CORS, AngularJS, and Parse (we're using Parse for part of our backend).

The symptom was that, if I logged in once, then logged out, I could not log in again. I could reach the server, but it wouldn't let me do the exact same thing I'd done just 30 seconds before.

Should Javascript Code Blocks be Delimited with Parentheses?

This is some some random thought I had.

I'm annoyed that I often need to terminate with this "})".

It would be easier, in some editors, to terminte with "))", because the editor will show you the matching parentheses.

Let's see:

function z(x)(return x+x;)
applying(a, function(x)(return x+x;));
var z = generate_function(function(x)(return x+y;), y);
if (x==y) (return x+y;) else (return false;)
for(var i=0;i<x.length;i++) (document.write(i))

Maybe it would work.

Adding Custom Fields to a Database Table

I was watching and OpenERP/Odoo video, and the demo showed custom fields being added.

My first thought was, "uh, I hope it's not implemented as a generalized database system written using a database as its platform."

I guess I could go read the code.

Then I started to think about using a NoSQL database to achieve that flexibility. NoSQL is schemaless, so being able to add fields is simple and not ugly. The tradeoff is that it's not relational - a huge tradeoff.

Hating on HATEOAS a little bit, thinking about it a lot

I've been thinking about how to enable HATEOAS on this web app, and it is a mind-bender. Django isn't quite up to it - but it does have a key feature of named links and URL generation that seems like a requirement for HATEOAS. To do HATEOAS, links need to be elevated to a higher status in the system.

For one, on the web, links are very different from the way software internals are organized. In software, and also in URLs, we have hierarchies: paths to files, paths to APIs, hierarchies of objects, and nested data structures.

Syndicate content