Hijack C library functions in D

I like playing with the D programming language and I wrote this little post to show how it’s easy to create a dynamic library (shared object, .so) that can be invoked in other programs; to have a little fun we will write a D replacement for the rand() C standard library function call. For your convenience, all the code is also on github Let’s start with the demo implementation, a C program that calls 10 times the stdlib function rand() to get a random number. ...

March 10, 2020 · Andrea Manzini

a very simple NTP client in D

I am quite a fan of the D programming language and I think it deserves more attention, even if since a few months it’s becoming more and more popular, as it gained top20 in the TIOBE Index for February 2020. As an experiment in network programming, I took this simple NTP client written in C and translated to D ; in my opinion while it’s keeping the low-level nature, it’s shorter, clearer and more effective. It’s only a dozen lines of code, but full program is available on my github; stars and contributions are welcome! ...

February 20, 2020 · Andrea Manzini

migrating a repository from mercurial to git

Since bitbucket is sunsetting the support for mercurial repositories, I wrote a quick and dirty script to automate the migration from mercurial to GIT: #!/bin/bash set -e set -u if [ "$#" -ne 3 ]; then echo "Illegal number of parameters" echo "usage: migrate.sh reponame hgrepourl gitrepourl" exit 1 fi REPONAME=$1 HGURL=$2 GITURL=$3 echo "Migrating $REPONAME from $HGURL to $GITURL..." cd /tmp hg clone $HGURL cd $REPONAME hg bookmark -r default master hg bookmarks hg cd .. mv $REPONAME ${REPONAME}_hg mkdir ${REPONAME}_git cd ${REPONAME}_git git init --bare . cd ../${REPONAME}_hg hg push ../${REPONAME}_git cd ../${REPONAME}_git git remote add hgmigrate $GITURL git push hgmigrate master cd /tmp rm -rf /tmp/${REPONAME}_hg /tmp/${REPONAME}_git echo "...done" Before running the script, you only need to install git and create a git repository (remote or local). ...

December 15, 2019 · Andrea Manzini

il linguaggio Lua: parte 14

segue dalla parte 13 Coroutine Come approccio alla programmazione concorrente, il linguaggio Lua non ha meccanismi interni per gestire nativamente i thread, ma si può appoggiare a ciò che offre il sistema operativo sottostante. Lua invece internamente offre il supporto alle coroutine: un programma Lua può avere diversi percorsi di esecuzione ‘parallela’ ognuno col proprio stack e variabili locali ma che condividono risorse e variabili globali con le altre coroutine. La prima differenza sostanziale col modello classico dei thread è che in un determinato istante ‘gira’ una e una sola coroutine, mentre in un sistema multiprocessore ci possono essere più thread in esecuzione in contemporanea. ...

February 15, 2019 · Andrea Manzini