Skip to content

Instantly share code, notes, and snippets.

@ktosiek
ktosiek / flatpak-spawn-host-failure.md
Created May 8, 2021 08:35
flatpak-spawn --host: Portal call failed: org.freedesktop.DBus.Error.ServiceUnknown
$ flatpak enter org.remmina.Remmina
$ flatpak-spawn --host true
Portal call failed: org.freedesktop.DBus.Error.ServiceUnknown

Resolution: use something like Flatseal to give Remmina access to org.freedesktop.Flatpak (not just org.freedesktop.portal.Flatpak)

@ktosiek
ktosiek / find.py
Created December 6, 2020 14:11
Find names of live instances of a Python class
import gc
from itertools import chain
from weakref import WeakKeyDictionary
from signals import Signal
import signals.other_file # noqa
def find_instance_names(cls: type):
results = WeakKeyDictionary()
@ktosiek
ktosiek / chmod.bt
Created September 26, 2020 20:36
bpftrace script for monitoring chmods. I've used this for debugging https://gist.github.com/ktosiek/88bdaa331563164125a5474735cbc8f8
// Monitor all chmods and renames in the system.
// Some of those take an fd, so also track all openat calls to know where the files live.
tracepoint:syscalls:sys_enter_chmod {
printf("%u %s %s %u\n", pid, comm, str(args->filename), args->mode);
}
tracepoint:syscalls:sys_enter_fchmod {
printf("%u %s %u %s %u\n", pid, comm, args->fd, @fds[pid, args->fd], args->mode);
}
@ktosiek
ktosiek / _README.md
Created September 11, 2020 16:16
Workaround for DNS being down after disconnecting from SSTP VPN

Workaround for DNS being down after disconnecting from SSTP VPN

When to use?

When you are using network-manager-sstp with Automatic DNS configuration, but don't have resolveconf installed. This will trigger the bug, and make your /etc/resolv.conf readable only by root.

How to use this fix?

Copy content of ip-up.local.sh to /etc/ppp/ip-up.local, and sudo chmod +x /etc/ppp/ip-up.local.

Why it works?

@ktosiek
ktosiek / monitor_sending_events.sh
Created August 18, 2020 07:47
Send a stream of events to Sentry
#!/usr/bin/env bash
# Heavily based on https://github.com/getsentry/onpremise/blob/fb125a1e4c40701b32f974f6eb2c46a05ca2cd78/test.sh#L80
load_options() {
while [[ -n "$1" ]]; do
case "$1" in
-h | --help) show_help; exit;;
--) shift; SENTRY_DSN=$1;;
*) echo "Unexpected argument: $1. Use --help for usage information."; exit 1;;
@ktosiek
ktosiek / PA profile-set astro-a50-gen4.conf
Last active February 27, 2024 22:46
Astro A50 support on Linux - basic configuration for PulseAudio 13 (tested on Ubuntu's 13.99.1). Install the files and reboot, to make sure udev and PA reloaded :-)
; /usr/share/pulseaudio/alsa-mixer/profile-sets/astro-a50-gen4.conf
[General]
auto-profiles = yes
[Mapping analog-voice]
description = Voice
device-strings = hw:%f,0,0
channel-map = left,right
paths-output = steelseries-arctis-output-chat-common
@ktosiek
ktosiek / results.txt
Created August 25, 2019 19:18
Graphene: serialize 100k objects, v2 vs v3
Graphene 2: 6.852552616968751
Graphene 3: 15.776521055027843
@ktosiek
ktosiek / graphql_raw_result.py
Created January 24, 2019 18:45
Return raw values from python graphql-core, skipping the complete_*_value functions.
import graphql.execution.executor
def complete_value(exe_context, return_type, field_asts, info, path, result):
if isinstance(result, RawGraphQLResult):
return result.value
return _complete_value(exe_context, return_type, field_asts, info, path, result)
class RawGraphQLResult:
def __init__(self, value):
self.value = value
@ktosiek
ktosiek / example.sql
Created June 1, 2017 21:19
primary key vs unique not null
create table unique_test (
id serial primary key,
u integer unique not null, text text
);
insert into unique_test select i as u, i as text
from generate_series(7, 10007) as i;
# explain verbose select u, text from unique_test group by id;
QUERY PLAN
-------------------------------------------------------------------------------
@ktosiek
ktosiek / loud.log
Last active September 23, 2016 15:33
>>> with client.capture_exceptions():
... print(1 + {})