Skip to content

Instantly share code, notes, and snippets.

View CRTified's full-sized avatar
🤔

Carl Richard Theodor Schneider CRTified

🤔
View GitHub Profile
@CRTified
CRTified / acpi_power_snippet.hs
Created April 19, 2017 22:43
Small snippet for a xmonad acpi logger that does not depend on /usr/bin/acpi or sed
-- dev is the device that shall be read (Like "BAT0")
-- attr are the attributes that are going to be read ("status" for charging status, "capacity" for charged capacity, and so on)
acpi_power :: String -> [String] -> Logger
acpi_power dev attr = io $ do
attrOut <- mapM (\x -> liftIO $ readFile $ sysFsPath ++ x) attr
return $ Just $ filter (/= '\n') (intercalate " " attrOut)
where
sysFsPath = "/sys/class/power_supply/" ++ dev ++ "/"
#################
# CORE SETTINGS #
#################
#
# Zim settings
#
@CRTified
CRTified / xmonad.hs
Created October 1, 2017 18:15
ACPI logger
-- Define acpi power logger
acpi_power :: String -> [String] -> Logger
acpi_power dev attr =
io $ do
attrOut <- mapM (\x -> liftIO $ readFile $ sysFsPath ++ x) attr
return $ Just $ filter (/= '\n') (intercalate " " attrOut)
where
sysFsPath = "/sys/class/power_supply/" ++ dev ++ "/"
file_reader :: String -> Logger
@CRTified
CRTified / 42_iPXE
Created November 2, 2017 21:00
iPXE netboot
#!/bin/sh
BOOTUUID=`blkid -o value $(df /boot | grep "$MOUNTPOINT\$"| cut -f1 -d" ") | head -n 2 | tail -n1`;
ROOTUUID=`blkid -o value $(df / | grep "$MOUNTPOINT\$"| cut -f1 -d" ") | head -n 2 | tail -n1`;
PREFIX=""
if [ "$BOOTUUID" = "$ROOTUUID" ]; then
PREFIX="/boot"
fi;
@CRTified
CRTified / shebang.c
Last active February 6, 2018 19:03
Shebangs
#!/usr/bin/env sh
#if 0
TMPFILE=$(mktemp);
tail -n +10 $0 | gcc -march=native -o $TMPFILE -x c -;
$TMPFILE "${@:1}";
RETVAL=$?
rm $TMPFILE;
exit $RETVAL;
#endif
@CRTified
CRTified / libvirt.nix
Created June 25, 2019 23:13
VFIO Passthrough
{ lib, pkgs, config, ... }:
with lib;
let
cfg = config.virtualisation.libvirtd;
boolToZeroOne = x: if x then "1" else "0";
aclString = with lib.strings;
concatMapStringsSep ",\n " escapeNixString cfg.deviceACL;
in {
bracket
(do
sock <- socket AF_UNIX Stream 0
setSocketOption sock ReuseAddr 1
bind sock $ SockAddrUnix s
listen sock maxListenQueue
return sock
)
(\sock -> do
@CRTified
CRTified / webcam.nix
Last active April 23, 2020 11:00
Webcam Setup with v4l-utils and udev
{
services.udev.extraRules = let
camSettings = pkgs.writeShellScript "setup-v4l2.sh" ''
${pkgs.v4l-utils}/bin/v4l2-ctl \
--device $1 \
--set-fmt-video=width=1920,height=1080,pixelformat=MJPG \ # Set to 1080p
-p 30 \ # Set to 30 FPS
--set-ctrl=power_line_frequency=1 \ # Set to 50Hz power line compensation
--set-ctrl=focus_auto=0 # Disable autofocus
'';
{
services.postgresql = {
enable = true;
ensureDatabases = [ "nextcloud" ];
ensureUsers = [
{ name = "nextcloud";
ensurePermissions."DATABASE nextcloud" = "ALL PRIVILEGES";
}
];
};
nix-build \
--cores 0 \
'<nixos-unstable/nixos>' \
-I nixos-config=image.nix \
-A config.system.build.sdImage \
-o result-cross \
--show-trace