Rust is a new language which aims to be fast a C/C++ but safer and more expressive. Writing code in Rust is not just fun but it also can be useful to write modules for Python to replace CPU-bound code with it’s counterpart in Rust. Thanks to the rust-cpython project...

Cross-compiling is the action of building a package or a binary for a different system thatn the current used for the compilation process; for example compiling ARM binaries on a x86 architecture. In this post I’m going to cross-compile Python packages for a specific Linux distribution using Docker as a...

Google’s Protocol Buffer is a library to encode and decode messages in a binary format optimised for compactness and portability between different platforms. At the moment the core library can generate code for C/C++, Java and Python but additional languages can be implemented by writing a plugin for the Protobuf’s...

The npm package manager uses semver to declare the version of the external dependancies of your package in a more flexible way. Unfortunately the current version of npm by default uses the caret ^ as a default prefix for package’s versions which means the required package must have the same...

These days is all about React. Most of the people are leaving the bandwagon of AngularJS in favour of the React’s bandwagon for a lot of different technical and not-technical reasons (#TROLLING they switch because is the new JavaScript Toy of the Year). But today and here I’ll not talk...

At my team in Plentific we needed a workflow for developing, test and deploying our projects, so I wrote a customised Git workflow to be as simple as possible but to be able to cover all our needs. The document is available on my Github account ready to be forked....

In this post I’m going to explain how it’s possible to hide JavaScript code into a PNG image and executing it into the browser without leaving any trace in the HTML document. This kind of hiding technique can be used to load JavaScript code into the browser bypassing the common...

Do you have a micro instance on Amazon Web Services and you run out of RAM and you don’t want to upgrade to a small one? Or do you need just extra RAM to compile Numpy, Scipy and Pandas only once? Here a simple and dirty solution. AWS instances comes...

A couple of days ago YouTube suggested me this video about optimising JavaScript games on Google Chrome. The video is a talk from the GDC 2012 so it’s pretty old (2 years in IT’s time is really a lot) but the content of the talk is still valid today and...

New year, new programming languages, new technologies and new IDE. I finally switched to Vim as a primary editor for Python, JavaScript, HTML and CSS. The learning curve of Vim is not so steep as you think, the main roadblock is not the editor itself but the correct configuration of...

In a DVCS rebasing is the action performed by re-applying all the commits done on the current active branch since it diverged from a remote branch. That is, all the commits are taken away and re-applied over the latest version of the remote branch. This will rewrite the history of...

Restoring a copy of a medium/big database can be a boring task, it can be worse when the process takes some times (let’s say more than 10 minutes) and you don’t have any idea of the state of the restore process and/or it’s ETA. On Unix you can monitor the...

For companies protecting their source code form reverse engineering is between very to vitally important. Using languages based on virtual machines easily expose the bytecode to simple un-compile techniques which revert the op-codes back to human readable code. One solution involves obfuscating the source code but with Python this is...

Exception handlers are important but more important is to code them in the correct way. Today I’ll show you an example of how to NOT write an exception handler. This example is taken from a real piece of code I found laying around in the code base, so “True story...

Arrays are a list of fixed number of elements of the same type stored into a continuos block of memory. String are a type of array with a fixed number of char with a NULL as the last element of the array. The assembly generated by an array will be...

Unit testing is important to ensure the stability and the correctness of the code throughout all lifespan of the project. However, testing some code requires a connection to external services (like SMTP, web, etc.) which in all cases must be avoided to simplify the test and development environment and to...

Following the last post about the buffer overflow protection, today we finally talk about strings. Strings We’ll start back from the last piece of code used in the previous post: #include <stdio.h> int main() { char text[] = "hello world"; return 0; } and its disassembly: 0x0000000100000ed0 <main+0>: push %rbp...

Now that I have a spare machine where I can do all my experiments, I can start again to write posts about Disassembly C code for fun but, wait, my current hardware is a 32-bit Pentium-M CPU and I want to build and disassembly 64-bit code! Let’s set up my...

Last night I brought to a new life my old laptop to be used during my commuting time to write posts, to experiments some technologies and last but not least show how old hardware can be recycled and used efficiently. With my great surprise I discovered most of the 32-bit...

Counting the number of 1’s in a binary representation of a number (aka Hamming weight aka popcount when binary numbers are involved) with Python using different implementations (naive implementations are obviously excluded :-) ). Implementation and benchmarking To compute the Hamming weight of a number in binary representation two implementations...

