Run Celery 4.1.0 on Windows 10

Posted by in Software, Tutorial

TL;DR: Use set FORKED_BY_MULTIPROCESSING=1 on the worker script/shell When running Celery on Windows 10, I got the following error: ValueError: not enough values to unpack (expected 3, got 0) This is quite unfortunate as Windows is supported on “best effort”. A pull request has a change, but it’s not pretty to patch an installation. To get around, you can just define an environment variable:

I only defined it on the worker’s side. HTH, A little experiment: If you find this post and ad below useful, please check the ad…read more

Use Docker Behind Proxy on Windows 8

Posted by in Software, Tutorial

The other day I had to install Docker at work, aka behind a corporate proxy (on Windows 8). While the docker installer is stand-alone and all is good, dealing with the VM is a different matter… The problem popped up when I tried to create a Django image and pip install failed miserably. To get around, you need to create a docker machine:

You also need to pass in the proxy as a build argument to build:

You can also pass the build argument to docker-compose but, in…read more

Convert Timestamp to DateTime for Pandas DataFrame

Posted by in Software, Tutorial

To convert a pandas data frame value from unix timestamp to python datetime you need to use:

where: timestamp is the column containing the timestamp value unit=’s’ defines the unit of the timestamp (seconds in this case) You can actually replace the column altogether:

Unfortunately, the conversion is not really aware of the time zone so, if you want to e.g. create a django module, you’ll need to make the datetime object aware:

Moreover, if you want to change to another timezone, you’ll need to:

A…read more

Save Pandas DataFrame as Django Model

Posted by in Software, Tutorial

TL;DR: use bulk_upload coupled with a comprehension to speed up loading. Initially, I started to convert the data frame to a Model object row by row and save it. While easy, it’s also arguably the slowest method to load records, because the save() call performs a commit. Then I looked up how to save pandas data frames and I found out quite a few ways… Manual commit The first step would be to tweak the transaction to manually commit like described here:

SQL Other solution would be to use…read more

Styling HTML to PDF with iText 2.1.7

Posted by in Software, Tutorial

There are various solutions for producing PDFs from a HTML file, some with excellent results (e.g. ones based on the chrome renderer). Unfortunately, they usually mean adding more dependencies to an existing system. To keep things in check, we’ve chosen to use iText to generate PDFs. Following the previous post, we need to enhance the generated PDF with some styles. Now, the older versions of iText can’t use CSS directly, so we’ll need to produce the styles by hand. iText has a StyleSheet object which can load tag styles via…read more

HTML to PDF with iText 2.1.7

Posted by in Software, Tutorial

Sometimes you need to use an older version of a product die to e.g. licensing changes. It’s my case with iText. While the new version looks fantastic, their changes (and removal of e.g. RTF output) are deal breakers for the feature set we need to maintain. Therefore, 2.1.7 is the most recent version we can use. Heh. In maven, this would be:

The string resulted from the previous article can be printed out fairly easily. First, we create a document and a writer:

We write the document:

read more

Load Templates with Pebble

Posted by in Software, Tutorial

Pebble is a templating engine. It looks particularly familiar to me because I have been using Django. You have access to blocks, include/import features, loops etc. This post is a simple exercise in loading some templates. Prerequisites I’ve been using Eclipse IDE, but you can use whatever you prefer. I’ve created a maven project and added pebble dependency:

The templates I’ve created 3 templates in the resources folder of the project: index.html


Note how the {{item}} parameter is taken from the loop in *index.html. inner.html

read more

Display a Function’s Errors in Oracle

Posted by in Software, Tutorial

TL;DR: Use the power of DBMS_OUTPUT.PUT_LINE, Luke! I’ve built a function along the lines of:

When using the function, I got some 0 results and I wanted to know why. The solution I got was using DBMS_OUTPUT.PUT_LINE:

Now, all you have to do is enable DBMS_OUTPUT in your environment and you’ll see the exceptions. NOTE: This is useful while building and tuning the function. IMHO one should disable the PUT_LINE statements in production. HTH, A little experiment: If you find this post and ad below useful, please check…read more

Call an Oracle Function from Spring with CallableStatement

Posted by in Software, Tutorial

Following the previous post, I wondered if there’s a more elegant way to call a function. It turns out there is and it’s based on CallableStatement:

The CallableStatementCreator sets up the statement and the CallableStatementCallback executes the statement and returns the value up to the execute() call. Having a function:

We can build a query string like:

The CallableStatementCreator instance is then:

This states the first parameter is a result, the second and 3rd parameter are function parameters. NOTE: Be careful because you can specify indices…read more

Call an Oracle Function from Spring

Posted by in Software, Tutorial

The easiest way to call a function from Spring is using SELECT. For example, having a function HAS_PANEL_FLAG_OK with two parameters and returning an integer, the function call looks like:

This will return all flags for the panels matching the condition. Java Call The query string can be something like:

and the actual query will be:

The problem I’ve encountered is the ability to specify an argument which is not part of the query. Something like this:

I’ll investigate this later… HTH, A little experiment: If…read more