[x^2 for x in lst]

Many to many

2014-05-03

Igår lärde jag mig att Django-mongodb-engine som jag använder för att få Django:s ORM-verktyg att fungera med MongoDB inte stöder ManyToMany-fält.Jag vill ha ett sådant för att modellera kopplingen mellan BlogEntry och Category.Lösningen blev att spara ID:arna för de kategorier som ett BlogEntry tillhör i ett ListField(models.ForeignKey(Category)). Inte någon perfekt lösning direkt.Nu blir jag tvungen att manuellt hämta kategorierna som ett BlogEntry tillhör från databasen.

Tidsbaserade frågor

2014-05-05

Dagens lärdom: Django-mongodb-engine stöder inte tidsbaserade frågor. Ex hade det varit trevligt att kunna fråga efter alla BlogEntries som har gjorts en viss månad en visst år men det går inte :( Det finns tydligen ett projekt som heter Django-db-indexer som ger stöd för sådana frågor. Orkar dock inte strula med installation av ett extra projekt jut nu. Gör filtrering i kod än så länge. Inte roligt, men innan antalet inlägg blir så stort att det kommer att ta tid att loopa igenom inläggen kanske jag hinner dra in Django-db-indexer.

Känns som om det hade varit lättare att använda Postgres...men hade det varit lätt hade det inte varit någon sport ;)

Links not allowed in comments anymore

2015-05-19

I haven't worked on the actual blog application for almost a year now. Reading computer related books, writing blog entries about them and other topics and working on the math app has just taken too much time. I have a quite long list of things I want to change or add to the blog and I plan to start doing some of these changes in the next month. I'll just have to finish writing about the next language in the 14languages series (which is Scala).

Yesterday, however I became so fed up with the spam bots adding lots of spam comments to some of the entries in the blog so I implemented a small filter that disallows comments containing links. To do that I had to add one file containing exactly four lines of Python code and add validators=[validate_comment] to the CharField representing the text field where the comments are added. Ain't Python (and Django) wonderful ;)

Now there will be no more spam comments added. I hope. If some such comments somehow finds their way pass the filter, I'll have to tweak it to block those as well. We'll see how it goes.

The downside of this is of course that no real comments containing links can be added to the blog entries. That's too bad. Damn bots.

Blog restarted

2019-06-20

After having laid dormant for a couple of years, this blog has now been restarted. The previous version of the blog was written in Python/Django and was deployed on a server that a friend rented from a VPS company. When my friend stopped renting the server, I had no place to deploy the blog app and, to be honest, I did not have much time to invest in writing blog entries either.

A couple of months ago when I noticed that I had some more time on my hands (the kids are now a couple of years older and can take more care of themselves) I also realized that I missed writing reviews of the computer related books I read and to have somewhere to write down random programming stuff that I encountered when working with my small hobby projects. Therefore the idea of restarting the blog emerged.

The problem was that I still did not have any place to deploy the blog app. To use Wordpress or similar was out of the question. I wanted to write my own blog app. So what to do?

In recent years I've become more interested in the Go programming language. Not that I'd stopped liking Python, but I'd tried out Go and found it refreshingly simple. At least compared to Java, but that's not saying much. I'd also stated to use AWS more and more and I'd taken two AWS certifications (solution architect associate and developer associate). Why not try to combine my Go interest with my recently acquired AWS knowledge? Also, if I could use lambdas and DynamoDB configured for on-demand capacity, the cost of running the blog application would not be very great.

So I rewrote the blog application as an AWS lambda function and stored the texts for the blog entries, book reviews and so on in couple of DynamoDB tables.

The texts that were published on the previous version of the blog I had stored in a MongoDB database on my laptop. As I did not wish to "loose" those texts, I wrote some programs to read the texts from the local MongoDB database and insert them (after having made some conversions due to the fact that I'd changed the format of the datatypes slightly) into DynamoDB in the cloud. These programs I wrote in Python. I must say that Python is extremely nice to use for these kinds of work. It is *so* simple to write programs like that in Python and the programs become so small and easy to understand.

Anyway, the result of the new blog app is what you see right now.

In the process of rewriting the blog app to Go I stumbled over the book Web Design Playground (see review here). It's a fantastic book, and it made me rewrite the HTML for the site quite a bit. The site is still butt ugly, but at least the underlying code looks a bit better ;)

I might publish a blog entry about the architecture of the blog application. When I feel that the application is somewhere near finished, which make take a while...