Skip to content

Instantly share code, notes, and snippets.

View nitely's full-sized avatar
🖖
live long and prosper

Esteban C Borsani nitely

🖖
live long and prosper
View GitHub Profile
@nitely
nitely / mariomka-benchmark.nim
Created August 13, 2020 03:36 — forked from thomastay/mariomka-benchmark.nim
quick and dirty bench for mariomka bench
import os
import std/[times, monotimes, stats]
from regex import nil
from std/re import nil
proc measureNimRegex(data, pattern: string) =
var r: RunningStat
var matches: int
let patternRe = regex.re(pattern)
for i in 1..3:
@nitely
nitely / findrune.nim
Created August 2, 2020 06:08
Fast find for Rune / Unicode / utf-8 in Nim
from strutils import find
from unicode import Rune
# XXX do a simpler find when vm (or no memchr available),
# since this is only fast due to memchr
# untested
func find*(s: string, r: Rune, start: Natural = 0): int =
if r.ord < 0xff:
return find(s, r.char, start)
let c = (r.ord and 0xff).char
@nitely
nitely / nfa_to_dfa.py
Created March 19, 2020 14:30
NFA to DFA
import deque
def _e_closure(node: Node, result: Set[Node]) -> None:
if isinstance(Node, (CharNode, EOFNode)): # si es matcheable
result.add(node)
return
# node deberia ser *, +, |, (, )
for n in node.out:
_e_closure(n, result)
@nitely
nitely / bench_unicodedb_ascii.nim
Created August 26, 2019 17:30
bench_unicodedb_ascii.nim
import nimbench
import unicodedb/properties
import unicodedb/types
import unicodedb/widths
import unicodedb/scripts
import unicodedb/decompositions
import unicode
template benchCode(
theProc: untyped,
@nitely
nitely / some.js
Created January 18, 2019 21:31
moment.js timezone SyntaxError
/*
ERROR in ./node_modules/moment-timezone/data/packed/latest.json
Module parse failed: Unexpected token e in JSON at position 0 while parsing near 'export default {
Module build failed (from ./node_modules/babel-loader/lib/index.js):
SyntaxError: /usr/src/app/ui/src/tz: Unexpected token, expected ";" (1:10)
Here is a solution:
*/
@nitely
nitely / index.html
Last active December 7, 2018 17:15
d3 area not showing
<!DOCTYPE html>
<meta charset="utf-8">
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/5.7.0/d3.min.js"></script>
<style>
body {
font: 10px sans-serif;
}
@nitely
nitely / serialize_datetime.py
Created November 21, 2018 23:25
django serialize_datetime for javascript and json consumption
def serialize_datetime(dt):
return (
dt.astimezone(timezone.get_default_timezone())
.isoformat()
.replace('+00:00', 'Z'))
@nitely
nitely / split.nim
Created August 25, 2018 18:00
nim-regex find based split
proc split*(s: string, sep: Regex): seq[string] =
result = @[]
var
m = RegexMatch()
ds = initDataSets(sep.states.len, true)
first = 0
last = 0
n = 0
while last <= s.len:
first = last
@nitely
nitely / substates.txt
Created August 4, 2018 08:56
systemd substates list
# from https://github.com/systemd/systemd/blob/b0450864f1723ad12176d7956377d89ff4a84d8c/src/basic/unit-def.c
"stub",
"loaded",
"not-found",
"bad-setting",
"error",
"merged",
"masked"
@nitely
nitely / strqueue_bench.nim
Last active May 18, 2018 03:51
strqueue_bench
import nimbench
type
StrQueue = object
s: string
pos: int
filled: int
b: seq[Slice[int]]
head: int
tail: int