Skip to content

Instantly share code, notes, and snippets.

View FlakM's full-sized avatar

Maciej Flak FlakM

View GitHub Profile
@FlakM
FlakM / pager_duty.py
Created February 1, 2024 07:48
Simple script for getting the hours for a month on-call from pager duty
#!/usr/bin/env python3
# Usage: pager_duty.py <MM.YYYY> <User Name>
# Example: ./pager_duty.py 12.2023 "Maciej Flak"
import http.client
import json
import sys
import os
from datetime import datetime, timedelta
@FlakM
FlakM / bpf_aya.rs
Created November 3, 2023 13:55
aya rust bpf userprobe tracing
#![no_std]
#![no_main]
use aya_bpf::helpers::bpf_get_current_pid_tgid;
use aya_bpf::helpers::gen::bpf_ktime_get_ns;
use aya_bpf::helpers::bpf_probe_read_user_str_bytes;
use aya_bpf::helpers::bpf_probe_read_kernel_str_bytes;
use aya_bpf::BpfContext;
use aya_bpf::{
macros::map,
macros::{uprobe, uretprobe},
//! ```cargo
//! [dependencies]
//!
//! axum = "0.6.20"
//! lazy_static = "1.4.0"
//! serde = "1.0.183"
//! serde_json = "1.0.104"
//! tokio = { version = "1.30.0", features = ["full"] }
//! ```
use axum::response::IntoResponse;

Setting up qemu VM using nix flakes

Did you know that it is rather easy to setup a VM to test your NixOs configuration?

Create simple flake:

# flake.nix
{
  inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
@FlakM
FlakM / snippets.scala
Last active October 26, 2022 12:35
Scala snippets
/**
* Copy given string into clipboard.
*
* @param s string that should be copied into clipboard
*/
def yank(s: String) = {
val stringSelection = new java.awt.datatransfer.StringSelection(s)
val clipboard = java.awt.Toolkit.getDefaultToolkit().getSystemClipboard()
clipboard.setContents(stringSelection, null)
}
  1. Is the problem well defined
    1. why is the problem occurring
    2. what is the outcome of the problem
    3. why hasn't it come up earlier
    4. what are possible solutions
  2. can you reproduce it in automated manner
    1. write automated test reproducing error
    2. if a problem is rather statistical, can you measure changes in a very fast and repeatable way
    3. describe manual tests if they were performed
  3. can you check if the change doesn't break anything else
/*
This will result in error:
SQL Error [XX000]: ERROR: unable to encode table key: *tree.DJSON
on insert
*/
CREATE TABLE json_events2 (
uuid STRING PRIMARY KEY,
value JSONB,
event_type STRING,
@FlakM
FlakM / script.sh
Created February 1, 2018 12:23
add png watermark to image
#!/bin/bash
DIR=~/tata
FILES=$DIR/*.JPG
mkdir -p workdir
cp $FILES workdir -a
for f in $DIR/workdir/*.JPG
do
echo "Processing $f file..."