Skip to content

Instantly share code, notes, and snippets.

#!/bin/bash
last_hsvol=64
while true; do
hsvol=$(headsetcontrol -o json | jq '.devices[0].chatmix')
vol=$(echo "scale= 5; $hsvol / 128 * 100" | bc)
if (( $hsvol != $last_hsvol )); then
wpctl set-volume @DEFAULT_SINK@ $vol% -l 1.0
last_hsvol=$hsvol
@Nama
Nama / sway_workspaces.py
Last active January 27, 2023 18:54
Restore workspaces in sway to displays and move applications to saved workspaces. Maintained in its own repo now: https://github.com/Nama/sway-workspaces
#!/usr/bin/python
'''
* setup displays first, e.g. with wdisplay
* run after setting up your displays `python sway_workspaces.py save <profilename>`
* repeat for every display setup
* setup kanshi and make it run `python sway_workspaces.py load <profilename>`
Multiple windows of an application/class aren't handled. No idea how to do so.
Had to alter the default tree, so the outputs are not the ports.
@Nama
Nama / TwitFix.plugin.js
Last active February 1, 2024 19:24
TwitFix link instead of twitter with betterdiscord
/**
* @name TwitFix
* @version 1.5
* @authorLink https://github.com/Nama
* @website https://yamahi.eu
* @description Send twitter links with preview
* @source https://gist.github.com/Nama/e61a13c29717b8eff48fa3ff41fc4ddd
* @updateUrl https://gist.githubusercontent.com/Nama/e61a13c29717b8eff48fa3ff41fc4ddd/raw/
*/
@Nama
Nama / monitor_away.ps1
Last active January 25, 2022 10:37
We can't have nice things cause of anti-piracy (again). Sound isn't send over HDMI if no video is sent. Auto turning off displays is not convenient. This script starts the screensaver if the HDMI audio output is currently the default device. Enable screensaver (set time to 999) and disable displays turning off. Checks for playback activity.
# https://stackoverflow.com/a/39319540
Add-Type @'
using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
namespace PInvoke.Win32 {
public static class UserInput {
[DllImport("user32.dll", SetLastError=false)]
private static extern bool GetLastInputInfo(ref LASTINPUTINFO plii);
[StructLayout(LayoutKind.Sequential)]
#!/bin/bash
#/etc/udev/rules.d/95-monitor-hotplug.rules
#KERNEL=="card0", SUBSYSTEM=="drm", ENV{DISPLAY}=":0", ENV{XAUTHORITY}="/home/yama/.Xauthority", RUN+="/home/yama/scripts/monitor-hotplug.sh"
# udevadm control --reload-rules && udevadm trigger
xrandr | grep -q "DP2-8 connected"
connected1=$?
xrandr | grep -q "DP2-1-8 connected"
@Nama
Nama / i3.py
Created November 7, 2019 15:39
#!/usr/bin/python
import os
import i3ipc
import sys
import pickle
PATH = os.path.expanduser("~/.config/i3/workspace_mapping")
def showHelp():
@Nama
Nama / arch_system_upgrade.py
Created November 7, 2019 14:06
update and notify about updates
#!/usr/bin/python
from sh import hostname, checkupdates, yay, touch
from tg_bot import send
chatid = '000000000'
updates = checkupdates()
if updates:
@Nama
Nama / rss_noc.py
Created September 29, 2016 22:19
Parse the news site https://noc.rub.de and serve the headlines as RSS feeds. Using Flask
#!/usr/bin/env python
from flask import Flask, request, url_for
from werkzeug.contrib.atom import AtomFeed
from html.parser import HTMLParser
import urllib.request
from datetime import datetime
app = Flask(__name__)
url_noc = 'https://noc.rub.de/cgi-bin/status/'
@Nama
Nama / hibernate.sh
Last active June 11, 2016 12:35
Script for Arch Linux. Hibernate can't continue if a new kernel is installed. So this script instead suggests to shutdown. Put in /etc/profile.d/ and run via command "hibernate". Should work with LTS and GRSEC kernels, too.
#!/bin/bash
KERNEL="/boot/vmlinuz-linux"
hibernate() {
grep $(uname -r) $KERNEL* > /dev/null
if [[ $? == 0 ]]; then
echo "Newest kernel is running, hibernating..."
systemctl hibernate
else
echo "New kernel is installed, can't continue after hibernate..."
@Nama
Nama / mnthdd.sh
Last active June 8, 2016 11:40
Easy mount devices encrypted with cryptsetup. I use this code in /etc/profile.d/
#!/bin/bash
mnthdd() {
# The full mount-path is put together bei $MOUNTPATH and $DRIVES
# In this example it would be /media/ + your parameter
MOUNTPATH="/media/"
# /etc/fstab
## hdd1
#/dev/mapper/hdd1 /media/hdd1 ext4 noauto,defaults 0 0
#