In the past, making data tangible was a complicated, manual process. Digital 3D representations of complex data have been around for quite a while, but they were always confined to the digital world. Mostly because it was impractical to convert a digital model to a physical representation. With the advent of cheap, affordable 3D printers, […]
Author: Danilo Bargen
Fetch Current Bitcoin Price with Python
Using the MtGox API, you can easily fetch the current Bitcoin price using a very small Python script. import requests url = ‘http://data.mtgox.com/api/2/BTCUSD/money/ticker’ r = requests.get(url, headers={‘Accept’: ‘application/json’}) print r.json()[‘data’][‘avg’][‘display_short’] If you want to support for multiple currencies and more information, here’s an extended version: # -*- coding: utf-8 -*- from __future__ import print_function, unicode_literals […]
Plot Registered Django Users with Matplotlib
Sometimes you want to see the number of registered users in your Django website over time. Fortunately Django stores the registration date of a user model instance in the date_joined field, so we can plot it. Prerequisites You need an installation of numpy and matplotlib. You can install the libraries using pip: $ pip install […]
Heroku Buildpack for Numpy, Scipy and Scikit-Learn
(TLDR: https://github.com/dbrgn/heroku-buildpack-python-sklearn) Background At Webrepublic we just launched a Python based system that among other things does comparison of large texts using tf-idf vectors in a multi-dimensional vector space and measuring the cosine similarity between them (see http://stackoverflow.com/a/8897648/284318). For this, we needed scikit-learn. During the deployment process, I discovered that one does not simply deploy […]
Using Jedi with YouCompleteMe
(In case you’re not familiar with it yet, Jedi is an awesome autocompletion library for Python that tries to understand your code. There are editor plugins available for Vim, Emacs and Sublime Text 2.) The “official” Jedi plugin for vim is jedi-vim, but there’s another vim autocompletion plugin that supports Jedi: YouCompleteMe. In contrast to […]
Enums in Python
Until now, if you wanted to use enumeration types in Python you had to fall back to a class-attribute approach: >>> class Color(object): … RED = 1 … GREEN = 2 … BLUE = 3 … >>> print(Color.RED) 1 This has different downsides, for example with representation (Color.RED is represented as an integer, not as […]
List Outdated Dependencies with Pip
In the past, if you wanted to review your installed pip packages to see if there are updates available, you either had to use tools like pip-tools or check all of them manually. But since version 1.3 (released on 2013-03-07), pip supports the checking of dependencies with the new list command. In contrast to pip […]
Testing Dajaxice Views in Django
If you want to test Dajaxice views from the Django test client, this might be your first approach: url = ‘/dajaxice/apps.front.add_vote/’ data = {‘vote’: ‘yes’, ‘primary_key’: ‘1’} response = self.client.post(url, data=data) This doesn’t work for several reasons. First of all, we need to simulate an AJAX request. Therefore the HTTP_X_REQUESTED_WITH header needs to be set. […]
Programming a Perceptron in Python
At HSR, I’m currently enrolled in a course about neural networks and machine learning. One of the simplest forms of a neural network model is the perceptron. Background Information A perceptron classifier is a simple model of a neuron. It has different inputs ($x_1$…$x_n$) with different weights ($w_1$…$w_n$). $$s = sum_{i=0}^n w_i cdot x_i$$ The […]
d3.js and X-Requested-With
Most JavaScript frameworks set the X-Requested-With HTTP Header to XMLHttpRequest when sending non-cross-domain XHR requests. Many web frameworks like Django or Flask use this to detect AJAX requests. Because of issues with X-Requested-With and cross-domain XHR requests, d3.js does not set that header by default. Therefore Django’s request.is_ajax() and Flask’s request.is_xhr() break. In order to […]
Recompile Vim with Python/Ruby Support on Arch Linux
Update 2014-08-21: The vim packages in Arch Linux have been reorganized: https://www.archlinux.org/news/reorganization-of-vim-packages/. The standard vim package should now contain Python support, so the recompile is not necessary anymore. For my vim configuration, I need a version of Vim that was built with Python and Ruby support. Unfortunately, the default version of Vim that is installed […]
Virtualenv Quickstart Guide
I was searching for a nice virtualenv quickstart guide today, but couldn’t find one that I liked. Either they were outdated and still relied on easy_install, or they were too complicated. So here’s my own. Why use virtualenv? Virtualenv (http://www.virtualenv.org/) basically provides you with a full Python environment (and/or versions) inside a single folder. This […]
Mail Loop From Hell
Found in #django on freenode, Jul 12, 2012. All names are edited. 11:16 < abrt> since it’s quiet in here I’ll tell you a story. 11:16 < abrt> back in 1992, I had just graduated university and was interning at a government facility in newport news 11:16 < abrt> along with some friends from college. […]
Goodbye WordPress, hi rstblog!
Since having switched from the PHP world to the Python world about 2 years ago, I thought about relaunching my Blog using Python instead of PHP. At first, I thought about creating an application with Django and PostgreSQL, but never really had the time and motivation to finally implement it. But today I stumbled over […]
Ubuntu / Redmine / Nginx / Mongrel / Supervisord
This is a howto to install Redmine on Ubuntu Natty (probably works on Debian too) with Nginx, Mongrel and Supervisord. The listed commands usually assume root permissions. Involved software: Redmine: Duh, the software you want to install 🙂 Nginx: A fast webserver/proxy from Russia Mongrel: The software used to serve redmine Supervisor: A supervisor daemon […]