Originally this article was about strings but as soon as I disassembled the first C test code I saw an interesting bit of assembly code so I switched the topic: today we will talk about buffer overflow protection and the canary (obviously I’m not talking about the little bird but...

Today we will talk about code inlining which means the ability of the compiler to replace a function call with the body of the called function. The sample code and disassembly The code outputs the power of two between 0 to 9 by colling a power() function: #include <stdio.h> int...

The datetime.datetime object can return the current date and time with a resolution up to microseconds which is true on *nix platforms but not completely true on Windows platforms. The problem On both platforms, and at least with Python 2.7, the minimum resolution reported by datetime is 1 microsecond: >>>...

I’m working on a script on Windows to automatically install Python packages listed in a text file like pip does. Because easy_install doesn’t support a requirements.txt as a packages’ list I made a small Batch file to simulate the pip’s behavior, and I discovered the for loop of Windows’s command...

In this blog I usually write posts related to information technology, but I stumble upon this post on NoiseFromAmerika (an italian blog about politics and economics) and I was surprised about how a concept backed by the common sense it’s so wrong when it’s analysed with scientific method. I made...

I’m not using often string manipulation (I usually handle SQLAlchemy’s queries and sometime XML/XHTML manipulation with the lxml library) but sometimes I need to analyse some paths expressed with a dotted notation comparing every path with a predefined list of path prefixes. The obvious solution is to compare in a...

Time to disassembly the if..then conditional statement. I’ll say in this post will be not exciting like the previous ones (except when we’ll disassembly the optimised code) but the if..then block is one of the base statements of every language so it’s important to know how it’s translate to assembly...

Today we look at the disassembly of a functions involving floats and SSE2 instructions. As I stated in the first post Disassembly C code for fun: part 1 the C code is compiled for a x86-64 architecture which means the CPU has the SSE/SSE2 instructions sets by default. The code...

Counting elements in a list, tuple or dictionary in Python is trivial, count the elements in a iterator is not. Because of the nature of a generator it’s not possibile to know how many elements will be returned from the iterator, only one element is returned at time and the...

So, in the previous post Disassembly C code for fun: part 1 I didn’t used as example the well known “Hello World!” code, but for a good reason: I need to explain some basics of the disassembly process (prologue, epilogue, stack, etc.) before proceed any further. Anyway in this post...

I’m currently reading The C Programming Language by Ritchie and Kernighan to learn the C language from ground zero. I already write sometimes C/C++ code but it’s always a good idea to learn a already known language from the chapter 1 specially if you learn it by practice skipping the...

Python 3 introduced the concept of parameter and return type annotation with PEP 3107. Other interpreted languages supports type annotations for example ActionScript3 and this improved the quality of the generated byte-code and the execution speed because the interpreter can output specialised code for the annotated type. But does is...

It takes me a while to discover how to do it, so I’ll leave this post as a note to myself and to anyone which will have the same need. By default Skia will be build as 32-bit static library under Mac OS X but for who needs to have...

Look this class definition, do you see what’s is wrong and potentially generate big problems in you code? class Foo(object): def __init__(self, bars=[]): self.bars = bars <!–more–!> Before jumping straight to the solution lets play with some instances of that class: >>> foo1=Foo([1, 2, 3]) >>> foo2=Foo([3, 4, 5]) >>>...

Developing an application or script which process data is a straight-forward pattern: data is collected, processed and the result is provided to be stored in a file or database. Those three blocks (collect, process, store) forms a pipeline and in the old days this pipeline is implemented in a series...

In SQLAlchemy you can query the database returning ORM objects instead of raw data from the SQL statement (if you don’t know about it this is a good starting point). Object can be fetched by the value of their primary key: session.query(<class>).get(<primary_key_value>) which returns an instance of class with the...

Core Data is the framework available on iOS to allow to store data on the device using a common API without worrying about the storage backend. It’s very powerful but if you are creating and managing the data from your app. However, if you are providing your custom SQLite database...

Apple inconsistency strikes again: if you have a MacBook Air USB SuperDrive you cannot use it with a normal MacBook Pro. Why, damn Apple, why? There’s no any technical reason except for marketing and profit I suppose. Anyway, googling around a bit I found a workaround to be able to...

It was a rainy and cold afternoon and I had nothing to do except to play around with Box2D on my Android device. I will show you the another-ball-bouncing example using Box2D and Cocos2D. For this example you will need to download these libraries: Cocos2D for Android: you can donwload...

Let start by explaining the goal: we want to send a custom signal when the user press a combination of keys. Sound pretty easy, your are already thinking to override the keyPressEvent() and keyReleaseEvent() virtual methods of your QMainWindow with your custom code. It’s a fair solution, but not the...

Google WebM is the new lossy encoder for images (and videos) which promise a better compression than the old and well known JPEG format. The source code is available anche can be build on Linux, Mac OS X and Windows as well. Anyway, on Windows if you follow the instructions...

It’s very simple with the QtWebKit APIs to open an link with your default browser from a QWebView (you can find some solutions like this in StackOverflow about that) but that works well only with <a> elements. If you are opening an external browser by a window.open() JavaScript function you need a...

Some days ago I was writing a DLL’s wrapper in ctypes and I came across of this typedef in the header file: typedef struct _FILEHandle *FILEHandle; To translate this definition into ctypes is pretty straight-forward (if you already know the solution :-) ). First of all, _FILEHandle is a forward...

