Skip to content

Instantly share code, notes, and snippets.

@jnpn
jnpn / rtree.py
Created June 10, 2019 15:03
trying ways to create random trees
import random
class Node:
def __init__(self, v, l=None, r=None):
assert v is not None, "can't create a node with value = None"
self.v = v
self.l = l
self.r = r
def __repr__(self):
@jnpn
jnpn / degenerate.py
Last active June 12, 2019 10:59
Some reflection helpers
"""
Reflection utils for repl interaction
"""
import types
from collections.abc import Iterable
from itertools import groupby
def kinds(m):
"""
@jnpn
jnpn / pset.el
Created June 12, 2019 20:16
Enumeration recursive de l'Ensemble Puissance
;; Un peu de combinatoire:
;;
;; Definition recursive de l'Ensemble Puissance (powerset)
;; (avec variantes stylistiques)
(setq lexical-binding t)
(defun pset (s)
(if (null s)
'(())
@jnpn
jnpn / gun.py
Created June 17, 2019 07:25
callable generator
class Gun:
'''
>>> g = Gun()
>>> f = g()
>>> [next(f), next(g)]
[2, 1]
>>> [next(f), next(g)]
[3, 2]
>>> [next(f), next(g)]
[4, 3]
@jnpn
jnpn / impots-v2.js
Last active June 20, 2019 19:29
calcul les impots par tranche (fr_FR)
// une tranche est un intervalle et un pourcentage
var defaut = {
tranches: [
{lo:0, hi:9964, percent:0},
{lo:9964, hi:27519, percent:14},
{lo:27519, hi:73779, percent:30},
{lo:73779, hi:156244, percent:41},
{lo:156244, hi:999999999999, percent:45}
]
}
@jnpn
jnpn / x.kt
Created June 20, 2019 18:38
xml to sax to tree in kotlin
package x
import java.util.Stack
import java.io.File
import javax.xml.parsers.*
import org.xml.sax.*
import org.xml.sax.helpers.*
class Node(val l:String, val q:String, val u:String, val a:Map<String,String>) {
val children:MutableList<Node> = mutableListOf<Node>()
@jnpn
jnpn / fsdups.py
Created July 1, 2019 19:00
os.walk . hd5 . groupby
import os
import sys
import hashlib
DIR=os.path.expanduser('~/Downloads')
def md5(f,c=4096):
m = hashlib.md5()
with open(f,'rb') as b:
m.update(b.read(c))
@jnpn
jnpn / compile.el
Created July 2, 2019 12:38
alpha compiler in emacs lisp
;; This buffer is for text that is not saved, and for Lisp evaluation.
;; To create a file, visit it with C-x C-f and enter text in its buffer.
;;
;; arithmetic expression compiler for elisp stack machine (and more)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; Tree -> Stack
(defun left (a)
(cadr a))
@jnpn
jnpn / fstring.el
Last active July 18, 2019 17:57
Attempt at bringing f-string in elisp.
;; This buffer is for text that is not saved, and for Lisp evaluation.
;; To create a file, visit it with C-x C-f and enter text in its buffer.
;;
;;; Attempt at bringing f-string in elisp.
;;; (@f "{a} = {b}")
;;; ->
;;; (let ((a~ a)
;;; (b~ b))
;;; (concatenate 'string a~ " = " b~))
@jnpn
jnpn / re-builder-ansi.el
Created October 5, 2019 07:43
emacs ansi removal regex
[]\[\(.;..\)?[[:digit:]]*?m →