Skip to content

Instantly share code, notes, and snippets.

View CircuitSacul's full-sized avatar

CircuitSacul

View GitHub Profile
@CircuitSacul
CircuitSacul / ref.py
Last active August 11, 2023 01:51
Strings weren't mutable, they said.
import typing as t
def ref(obj):
class Ref:
pass
slf = Ref()
slf.__obj = obj
build_methods(slf)
@CircuitSacul
CircuitSacul / backup.mjs
Created January 25, 2023 06:26
automatic backups for postgresql databases using google/zx
#!/usr/bin/env zx
await cd('BACKUP FOLDER')
let files = await $`ls`
let min = 0
files.stdout.split("\n").forEach(file => {
let fileNumber = Number.parseInt(file.split(".")[0], 10)
if (fileNumber > min) {
min = fileNumber
@CircuitSacul
CircuitSacul / lazy_converter_list.py
Last active January 14, 2022 23:25
Quickly convert values of large lists.
# example:
range_of_ints = range(0, 500_000_000_000_000)
squared_ints = LazyList(range_of_ints, lambda v: v**2)
print(len(squared_ints) == len(range_of_ints)) # -> True
print(squared_ints) # -> LazyList([0, 1, 4, 9, 16, ..., 249999999999999000000000000001])
print(squared_ints[55:100]) # -> LazyList([3025, 3136, 3249, 3364, 3481, ..., 9801])
print(squared_ints[500]) # -> 250000