Python Create UUID from random string of words

Context: I'm loading data from one database (A) to another database (Weaviate). Weaviate only supports UUID, however database A is using strings as the primary identifier for some tables.

Problem: In order to not duplicate data I need to ensure that the string identifier gets converted to an UUID in …

Continue reading »

Python Create UUID from integer

Code:

import uuid
my_uuid = uuid.UUID(int=1)
print(my_uuid)

That should show the following string:

00000000-0000-0000-0000-000000000001

You can also convert back to integer by doing:

my_uuid.int()

For my use case this was needed because my source database has integer based IDs, however the destination …

Continue reading »

ChatGPT Python: using an unofficial library

ChatGPT at the time of writing this blog does not have an official API nor libraries published. Luckily, many folks have inspected the API calls made when using the ChatGPT web UI and created unofficial Python clients.

This blog post, will show you how to use the unofficial chatGPT python …

Continue reading »

Recursive karatsuba multiplication in Python

I'm currently taking the class Algorithm: Design and Analysis of Stanford via Coursera and in the class the Karatsuba algorithm got mentioned. I went ahead and implemented it based on the lecture slides.

The Karatsuba algorithm is a fast multiplication algorithm. It's special because it was the first multiplication algorithm …

Continue reading »

Install PyQt in a virtualenv with Pip

Noticed that pip install pyqt isn't working? At least at the time of writing this blog it isn't..

This is the error that I got:
IOError: [Errno 2] No such file or directory: setup.py

It seems they didn't package it well and it's using configure.py to install. So …

Continue reading »

Only use worker when required on heroku with Django/Python

For a mobile project I required a background worker which sents an email with 300 generated QR codes zipped together as attachment. This costs quite some time so we need a background worker to execute this task.

I wanted to achieve the following result:

  • When the user wants to generate …

Continue reading »

Django Custom View Decorator with Arguments

To make my life easier I made a simple decorator which checks if the parameters are present in the request.POST or request.GET and returns a response if they are not.

It accepts a list of parameters in string format and will loop through each parameter to check if …

Continue reading »

Simple function to return json in Django

Just a small code snippet I use when I need to return json, comments are welcomed.

from django.http import HttpResponse  
from django.utils import simplejson as json

def json_response(dict_to_convert_to_json):  
    return HttpResponse(json.dumps(dict_to_convert_to_json),
                        mimetype="application/json")

To use it in your view you just do it this …

Continue reading »

Trying to install scrapy with pip lxml error: command 'gcc' failed with exit status 1

Just tried to install scrapy with pip / easy_install, but when it comes to installing lxml it will give the following error:

gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.7 -c src/lxml/lxml.etree.c -o build/temp.linux-x86_64-2.7/src/lxml/lxml …

Continue reading »

How to install Setuptools to a specific python version

To install easy_install for a specific python version. I just installed from source and used the python version you want to install setuptools too. I used the following steps in Ubuntu 11.04 with Python 2.5 and Python 2.7 installed. The following commands will install setuptools to python …

Continue reading »