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 / node-walk.es6
Last active March 12, 2024 09:40
Walk through a directory recursively in node.js.
// ES6 version using asynchronous iterators, compatible with node v10.0+
const fs = require("fs");
const path = require("path");
async function* walk(dir) {
for await (const d of await fs.promises.opendir(dir)) {
const entry = path.join(dir, d.name);
if (d.isDirectory()) yield* walk(entry);
else if (d.isFile()) yield entry;
@lovasoa
lovasoa / canvas color picker.html
Last active February 28, 2024 19:53
JS color picker: HTML5 & javascript color picker that uses HTML5 canvas. User can choose hue and value, saturation is set to 1. It has color history management.
<!doctype html>
<html>
<head>
<meta charset="utf8" />
<title>Canvascolor</title>
<style>
body {
background-image:url(http://github.com/favicon.ico); /*Just for fun*/
}
main {
@lovasoa
lovasoa / partial-evaluation.js
Last active December 28, 2023 05:56
Partial-evaluation for javascript.
/** pe
* @argument f: the multiple-argument function to turn into a partially-evaluatable
* @returns : A single-argument function that applies its argument as the first argument of f, and returns the partially-evaluated function
* @exemple: pe((a,b)=>a+b)(9)(1) === 10
*/
function pe(f, context, args) {
if(!args) args = [];
if (args.length === f.length) return f.apply(context, args);
return function partial (a) {
var args_copy = args.concat.apply(args, arguments);
@lovasoa
lovasoa / dichotomic-bash.sh
Last active December 6, 2023 23:57
Generic dichotomic search as a shell script
#!/usr/bin/env bash
# Dichotomic search in bash
# This is a bash-specific function that uses bash features.
# This is not guaranteed to work in other shells.
#
# Usage:
# source dichotomic-bash.sh
# result=$(dichotomic_search min max command)
#
# Returns the largest i for which `command i` succeeds (exits with a null exit code)
@lovasoa
lovasoa / pompes.py
Last active September 11, 2023 07:49
pompes à cocktail
import board
import busio
from adafruit_mcp230xx.mcp23017 import MCP23017
import time
from typing import List, Tuple
i2c = busio.I2C(board.SCL, board.SDA)
mcp = MCP23017(i2c, address=0x27)
NOMBRE_POMPES = 16
@lovasoa
lovasoa / read_logs.go
Created November 30, 2020 11:41
Read compressed docker logs without decompressing them all to disks simultaneously. (see https://github.com/moby/moby/issues/41678)
package main
import (
"compress/gzip"
"context"
"encoding/json"
"fmt"
"io"
"log"
"os"
@lovasoa
lovasoa / gale_2.csv
Created May 13, 2023 11:08
Solutions to all stable mariage problems of size 2 and 3
man_1_preference_1 man_1_preference_2 man_2_preference_1 man_2_preference_2 woman_1_preference_1 woman_1_preference_2 woman_2_preference_1 woman_2_preference_2 woman_1_mariage woman_2_mariage
1 2 1 2 1 2 1 2 1 2
1 2 1 2 1 2 2 1 1 2
1 2 1 2 2 1 1 2 2 1
1 2 1 2 2 1 2 1 2 1
1 2 2 1 1 2 1 2 1 2
1 2 2 1 1 2 2 1 1 2
1 2 2 1 2 1 1 2 1 2
1 2 2 1 2 1 2 1 1 2
@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):
@lovasoa
lovasoa / hanoi.rs
Last active January 28, 2023 14:09
Tower of hanoi solver in rust.
/***
Tower of Hanoi solver.
https://en.wikipedia.org/wiki/Tower_of_Hanoi
Example :
```
$ rustc hanoi.rs
$ ./hanoi 3
@lovasoa
lovasoa / lib.rs
Last active October 30, 2022 00:33
autovec : alternative to rust's standard vector type which uses column-oriented storage for better code auto-vectorization. In short: makes rust code working with vectors of structs magically faster.
#[derive(Clone, Debug, PartialEq)]
struct B {
x: bool,
y: f64,
}
pub trait AutoVec {
type Vec;
}