Skip to content

Instantly share code, notes, and snippets.

View dolohow's full-sized avatar

Łukasz Żarnowiecki dolohow

View GitHub Profile
@dolohow
dolohow / cache.py
Created May 14, 2023 10:40
python cache shelve decorator
import shelve
import time
def cache(func):
def wrapper(*args, **kwargs):
with shelve.open('cache.db') as cache_db:
cache_key = f"{func.__name__}{args}{kwargs}"
if cache_key in cache_db:
# Check if data is expired
cache_time, cache_data = cache_db[cache_key]
@dolohow
dolohow / delete.py
Last active March 5, 2023 09:18
Backup and delete old messages on telegram
#!/usr/bin/python3
import pymongo
import json
import asyncio
from pyrogram import Client
client = pymongo.MongoClient("localhost", 27017)
db = client.telegram
@dolohow
dolohow / photoblog_export.mjs
Created February 24, 2023 11:33
Script that allows you to export image links from soon to be closed photoblog.pl
import { JSDOM } from 'jsdom';
const username = '...';
const number_of_pages = 1
async function parse(url) {
let response = await fetch(url)
let text = await response.text()
const dom = new JSDOM(text)
return dom.window;
import sys
import openpyxl
worktime = openpyxl.load_workbook(sys.argv[1]).active
absence1 = openpyxl.load_workbook(sys.argv[2]).active
absence2 = openpyxl.load_workbook(sys.argv[3]).active
people = {}
for row in worktime.iter_rows(min_row=2, min_col=1, max_col=6):
@dolohow
dolohow / caldav.py
Last active May 21, 2022 19:42
Manage Nextcloud CalDav calendars
import caldav
def ct(d):
return d.strftime("%Y%m%dT%H%M00")
class Calendar:
def __init__(self, caldav_url, username, password, calendar_name):
@dolohow
dolohow / garmin.js
Created May 2, 2022 10:15
Remove all garmin courses
document.querySelectorAll('.icon-trash').forEach((r, i) => {
setTimeout(() => {
r.click();
document.querySelector('.btn-primary').click();
}, i * 2000)
})
@dolohow
dolohow / full_system_backup.sh
Created February 19, 2021 17:31
btrfs snapshot + rsync backup
#!/bin/bash
# Run
# chmod +x full_system_backup.sh
# touch full_system_backup_exclude
# ./full_system_backup.sh SSH_REMOTE
btrfs subvolume snapshot -r / /mnt/snapshot
mount --bind /boot /mnt/snapshot/boot
@dolohow
dolohow / delete.py
Last active March 4, 2023 14:19
Delete old telegram bot messages from group chat and user commands
#!/usr/bin/python
# Prerequisities
# pip install pyrogram tgcrypto
from datetime import datetime
from pyrogram import Client
# Configure here
@dolohow
dolohow / main.py
Created October 27, 2020 16:44
wp_merge
"""
This module combines input from CSV file with API endpoint data and outputs
result to CSV file.
Example:
Usage:
$ wpe_merge input_csv_file output_csv_file
To show help use:
import curses
import pdb
import random
import time
from curses import wrapper
GAME_BOARD_SIZE = (20, 20)