Skip to content

Instantly share code, notes, and snippets.

View gandroz's full-sized avatar

Guillaume Androz gandroz

View GitHub Profile
@gandroz
gandroz / to_wei.py
Created February 19, 2022 15:03
to wei
web3.toWei(Decimal('0.000000005'), 'ether')
# returns 5000000000
@gandroz
gandroz / from_wei.py
Created February 19, 2022 15:02
from wei
w3.fromWei(3841357360894980500000001, 'ether')
# returns Decimal('3841357.360894980500000001')
@gandroz
gandroz / call_c_library.py
Created May 4, 2021 20:35
Calling a C library
import ctypes
cmodule = ctypes.cdll.LoadLibrary('./my_c_library.so')
@gandroz
gandroz / test_c_module.py
Last active May 5, 2021 14:22
test function to call c methods
# load c library
cmodule = load_module()
# define source and target strings
source = "levenshtein"
target = "levenstein"
# define edition costs
insert_cost = 1
delete_cost = 1
replace_cost = 2
# call c function
@gandroz
gandroz / load_c_module.py
Last active May 5, 2021 14:25
Load C module helper function
def load_module():
# load library
cmodule = ctypes.cdll.LoadLibrary('./levenshtein.so')
# define arguments type
cmodule.levenshtein.argtypes = [ctypes.c_char_p,
ctypes.c_char_p,
ctypes.c_int,
ctypes.c_int,
ctypes.c_int]
# define return type
@gandroz
gandroz / makefile
Created May 4, 2021 17:43
makefile for c library
CFLAGS = -fpic -lm -std=gnu99 -O3 -march=native -DCONJUGRAD_FLOAT=64
all: levenshtein.so
m.PHONY : clean
levenshtein.so: levenshtein.o
gcc -shared -o $@ $^
%.o: %.c
@gandroz
gandroz / levenshtein.c
Last active May 4, 2021 17:51
Minimum Levenshtein distance optimized
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#define MIN3(a, b, c) ((a) < (b) ? ((a) < (c) ? (a) : (c)) : ((b) < (c) ? (b) : (c)))
int levenshtein(char *source, char *target, int ins_cost, int del_cost, int rep_cost)
{
/*
Input:
source: a string corresponding to the string you are starting with
@gandroz
gandroz / levenshtein_tab.c
Last active May 4, 2021 17:52
Levenshtein distance matrix construction
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#define MIN3(a, b, c) ((a) < (b) ? ((a) < (c) ? (a) : (c)) : ((b) < (c) ? (b) : (c)))
int* min_edit_distance_tab(char *source, char *target, int ins_cost, int del_cost, int rep_cost)
{
/*
Input:
source: a string corresponding to the string you are starting with
@gandroz
gandroz / ip_sender.timer
Created March 14, 2021 20:59
IP sender timer
[Unit]
Description=Current IP email sender timer
[Timer]
OnCalendar=hourly
Unit=sendip.service
[Install]
WantedBy=multi-user.target
@gandroz
gandroz / ip_sender.service
Created March 14, 2021 20:58
IP sender service
[Unit]
Description=Current IP email sender
After=multi-user.target network.target
[Service]
User=guillaume
Group=guillaume
Type=simple
ExecStart=/home/guillaume/miniconda3/envs/ipsender/bin/python /home/guillaume/src/ipsender/send.py