Skip to content

Instantly share code, notes, and snippets.

@jul
jul / reciprocal.moving.poi.py
Last active May 1, 2024 08:02
making templatized sociogram
#!/usr/bin/env python3
import os
import psycopg2
from datetime import date, datetime, timedelta
from archery import mdict
def int_env_default(var, default):
return int(os.getenv(var) or default)
@jul
jul / devine_addition.py
Last active September 25, 2024 06:30
Appli pour faire réviser les additions
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# WTFPL 2.0 do whatever the freak you want with this code except claiming its yours.
#!/usr/bin/env python3
from random import shuffle
import FreeSimpleGUI as sg
N=5
M=4
first = True
@jul
jul / lol.py
Last active October 25, 2022 20:47
the kind of simple wsgi with a pretty dynamic router (please NEVER do this at home)
#!/usr/bin/env python
# requires pip install multipart
import multipart
from wsgiref.simple_server import make_server
from json import dumps
from urllib.parse import parse_qsl
# require pip install confined my OWN FORTH BASED templating SYNTAX
from confined import templatize
class e: a=0
@jul
jul / simple.py
Created October 24, 2022 18:50
a simple multipart-form-data wsgi server echoing path, file and data sent to it (for testing web-client)
import multipart
from wsgiref.simple_server import make_server
from json import dumps
from urllib.parse import parse_qsl
import logging
def simple_app(environ, start_response):
fo,fi=multipart.parse_form_data(environ)
@jul
jul / check_require.sh
Last active September 11, 2022 12:28
checking for useless requirements in requirements.txt in python
#!/usr/bin/env bash
# author [email protected]
# licence WTFPL2.0
WORKDIR=./__
WVENVDIR=todel
GRUIK=
PYTHON=
export WVENVDIR
UPGRADE_PIP=hygien
TO_KEEP_OR_NOT_TO_KEEP="DONT_KEEP"
@jul
jul / get_magic.py
Created May 1, 2022 11:49
minimalist magic detection for fun
#!/usr/bin/env python3
from requests import get
import re
'''
sometimes, you want a minimalistic magic number detection for simple file types.
Like for instance, you scrap the web and you don't trust the web server when returning the mime type
(actually happened to me on bilbliothèque nationale de france more than once)
So, yo want to make sure that for instance, the returned content is atcually a jpeg, and you may not be
on a unix OS with libmagic and you may not want to add dependencies and ...
just comparing 3 bytes in a row in a raw byte stream is not THAT hard
@jul
jul / oneline.sh
Last active January 24, 2022 23:41
timing python oneliner by size of line
#!/usr/bin/env bash
export LANG=C
redadd() { python3 -c '(s,d,r)=(__import__("sys"),__import__("archery").mdict,__import__("functools").reduce);print(sorted(r(d.__add__,(d({l[:-1]:1}) for l in s.stdin.readlines())).items(),key=lambda k:k[1],reverse=True)[:10])' ; }
red() { python3 -c '(s,d,r)=(__import__("sys"),__import__("archery").mdict,__import__("functools").reduce);print(sorted(r(d.__radd__,(d({l[:-1]:1}) for l in s.stdin.readlines())).items(),key=lambda k:k[1],reverse=True)[:10])' ; }
function count() { python3 -c'(s,d)=(__import__("sys"),__import__("archery").mdict);print(sorted(sum((d({l[:-1]:1}) for l in s.stdin.readlines()),{}).items(),key=lambda k:k[1],reverse=True)[:10])'; }
cfl() { python3 -c'(s,t,d,f)=(__import__("sys"),__import__("tld"),__import__("archery").mdict,lambda l:t.get_fld(l[:-1],fix_protocol=True,fail_silently=True));print(sorted(sum((d({f(l):1}) for l in s.stdin.readlines()),{}).items(),key=lambda k:k[1],reverse=True)[:10])'; }
test_time() {
func="$1"
TIMEFORMAT="%U"
@jul
jul / freebsd_inst.sh
Last active October 8, 2025 22:11
freeBSD with a clean install of podman on linux (qemu)
#!/bin/bash
set -e
# specs for virtual machine
declare -A VMACHINE=( [RAM]=4g [CPU]=2 )
# you can override them by redifining them in this file
[ -e specs.sh ] && source ./specs.sh
echo all files in skel will be copied in /home/user
@jul
jul / todel.py
Last active September 24, 2024 10:10
jeu de la vie (à réécrire (kleenex)) en pavage triangulaire
import FreeSimpleGUI as sg
from operator import itemgetter
### uitliser ipython -i argv[0] pour être en interactif et faire joujou
can = sg.Canvas(size=(1412,998))
status=sg.Text('status')
win = sg.Window("titre",[[can,],[status,],], finalize=True)
c = can.TKCanvas
from time import sleep, time
from random import randint
from os import system
@jul
jul / goft.py
Created December 12, 2021 12:22
gof triangulaire on the way
import PySimpleGUI as sg
from operator import itemgetter
### uitliser ipython -i argv[0] pour être en interactif et faire joujou
can = sg.Canvas(size=(400,600))
status=sg.Text('status')
win = sg.Window("titre",[[can,],[status,],], finalize=True)
c = can.TKCanvas
from time import sleep
SZ=50