Skip to content

Instantly share code, notes, and snippets.

View lovasoa's full-sized avatar
🎯
Focusing

Ophir LOJKINE lovasoa

🎯
Focusing
View GitHub Profile
@lovasoa
lovasoa / README.md
Last active October 1, 2019 14:40
Command-line utility that transcribes a number to the mayan numeral system. Written in rust.
pub fn decrypt(mut input_buf: Vec<u8>) -> Result<Vec<u8>, InvalidEncryptedImage> {
if get_int(&input_buf, 0) != 0x0A_0A_0A_0A { return Ok(input_buf); }
let header_size = get_int(&input_buf, input_buf.len() as u32 - 4);
let encrypted_size_pos = header_size + 4;
let encrypted_pos = encrypted_size_pos + 4;
let encrypted_size = get_int(&input_buf, encrypted_size_pos);
let encrypted_end_pos = encrypted_pos + encrypted_size;
let footer_size = input_buf.len() as u32 - 4 - encrypted_end_pos;
let encrypted = input_buf.get(encrypted_pos as usize..(encrypted_pos + encrypted_size) as usize).unwrap();
let mut encrypted_copy = Vec::from(encrypted);
@lovasoa
lovasoa / influxdb_benchmark.py
Created July 11, 2019 10:47
InfluxDB python client benchmark
def test(client, n):
"""Stupid test function"""
q = f"SELECT * FROM test LIMIT {n}"
client.query(q)
setup = """
from __main__ import test
from influxdb import InfluxDBClient
html, body {
font-family: sans-serif;
margin: 0;
padding: 0;
font-size: 16px;
}
header > nav{
display: flex;
border: 1px solid black;
import xml.sax
import sys
import json
class InkscapeSvgHandler(xml.sax.ContentHandler):
def __init__(self):
self.o = {}
self.t = 1554660678511
def startElement(self, name, attrs):
if name not in ("path","line","rect"):
This file has been truncated, but you can view the full file.
<?xml version="1.0"?>
<svg xmlns="http://www.w3.org/2000/svg" id="canvas" width="51880" height="65536" version="1.1" style="cursor: move; will-change: auto; transform: scale(0.1);">
<defs id="defs"/>
<line id="sjww41vjcg" x1="16580" y1="15620" x2="16610" y2="15620" stroke="#fdeedf" stroke-width="48" opacity="1"/>
<line id="sjww42o52m" x1="18560" y1="11500" x2="18920" y2="11700" stroke="#ffffff" stroke-width="48" opacity="1"/>
<line id="sjww42q3rs" x1="18730" y1="11500" x2="18760" y2="11500" stroke="#ffffff" stroke-width="48" opacity="1"/>
<line id="sjww42qyy4" x1="18710" y1="11520" x2="19110" y2="11930" stroke="#ffffff" stroke-width="48" opacity="1"/>
<line id="sjww44z7l3" x1="14570" y1="10900" x2="14570" y2="10890" stroke="#fff6ee" stroke-width="48" opacity="1"/>
<line id="sjww476g4i" x1="15630" y1="11410" x2="15620" y2="11410" stroke="#fff6ee" stroke-width="48" opacity="1"/>
<path id="ljww4bditk" stroke="#84776b" stroke-width="48" opacity="0.3" d="M 25950 13620"/>
@lovasoa
lovasoa / async_balancing.js
Created June 4, 2019 13:09
Balance load between asynchronous functions
/**
* Balances work between several asynchronous functions.
* Given an array of async functions that make the same computation,
* returns a single function that has the computation made by
* the first idle function.
*
* @template T,U
* @param {((...args:T) => Promise<U>)[]} functions
* @param {boolean?} fifo Whether to process the arguments in fifo or lifo
* @returns {(...args:T) => Promise<U>}
@lovasoa
lovasoa / max_canvas_size.js
Created May 27, 2019 17:07
Compute the maximum available canvas width and height in a browser
async function maxCanvasSize(ratio) {
let cvs = document.createElement("canvas");
let xmin = 1, xmax = 1 << 18;
while (xmax - xmin > 1) {
let x = ((xmin + xmax) / 2) | 0;
let y = (x / ratio) | 0;
if (await canvasTest(cvs, x, y)) xmin = x;
else xmax = x;
}
return [xmin, xmin / ratio | 0];
@lovasoa
lovasoa / my_aes_decrypt.py
Created May 22, 2019 11:32
custom aes decrypt in pure python3 (does not include the key schedule algorithm)
#!/usr/bin/env python3
# coding: utf-8
from functools import reduce
from operator import xor
import struct
aes_inverse_s_box = bytes.fromhex(
'52096ad53036a538bf40a39e81f3d7fb7ce339829b2fff87348e4344c4dee9cb547b9432a6c2233dee4c950b42fac34e082ea16628d924b276'
'5ba2496d8bd12572f8f66486689816d4a45ccc5d65b6926c704850fdedb9da5e154657a78d9d8490d8ab008cbcd30af7e45805b8b34506d02c'
'1e8fca3f0f02c1afbd0301138a6b3a9111414f67dcea97f2cfcef0b4e67396ac7422e7ad3585e2f937e81c75df6e47f11a711d29c5896fb762'
@lovasoa
lovasoa / aes.py
Last active March 1, 2023 10:08 — forked from bonsaiviking/aes.py
A simple/simplistic implementation of AES in pure Python 3
# My AES implementation
# By Daniel Miller
# Ported to python 3 by @lovasoa
def xor(s1, s2):
return bytes(a ^ b for a, b in zip(s1, s2))
class AES(object):