Skip to content

Instantly share code, notes, and snippets.

@jul
jul / devine_addition.py
Last active April 22, 2024 13:33
Appli pour faire réviser ma fille 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 PySimpleGUI as sg
N=5
M=4
first = True
@jul
jul / freebsd_inst.sh
Last active February 19, 2024 21:31
qemu freeBSD on linux
#!/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
function require () { which $1 &> /dev/null && echo "$1 OK" || ( echo "ARG: You SHOULD install $1 $@"; exit 1; ) }
echo CHECKING
@jul
jul / heapify.py
Last active July 20, 2023 15:54
Exact translation of an heap obfuscated algorithm
"""A heap is a recipie to represent an array as a
binary tree.
A binary tree is a convenient structure for
manipulating ordered data.
Said simply:
we implement a binary tree abstraction on top of an array.
this tree as the following properties:
any child value is smaller than its parent's value
left child is greater than right child.
@jul
jul / get_unbound_adblock.sh
Last active January 9, 2023 06:24
update unbound adblocklist
#!/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 / 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 / rectangle.py
Last active September 26, 2022 12:02
how the class point should not be made in python
#!/usr/bin/env python
# version 2 here https://gist.github.com/jul/200d3a5895a437e20df6
from cmath import polar, rect, pi as PI, e as E, phase
rad_to_deg = lambda r : r/2/PI*360.0
deg_to_rad = lambda r : r*2*PI/360.0
identity = lambda r: r
class Point(complex):
@jul
jul / polygon_rotation.py
Last active September 23, 2022 23:43
We don't need an OOP class called point or rectangle
from PIL import Image, ImageDraw
from cmath import pi as PI, e as E
I = complex("j")
to_x_y = lambda cpl : (cpl.real, cpl.imag)
im = Image.new("RGB", (890, 890), "white")
draw = ImageDraw.Draw(im)
rotation = E**(I*PI/3)
homothetia = min( im.size[0], im.size[1])
# to bored to be smart, random guessing
@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 julien@tayon.net
# 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