Skip to content

Instantly share code, notes, and snippets.

View karolyi's full-sized avatar
🏠
Working from home

László Károlyi karolyi

🏠
Working from home
View GitHub Profile
#!/usr/bin/env bash
STATE='ON'
if [[ $1 == 'off' ]]; then
STATE='OFF'
fi
STR_1='<?xml version="1.0" encoding="UTF8"?><SMARTPLUG id="edimax"><CMD id="setup"><Device.System.Power.State>'
STR_2='</Device.System.Power.State></CMD></SMARTPLUG>'
@karolyi
karolyi / pacman-autoremove.sh
Created October 22, 2021 11:25
pacman autoremove
#!/usr/bin/env sh
pacman -Rs $(pacman -Qtdq)
@karolyi
karolyi / start-jackd.sh
Last active February 6, 2022 10:57
Start jackd properly
#!/usr/bin/env bash
set -x
killall -9 jackdbus
qjackctl &
sleep 2
while true;
do
@karolyi
karolyi / activate.fish
Last active July 10, 2020 17:43
Set PYTHONEXECUTABLE for OSX/DARWIN Homebrew Python venv
# This file must be used with ". bin/activate.fish" *from fish* (http://fishshell.org)
# you cannot run it directly
# --- $PYTHONEXECUTABLE SETTING: See https://stackoverflow.com/a/53190037/1067833 ---
function deactivate -d "Exit virtualenv and return to normal shell environment"
# reset old environment variables
if test -n "$_OLD_VIRTUAL_PATH"
set -gx PATH $_OLD_VIRTUAL_PATH
set -e _OLD_VIRTUAL_PATH
@karolyi
karolyi / pkgmirror-revalidator.py
Created May 3, 2020 10:15
Revalidating nginx reverse-proxied FreeBSD pkg mirrors
#!/usr/bin/env python3.7
from argparse import ArgumentParser
from hashlib import sha256
from http.client import HTTPResponse
from io import BytesIO
from json import loads
from pathlib import Path
from subprocess import check_output
from sys import exit
proxy_cache_path /var/cache/pkgmirror/ max_size=10G inactive=1y manager_sleep=10m keys_zone=pkgirror_meta_zone:10m;
server {
listen *:80;
listen [::]:80;
server_name pkgmirror._yourdomain_;
autoindex on;
access_log /var/log/nginx/pkgmirror._yourdomain_-access.log combined2 buffer=32k flush=5m;
error_log /var/log/nginx/pkgmirror_yourdomain_-error.log info;
@karolyi
karolyi / backup-mariadb.sh
Last active April 19, 2023 12:14
Fast backup/restore mysql databases
#!/usr/bin/env bash
mariabackup --stream=xbstream --backup --user root|pigz >mariadb-backup.gz
@karolyi
karolyi / multitail.conf
Last active August 20, 2018 20:37
Uwsgi syntax for multitail
# ----
#
# uwsgi log https://gist.github.com/karolyi/3032020b4d62c6fd0b9148db1a242548
colorscheme:uwsgi:https://uwsgi-docs.readthedocs.io/en/latest/
# HTTP method highlighting
cs_re_s:cyan:\{[0-9]+ vars in [0-9]+ bytes\} \[.*\] (GET)
cs_re_s:magenta:\{[0-9]+ vars in [0-9]+ bytes\} \[.*\] (POST|PUT|DELETE|OPTIONS)
# Response time highlighting: >500: yellow, >750ms: magenta-bold, >1000ms: red-bold
cs_re_val_bigger:red,,bold:1000:generated [0-9]+ bytes in ([0-9]+) msecs
cs_re_val_bigger:magenta,,bold:750:generated [0-9]+ bytes in ([0-9]+) msecs
@karolyi
karolyi / django.py
Created April 12, 2018 13:10
Register Length() to django queryset
from django.db.models import CharField
from django.db.models.functions import Length
CharField.register_lookup(Length, 'length')
result = MyModel.objects.filter(text__length__gt=10)
@karolyi
karolyi / 0001_initial.py
Created November 4, 2017 01:10
Modify column in django migration
# -*- coding: utf-8 -*-
# Generated by Django 1.11.6 on 2017-10-19 13:31
from __future__ import unicode_literals
from django.conf import settings
from django.db import connection, migrations, models
from django.db.migrations import RunPython
PROJECT_NAMESPACE = settings.PROJECT_NAMESPACE