Skip to content

Instantly share code, notes, and snippets.

@xentec
xentec / kanshi-save.nu
Last active January 29, 2025 15:06
Generates a kanshi profile from current monitor configuration with the help of Nushell. (https://git.sr.ht/~emersion/kanshi)
#!/usr/bin/env nu
def ind [level: int = 2, symbol: string = " "] {
mut id = ''
if $level > 0 { # fix for single runs of 1..0
for i in 1..$level {
$id += $symbol
}
}
$id + $in
@xentec
xentec / csv2ics.rs
Created July 21, 2024 01:48
Easily generate ICS calendars from an event list in CSV format.
use std::io::Write;
use icalendar::{self as ical, Component, DatePerhapsTime, EventLike};
use csv;
use chrono::{DateTime, Utc};
use serde::Deserialize;
#[derive(Deserialize)]
struct Event {
summary: String,
description: Option<String>,
@xentec
xentec / slight.fish
Last active September 21, 2023 11:15
Highlight syntax of input
#!/usr/bin/env fish
# Example: cat index.html | ./slight.fish html
# cat main.c | ./slight.fish c
set -l syntax $argv[1]
exec kate-syntax-highlighter /dev/stdin \
--syntax $syntax \
--output-format ansi256Colors \
@xentec
xentec / oth-mensa.nu
Last active January 8, 2025 09:46
CLI mensa plan for OTH Regensburg. Requires Nushell to run.
#!/usr/bin/env nu
def fetch [week: int] {
let url = $"https://www.stwno.de/infomax/daten-extern/csv/HS-R-tag/($week).csv"
(
http get --raw $url
| decode "iso-8859-1"
| str replace --regex "\n(\n|(;|\\())" "$2" # fix bullshit
| from csv -s ";"
)
@xentec
xentec / scr-lock.fish
Created October 21, 2021 17:12
Screen locking script for swaylock.
#!/usr/bin/env fish
# You need sway, swaylock, grim, imagemagick, jq and parallel.
set SCREEN (swaymsg -t get_outputs | jq -r .[].name)
for s in $SCREEN;
set -l img /tmp/lock-$s.jpg
set -a IMG $img
set -a PARAMS "-i $s:$img"
end
use reqwest;
use scraper::{Html, Selector};
use structopt::{self, StructOpt};
#[derive(StructOpt)]
#[structopt(name = "w0bm-sav0r")]
struct Opt
{
#[structopt()]
username: String,
#!/bin/env fish
set file_name_base (date "+%Y-%m-%d_%H-%M-%S")
#set url "http://example.com"
#set uploader "rsync"
#set uploader_target "server:/srv/http/"
if [ $WAYLAND_DISPLAY ];
set IS_WAYLAND 1
set SEL_CMD 'slurp' -d
@xentec
xentec / at-mock.ino
Created August 15, 2018 15:33
Arduino AT command mock
#ifndef __AVR_ATmega328P__
# define __AVR_ATmega328P__ // IDE helper
#endif
#include <Arduino.h>
struct cmd_pair
{
const char *query, *response, *err;
};
@xentec
xentec / range.hpp
Last active November 3, 2017 07:47
Slices, C++ style. Helper class to retain sanity
#pragma once
#include <iterator>
template<class Iter>
struct Range
{
using value_type = typename std::iterator_traits<Iter>::value_type;
Range(Iter b): b(b) {}
#!/bin/bash
# general dependencies:
# bash (to run this script)
# util-linux (for getopt)
# procps or procps-ng
# hostapd
# iproute2
# iw
# iwconfig (you only need this if 'iw' can not recognize your adapter)