Skip to content

Instantly share code, notes, and snippets.

View filevich's full-sized avatar
🥜
deez nuts

JP Filevich filevich

🥜
deez nuts
View GitHub Profile
@filevich
filevich / example.go
Created February 15, 2024 18:30
go logrotate + verbose stdout example
package main
import (
"flag"
"fmt"
"io"
"log"
"os"
"strconv"
@filevich
filevich / pascal_2_lower_snake_case.py
Created April 21, 2023 06:12
pascal to lower snake case in python
import re
s = lambda txt: re.sub(r'(?<!^)(?=[A-Z])', '_', txt).lower()
# eg: s("FooBarBaz") returns "foo_bar_baz"
@filevich
filevich / multi.py
Last active December 15, 2022 05:08
split buffer or range in subranges for a given number of threads
import threading
import time
import random
def thread_function(name, n):
print(f"Thread {name} starting - duration: {n}")
time.sleep(n)
if __name__ == "__main__":
@filevich
filevich / delta
Created November 22, 2022 23:44
python time delta
from datetime import datetime, timedelta
tic = datetime.now()
# do domething
d = (datetime.now() - tic) / timedelta(hours=1)
fmt_dur = lambda d: "{}".format(d)[:-7]
@filevich
filevich / linux-essentials.md
Last active August 26, 2024 16:39
linux install essentials

Gnome config

  • Appearance > Auto-hide the Dock: on
  • Appearance > Icon size: 20
  • Search > Files + Characters: off
  • Sound > Over-Amplification on
  • Power > Auto brightness: off
@filevich
filevich / progress.py
Last active September 21, 2022 00:21
simple progress print python
def progress(it,every,total):
r = (it+1) % delta == 0
p = ((it+1) / total) * 100
if r: print(f"{p:.0f}%");
for i in range(1_000_000):
progress(
it=i,
every=len(data)/10,
total=len(data))
@filevich
filevich / linux-tips.md
Last active October 4, 2024 13:25
linux tips

distro name

lsb_release -a or cat /etc/lsb-release

simple time

/usr/bin/time -f 'TIME:%e RAM:%M\n' go run cmd/dmc/*.go

quick bench cmd alias

import { useState, useEffect, useRef, useMemo } from 'react';
export const useQuery = () => {
const abortCtrl = useMemo(() => new AbortController(), [])
// a priori
, url = useRef("")
, opt = useRef({})
const [res, setRes] = useState(null)
, [err, setErr] = useState(null)
@filevich
filevich / static ip
Created April 11, 2022 21:14
linux guide
# interfaces(5) file used by ifup(8) and ifdown(8)
# Include files from /etc/network/interfaces.d:
source-directory /etc/network/interfaces.d
# replace enp1s0 with your link according to: `$ip -c link show`
auto enp1s0
iface enp1s0 inet static
address 192.168.1.8
netmask 255.255.255.0
@filevich
filevich / combs.py
Last active March 6, 2022 16:32
all possible combinations and subsets of a given array
def cross(h, xs):
return [[h]+x for x in xs]
def combs(xs, n):
if n == 1:
return [[x] for x in xs]
res = []
head = xs[:-n + 1]