For my next project I need to serialise a list of classes using the technology which fits those requirements: ninimum code to serialise/unserialise minmum file size when compressed As you can see the speed for read/write the serialised data is not a requirement but the size of the compressed file...

Adobe Edge is the new product form Adobe which will aim to replicate the features of Flash using HTML5 technology. I’m using Adobe Edge to create an animated introduction for a small GWT project and I ended up with the need to execute code at the end of the movie....

Some weeks ago I read about the Necessitas project on the Qt Labs Blog which let you able to run Qt application on the Android platform. It was very interesting and now I’m going to try it. My test environment is my Mac Book Pro with Snow Leopard. Unfortunately the...

How to setup and compile the latest source code of PySide under Mac OS X Prerequisites Before starting to download and compile, PySide sources you must have some things installed on your system: XCode Python for Mac OS X. In this how-to I will use the 64-bit version Qt toolkit...

To pass a Win32 window handler from a PySide object to a [win32gui.GetDC()](http://docs.activestate.com/activepython/2.7/pywin32/win32gui__GetDC_meth.html) method is not so simple as with PyQt4 or wxPython. I wrote a small test for a C function wich renders a bitmap to a Windows DC and I made a PyQt QMainWindow to show the result....

In this post I’ll show an updated version of the SWIG tutorial to build a Python module on top of a C library which works under Mac OS X. My test environment: Mac OS X 10.6.6 Python 2.7.1 32bit SWIG 2.0.1 XCode 3.2.5 Here a copy&paste of the original tutorial...

In this post I’ll show you a simple event dispatcher implementation in Python. Every big UI frameworks can play with events an listener without reinvent the wheel but sometimes you need a very simple way to dispatch and receive events in you application without involve in megabytes of an external...

Babel is a framework to translate date, times, numbers and currency in all the languages of the world. Unfortunately the package is not py2exe-friendly but with a little patch we can let Babel works when is embedded with py2exe. When you build a Windows executable with py2exe all goes fine...

A couple fo days ago Python 2.7 was release as a first stable release. Looking at the Mac OS X ports I found the new official 64-bit release and I installed it. But now the Qt Python bindings stops working because they are compiled as 32-bit binaries. The procedure to...

New country, new life style, new spoken language and new GUI toolkit ! After 5 years of wxPython toolkit now it’s the time to move to PyQt4. Let’s see how install this GUI toolkit under Mac OS X Snow Leopard. First, donwload th QT4 SDK from QT official site, from...