Skip to content

Instantly share code, notes, and snippets.

@jul
jul / get_magic.py
Created May 1, 2022
minimalist magic detection for fun
View get_magic.py
#!/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 / liseuse.draft.py
Last active May 1, 2022
FUCK LA BNF.py
View liseuse.draft.py
from pyquery import PyQuery as S
import urllib
from json import loads, dumps
from os import path, makedirs
from requests import get
WAIT=.5
"""
Admire the doc made by these fucking twats
http://www.bnf.fr/fr/professionnels/donnees_bnf_recuperables/a.donnees_rdf.html#SHDC__Attribute_BlocArticle7BnF
@jul
jul / freebsd_inst.sh
Last active Mar 22, 2022
qemu freeBSD on linux
View freebsd_inst.sh
#!/bin/bash
set -e
LOCATION=$(pwd)
ARCH=amd64
VERSION=13.1
FLAVOUR=BETA2
FROM_VM=https://download.freebsd.org/ftp/releases/VM-IMAGES/${VERSION}-${FLAVOUR}/${ARCH}/Latest/
FROM_CDROM=https://download.freebsd.org/ftp/releases/ISO-IMAGES/${VERSION}/
FILENAME=FreeBSD-${VERSION}-${FLAVOUR}-${ARCH}.qcow2
CDROM="$( basename $FILENAME .qcow2 )-bootonly.iso"
@jul
jul / oneline.sh
Last active Jan 24, 2022
timing python oneliner by size of line
View oneline.sh
#!/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 / get_unbound_adblock.sh
Last active Jan 24, 2022
update unbound adblocklist
View get_unbound_adblock.sh
#!/bin/bash
#
# FUCKING PUBLIC LICENCE
# This code belongs to me jul@github.com/@obnoxiousJul and all (insert <#alias>) contributing in making it fun.
# And fucking stop being Pissenlit Würzel Schleckers met bigoudis with open source devs and maintainers
# v 0.5.1 cross devuan/debian restarting of unbound
# v 0.5 having fun
# v 0.4 code got ugly, BUT, making dynamic list from adblock conf for firefox (easylist)
@jul
jul / todel.py
Last active Dec 13, 2021
jeu de la vie (à réécrire (kleenex)) en pavage triangulaire
View todel.py
import PySimpleGUI 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 Dec 12, 2021
gof triangulaire on the way
View goft.py
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
@jul
jul / gof_base.py
Created Dec 11, 2021
préparer un jeu de la vie en base triangulaire (les carrés sucent)
View gof_base.py
import PySimpleGUI as sg
### uitliser ipython -i argv[0] pour être en interactif et faire joujou
can = sg.Canvas(size=(400,600))
win = sg.Window("titre",[[can,],],finalize=True)
c = can.TKCanvas
from time import sleep
SZ=50
ORD=1
def save(canvas, name="save"):
@jul
jul / tr.py
Created Dec 11, 2021
dessiner un pavage triangulaire en python en moins de 100 sloc
View tr.py
import PySimpleGUI as sg
### uitliser ipython -i argv[0] pour être en interactif et faire joujou
can = sg.Canvas(size=(400,600))
win = sg.Window("titre",[[can,],],finalize=True)
c = can.TKCanvas
SZ=50
def tr(x,y, up=1,**kw):
""" créer un triangle équilatéral centré en x,y avec une homothétie /
symmétrie sur l'axe des y (up / down) exprimée en coordonnées
@jul
jul / wall_clock.py
Last active Aug 30, 2021
a wall clock with matplotlib
View wall_clock.py
import matplotlib.pyplot as plt
from time import sleep, time, localtime
# Constant are CAPitalized in python by convention
from cmath import pi as PI, e as E
# correcting python notations j => I
I = complex("j")
# maplotlib does not plot lines using the classical
# (x0,y0), (x1,y1) convention