Skip to content

Instantly share code, notes, and snippets.

@usr-ein
usr-ein / Dockerfile
Last active June 26, 2024 15:20
Optimal multistaged Dockerfile for poetry
# syntax=docker/dockerfile:1
# Keep this syntax directive! It's used to enable Docker BuildKit
# Based on https://github.com/python-poetry/poetry/discussions/1879?sort=top#discussioncomment-216865
# but I try to keep it updated (see history)
################################
# PYTHON-BASE
# Sets up all our shared environment variables
################################
@usr-ein
usr-ein / gdb.sh
Created July 11, 2022 17:59
Hacking: The Art Of Exploitation book cover code (partial)
$ unset HISTFILE
$ gdb -q /usr/bin/etftp
Using host libthread_db library "/lib/tls/i686/cmov/libthread_db.so.1".
(gdb) run -g $(perl -e 'print "AAAA"x64;for($i=65;$i<90;$i++){print
chr($i)x4}')
Starting program: /usr/bin/etftp -g $(perl -e 'print
"AAAA"x64;for($i=65;$i<90;$i++){print chr($i)x4}')
tftp: unknown host
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
@usr-ein
usr-ein / tv_snow.py
Last active December 9, 2021 13:46
A TV "snow" (static) white noise generator
#!/usr/bin/env python3
"""
WARNING: CAN TRIGGER EPILEPSY, ESPECIALLY IF ZOOMED IN !
This is a very stupid white noise generator.
It simulates a TV screen's static noise so that you can display it onto a screen
and make it look like a TV.
I made it because I like that effect and couldn't find an app for it, but only shitty GIFs that aren't really random.
@usr-ein
usr-ein / 1_turtlev4.ps
Last active October 4, 2021 10:02
L-Systems in pure PostScript, because I like pain. Written on 2020-01-26
%!PS
% Author: Samuel Prevost <samuel.prevost@etu.upmc.fr>
% To view the result, run ps2pdf file.gs output.pdf
% Ref
% https://www-cdf.fnal.gov/offline/PostScript/BLUEBOOK.PDF
% https://www.math.ubc.ca/~cass/courses/ps.html
% https://ift2015h20code.files.wordpress.com/2020/01/ift2015h20-tp1-postscript.pdf
@usr-ein
usr-ein / videostream.py
Created September 17, 2021 13:22
Video stream from JPEG - Create an HTTP video stream from a file that periodically gets overwritten by another process
#!/usr/bin/env python3
import io
import os
from sys import argv
from time import sleep
from flask import Flask, Response, render_template
from PIL import Image
app = Flask(__name__)
@usr-ein
usr-ein / gpudiff.py
Last active October 5, 2022 10:56
GPUDiff - a treemap GPU memory profiler for PyTorch (and TF if you want to port it)
from __future__ import annotations
import os
from typing import List, Optional, Dict, Union
import subprocess as sp
import plotly.express as px
import torch
class Singleton(type):
@usr-ein
usr-ein / colours.py
Created August 15, 2021 19:18
Print the colours and their associated codes
#!/usr/bin/env python3
def main():
"""Main function"""
for i in range(30, 37 + 1):
print(("\033[%dm" % i) + ("\\033[%dm" % i))
print("\033[39m\\033[49m - Reset colour")
@usr-ein
usr-ein / tracerouteMap.py
Created July 30, 2021 11:59
Traceroute mapping - maps hops that packet make by setting the TTL to increasing values and seeing where it dies, then making a geo map from the IPs
# CLI
import sys
# Traceroute
import pexpect
# import trparse # DEPRECATED
import socket
import struct
# IP location
import json
import urllib.request
@usr-ein
usr-ein / reinforce.py
Created July 23, 2021 15:45
REINFORCE algorithm in PyTorch
import argparse
import gym
import numpy as np
from itertools import count
import torch
import torch.nn as nn
import torch.nn.functional as F
import torch.optim as optim
from torch.distributions import Categorical
@usr-ein
usr-ein / test_pytorch.py
Created June 30, 2021 14:41
Test if different DL frameworks work well with your current CUDA installation
#!/usr/bin/env python3
"""Tests PyTorch CUDA capabilities"""
import sys
import torch
def main():
"""Main function"""