Skip to content

Instantly share code, notes, and snippets.

#!/bin/bash -e
# Personal development environment (PDE) in Linux
# `mkdir /w; cd /w; ./setup-pde.sh`
# Install:
# git curl wget unzip
mkdir -p ~/.config
@sakhnik
sakhnik / print-wifi-qr.py
Created August 18, 2024 17:33
Print QR code for WiFi access point on a thermal printer
#!/usr/bin/env python
ssid = 'my-ssid'
password = '1234567890'
def print_qr(f, data):
# Select the QR code model (2: model 2)
f.write(b'\x1D\x28\x6B\x04\x00\x31\x41\x32\x00')
@sakhnik
sakhnik / setup-pde.ps1
Last active February 17, 2025 11:03
Personal development environment for Windows (neovim + MinGW gcc)
# Setup personal development environment in Windows
Function Test-CommandExists
{
Param ($command)
$oldPreference = $ErrorActionPreference
$ErrorActionPreference = 'stop'
try {if(Get-Command $command){RETURN $true}}
Catch {Write-Host "$command does not exist"; RETURN $false}
Finally {$ErrorActionPreference=$oldPreference}
@sakhnik
sakhnik / orient-summary.py
Last active May 28, 2023 05:06
Calculate multi-stage results in orienteering events in Ukraine
#!/usr/bin/env python
# Підрахунок очок і обчислення місць учасників багатоетапних
# змагань зі спортивного орієнтування.
# Запуск:
# - Експортувати результати етапів у файли e1-results-iof-3.0.xml,…
# - Задати кількість етапів у змінній stage_count
# - Запустити ./summary.py
# Таблицю буде надруковано в текстовому вигляді у стандартний вивід stdout
@sakhnik
sakhnik / add-stages.sql
Last active April 12, 2023 15:48
Increase stage count in Quick Event
INSERT INTO main.stages (id) VALUES (2);
INSERT INTO main.stages (id) VALUES (3);
INSERT INTO main.stages (id) VALUES (4);
INSERT INTO main.classdefs (classId, stageId) SELECT b.classId, 2 FROM main.classdefs b WHERE b.stageId = 1;
INSERT INTO main.classdefs (classId, stageId) SELECT b.classId, 3 FROM main.classdefs b WHERE b.stageId = 1;
INSERT INTO main.classdefs (classId, stageId) SELECT b.classId, 4 FROM main.classdefs b WHERE b.stageId = 1;
INSERT INTO main.runs (competitorId, siId, stageId) SELECT b.competitorId, b.siId, 2 FROM main.runs b WHERE b.stageId = 1;
INSERT INTO main.runs (competitorId, siId, stageId) SELECT b.competitorId, b.siId, 3 FROM main.runs b WHERE b.stageId = 1;
<!DOCTYPE HTML>
<!--
Load schedding reminder
from https://kyiv.yasno.com.ua/schedule-turn-off-electricity
group 3
Anatolii Sakhnik <sakhnik@gmail.com>
Kyiv, 2022
-->
<html>
@sakhnik
sakhnik / sway.log
Last active May 24, 2020 05:16
Sway log while demoing floating shrinked mpv
2020-05-24 08:09:29 - [sway/main.c:152] Linux chbox 5.6.14-arch1-1 #1 SMP PREEMPT Wed, 20 May 2020 20:43:19 +0000 x86_64 GNU/Linux
2020-05-24 08:09:29 - [sway/main.c:168] Contents of /etc/os-release:
2020-05-24 08:09:29 - [sway/main.c:152] NAME="Arch Linux"
2020-05-24 08:09:29 - [sway/main.c:152] PRETTY_NAME="Arch Linux"
2020-05-24 08:09:29 - [sway/main.c:152] ID=arch
2020-05-24 08:09:29 - [sway/main.c:152] BUILD_ID=rolling
2020-05-24 08:09:29 - [sway/main.c:152] ANSI_COLOR="38;2;23;147;209"
2020-05-24 08:09:29 - [sway/main.c:152] HOME_URL="https://www.archlinux.org/"
2020-05-24 08:09:29 - [sway/main.c:152] DOCUMENTATION_URL="https://wiki.archlinux.org/"
2020-05-24 08:09:29 - [sway/main.c:152] SUPPORT_URL="https://bbs.archlinux.org/"
@sakhnik
sakhnik / sway-config
Last active May 24, 2020 05:17
Min sway config to demo the floating shrinked MPV bug May 24, 2020
set $mod Mod4
exec /usr/bin/alacritty
# Use Mouse+$mod to drag floating windows to their wanted position
floating_modifier $mod
# start a terminal
bindsym $mod+Return exec i3-sensible-terminal
@sakhnik
sakhnik / review.js
Created January 25, 2019 20:45
Add a link from a JIRA ticket to code review
// ==UserScript==
// @name Goto review
// @namespace all
// @version 1
// @grant none
// @include https://jira.mycompany.com/browse/*
// ==/UserScript==
(function(){
'use strict'
@sakhnik
sakhnik / magic.cpp
Created November 7, 2018 07:29
Count magic numbers from 000000 to 999999
// vim: set et ts=4 sw=4:
// make: g++ -std=c++14 magic.cpp
#include <iostream>
#include <cassert>
int main()
{
// First count 3-digit combinations yielding different results from 0 to 9+9+9 (28 total)
int counts[28] = {};