Skip to content

Instantly share code, notes, and snippets.

View limitedeternity's full-sized avatar
🔭
Ищу смыслы

Vyacheslav Bespalov limitedeternity

🔭
Ищу смыслы
View GitHub Profile
@limitedeternity
limitedeternity / random_field.sql
Last active January 25, 2024 18:50
Field value in a random PostgreSQL table record
create table if not exists scientist (id integer primary key, firstname varchar(100), lastname varchar(100));
insert into scientist (id, firstname, lastname) values (1, 'albert', 'einstein') on conflict DO NOTHING;
insert into scientist (id, firstname, lastname) values (2, 'isaac', 'newton') on conflict DO NOTHING;
insert into scientist (id, firstname, lastname) values (3, 'marie', 'curie') on conflict DO NOTHING;
CREATE OR REPLACE FUNCTION random_record(
table_name anycompatible
)
RETURNS SETOF anycompatible
@limitedeternity
limitedeternity / .nanorc
Last active December 18, 2023 18:22
My Nano config (.nanorc)
# Enable built-in syntax highlighting
include "/usr/share/nano/*.nanorc"
include "/usr/share/nano/extra/*.nanorc"
# Make the Home key smarter. When Home is pressed anywhere but at the
# very beginning of non-whitespace characters on a line, the cursor
# will jump to that beginning (either forwards or backwards). If the
# cursor is already at that position, it will jump to the true
# beginning of the line.
set smarthome
@limitedeternity
limitedeternity / MessageTypes.h
Last active November 22, 2023 13:57
Locate C++ classes marked with __attribute__((annotate("..."))) using libclang
#pragma once
#include <string>
#define EXPAND(...) EXPAND4(EXPAND4(EXPAND4(EXPAND4(__VA_ARGS__))))
#define EXPAND4(...) EXPAND3(EXPAND3(EXPAND3(EXPAND3(__VA_ARGS__))))
#define EXPAND3(...) EXPAND2(EXPAND2(EXPAND2(EXPAND2(__VA_ARGS__))))
#define EXPAND2(...) EXPAND1(EXPAND1(EXPAND1(EXPAND1(__VA_ARGS__))))
#define EXPAND1(...) __VA_ARGS__
#define FOR_EACH(macro, ...) \
@limitedeternity
limitedeternity / Pipfile
Last active August 6, 2023 14:37
Determine workload from ITMO study plan
[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"
[packages]
pandas = "2.0.3"
openpyxl = "3.1.2"
tabulate = "0.9.0"
scipy = "1.10.1"
@limitedeternity
limitedeternity / post-commit
Created July 13, 2023 15:19
These hooks enforce commits to be signed, because most Git GUI clients don't support x509 signatures
#!/bin/bash
export LC_ALL=en_US.utf8
set -o nounset
set -o pipefail
set +o histexpand
RED='\033[0;31m'
YELLOW='\033[33m'
GREEN='\033[0;32m'
@limitedeternity
limitedeternity / WinMinimize.ahk
Last active June 22, 2023 09:49
Supercharged Win+{Up,Down} (AutoHotkey v2)
#Requires AutoHotkey v2.0
#SingleInstance Force
#NoTrayIcon
MINIMIZED := []
STATE_MINIMIZED := -1
return
; Win + Shift + Down = Minimize Window
@limitedeternity
limitedeternity / zip_texts.py
Last active March 14, 2023 17:52
Functional 'zip' for text files
from argparse import ArgumentParser
from itertools import repeat
from pathlib import Path
import shutil
def main(args):
invalid_sources = filter(lambda path: not path.is_file(), args["source"])
if (source := next(invalid_sources, None)):
print("Provided source doesn't exist: %s" % source.absolute())
@limitedeternity
limitedeternity / plant_dll.py
Last active February 20, 2023 11:03
A script for planting debug component DLLs instead of release ones
from argparse import ArgumentParser
import logging
from pathlib import Path
import shutil
DLL_LOCATIONS = (
Path("C:\Program Files (x86)\Common Files\SecurIT"),
Path("C:\Program Files (x86)\Zecurion\Endpoint")
)
@limitedeternity
limitedeternity / Monorepo.ps1
Last active March 13, 2023 19:08
Adds a git alias for running commands in all repositories of a monorepository
function New-Monorepo
{
[CmdletBinding()]
Param(
[Parameter(Mandatory, Position=0)]
[string] $Path
)
Process
{
@limitedeternity
limitedeternity / pow2_equiv.v
Last active December 22, 2022 10:09
"Bitwise hacks" proofs
Require Import Coq.Init.Nat Coq.Arith.PeanoNat Coq.Numbers.NatInt.NZPow Coq.Numbers.NatInt.NZBits Lia.
Theorem shiftr_div_pow2 : forall (a n : nat),
shiftr a n = a / 2 ^ n.
Proof.
intros. Nat.bitwise. rewrite Nat.shiftr_spec'. symmetry. apply Nat.div_pow2_bits.
Qed.
Lemma shiftl_mul_pow2 : forall (a n : nat),
shiftl a n = a * 2 ^ n.