Skip to content

Instantly share code, notes, and snippets.

@mdalp
mdalp / neo4j-contact networks
Last active November 14, 2019 10:45
This Gist wants to show how to take advantage of the Neo4j graph modeling to represent and navigate contact networks.
:neo4j-version: 2.2
:author: Marcello Dalponte
:twitter: @m_dalp
## Contact networks
A contact network is one of the typologies of dynamic networks described in the famous paper of Holme and Saramäki[1].
A dynamic network is a mathematical representation of the evolution of the relationships between entities through graphs.
It's interesting to catch this dynamicity because describes the transitivity of the order of the interactions: if A meets B and after B meets C then A can transmit something to C but not the opposite; this is useful to study the spreading of informations or infections.
An interesting project that aims to collect this kind of data is Sociopatterns[2], where Cattuto and others developed a framework to collect contacts data from RFID sensors [3].
@mdalp
mdalp / star_wars_rebels_finance
Last active December 20, 2021 04:16
Rebels financial system
# The story of rebels economical system began
## Introduction
Here I tell you a story to present a solution to an everyday problem.
How many times it happens that you go for a travel in the hyperspace
with other rebels, you go on a mission with a couple of Jedi or,
in general, you do something together with other people with which
you have to share expenses?
@mdalp
mdalp / davetype.py
Created March 4, 2016 16:53
Weird type that automatically makes all methods of a class static.
import re
class DaveType(type):
not_allowed_attr_names = re.compile('^__\w+__$')
@classmethod
def _is_allowed_attr_name(cls, name):
return not cls.not_allowed_attr_names.match(name)
@classmethod
@mdalp
mdalp / powered_related_factory.py
Last active September 15, 2016 17:29
Powered RelatedFactory to be able to smoothly use the django `attr__subattr` syntax with RelatedFactories
@mdalp
mdalp / binary_digits.py
Last active June 14, 2017 12:39
Easy implementation of a conversion tool from integer to binary.
from __future__ import division
def binary_digits(n):
if n == 0:
return '0'
res = ''
while n > 0:
mod_n = n % 2
res = str(mod_n) + res
n = int(n / 2)
@mdalp
mdalp / deferred_log_handler.py
Created February 16, 2018 12:22
Proof of concept for a log handler that defers logs calls to an other process.
from __future__ import absolute_import, division, unicode_literals, print_function
import atexit
import cPickle
import logging
import multiprocessing
import sys
import time
import traceback
from datetime import datetime