Skip to content

Instantly share code, notes, and snippets.

@spajak
spajak / .dircolors
Last active March 8, 2022 17:09
Improved ~/.dircolors for dark background. Color changes from Debian defaults are mostly cosmetic. Added a few popular multimedia extensions and removed the archaic ones.
# Improved ~/.dircolors designed for dark background
# Configuration file for dircolors, a utility to help you set the
# LS_COLORS environment variable used by GNU ls with the --color option.
# Copyright (C) 1996-2018 Free Software Foundation, Inc.
# Copying and distribution of this file, with or without modification,
# are permitted provided the copyright notice and this notice are preserved.
# The keywords COLOR, OPTIONS, and EIGHTBIT (honored by the
# slackware version of dircolors) are recognized but ignored.
@spajak
spajak / ccs.py
Last active June 3, 2022 01:20
Generate console colors scheme for Windows Console, Windows Terminal and Putty in a form of .reg files (Windows Registry) and json
# Console colors for Windows
# --------------------------
# Script outputs console color scheme files for Windows in the followng formats:
# <win>.reg file - Windows legancy console colors
# <putty>.reg file - Putty console colors
# <concfg>.json - concfg.json scheme
# <wt>.json - Windows Terminal color scheme
#
# Windows reg file is for default console. Putty sessions are configurable below, see: `puttySessions` variable.
# Feel free to change the colors. Provided palette is a simple and reasonable default for dark background.
@spajak
spajak / serialization.php
Last active October 16, 2021 03:19
PHP serializers (native, json, igbinary, msgpack) performance and size comparison (for session like, small, arrays dataset)
<?php
define('ITERATIONS', 1000000);
# [igbinary serializer PHP extension](https://github.com/igbinary/igbinary)
if (!extension_loaded('igbinary')) {
throw new DomainException('Required PHP module "igbinary" is not loaded');
}
# [MessagePack binary serializer PHP extension](https://github.com/msgpack/msgpack-php)
@spajak
spajak / systemd-user.sh
Last active October 6, 2019 16:55
My steps to enable systemd manager for any user (In this case www-data)
# Create user runtime directory
sudo install -d -o www-data -g www-data -m 0700 /run/user/`id -u www-data`
# Start user manager
sudo systemctl start user@`id -u www-data`
# Optionally enable lingering (User manager is spawned for the user at boot and kept around after logouts).
sudo loginctl enable-linger www-data
# Test it
@spajak
spajak / mpeg2mkv-steps.ps1
Last active February 29, 2024 20:35
Convert/rip DVD to MKV. Encode to MPEG-4 & merge into MKV - all without GUI, only command line tools
# My steps to:
# Convert DVD Video to MPEG-4 in MKV without GUI, using only CLI (Command Line Interface) tools.
# No need for MeGUI, Avisynth, Handbrake etc..
# ------------------------------------------------------------------------------
# Tools needed: `mediainfo`, `ffmpeg` & `ffprobe`, `x264`, `mkvmerge`, `mplayer` (optional).
# Google for them. Use latest versions. Windows tip: avoid Cygwin and get
# the official builds, x64, when possible.
# Before start use `mediainfo` & `ffprobe` and note down informations about the source material:
@spajak
spajak / ogm-chapters.py
Last active December 7, 2022 08:44
Simple OGM chapters generator for MKVToolNix
# Simple OGM chapters generator for MKV Video
# -------------------------------------------
# Use it like this:
# $ python ogm-chapters.py times.txt [chapters.txt]
# Where times.txt contains timestamps separated by a whitespace or comma
import sys
from pathlib import Path
import re
@spajak
spajak / Task.php
Last active June 28, 2019 17:06
PHP long running task with MySQL transaction + progress + state
<?php
/**
* Long running task with single MySQL transaction. Only one task with the same name
* can be running at a time. Next executed task waits untill previous finishes, or
* doesn't wait, but throws DomainException instead.
*
* Use it like so:
* $task = new Task('foo', $db);
* $task->run();
@spajak
spajak / entware-ng.sh
Last active June 19, 2019 10:12
Bootstrap Entware-ng on Synology DS
#!/bin/bash
# Script installs Entware-ng (https://github.com/Entware/Entware-ng)
# on Synology DSM 6.2 under /opt directory.
# Must be run with sudo. Can be used as a scheduled task on system boot.
printf -- "---------------------------\n"
printf -- "| Installing Entware-ng.. |\n"
printf -- "---------------------------\n"
@spajak
spajak / php-error-logging.php
Last active June 30, 2019 12:55
PHP 7 runtime errors/exceptions handling done right
<?php
/**
* Simple, custom, bulletproof PHP 7 runtime errors/exceptions handling done right (I hope so :).
* By handling I mean logging to systemd journal or stderr, and die if any exception,
* error, warning, and even notice or strict occurs. This is not all-in-one
* or an ultimate solusion, but a good base to start with.
* Logs go to stderr or systemd journal (recommended, but optional). Systemd extension
* for PHP can be found at https://github.com/systemd/php-systemd
*/
@spajak
spajak / fib.py
Created June 11, 2019 17:07
Fibonacci sequence iterator in Python
class Fib:
"""Iterator that yields numbers in the Fibonacci sequence"""
def __init__(self, max):
self.max = max
def __iter__(self):
self.a = 0
self.b = 1
return self