Skip to content

Instantly share code, notes, and snippets.

@silverweed
silverweed / asus-kbd-backlight.service
Last active January 12, 2024 18:49
Util scripts
# /usr/lib/systemd/system/asus-kbd-backlight.service
[Unit]
Description=Asus Keyboard Backlight
Wants=systemd-backlight@leds:asus::kbd_backlight.service
After=systemd-backlight@leds:asus::kbd_backlight.service
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/bin/chown root:backlight /sys/class/leds/asus::kbd_backlight/brightness
@silverweed
silverweed / brightness.lua
Last active July 6, 2023 07:55
Awesome 4 rc.lua
---------------------------------------------------
-- Licensed under the GNU General Public License v2
-- * (c) 2016, silverweed
---------------------------------------------------
-- {{{ Grab environment
local tonumber = tonumber
local setmetatable = setmetatable
local string = { gmatch = string.gmatch }
-- }}}
@silverweed
silverweed / countlines.sh
Last active July 6, 2023 07:54
Simple bash script to count effective lines of code for several types of languages
#!/bin/bash
# count lines of code, excluding comments and empty lines.
# (c) silverweed - released under Public Domain
comment_style() {
local CS=''
case $1 in
c|cpp|cs|java*|js) CS='^\s*//|^\s*\*|^\s*/\*' ;;
sh|bash|zsh|ruby|py*) CS='^\s*#' ;;
lua) CS='--' ;;
@silverweed
silverweed / indentcount.hs
Last active July 6, 2023 07:54
Counts line indents in code and shows stats
-- @author silverweed, 2016
-- @license WTFPL
import System.Environment
import System.IO
import Data.List
showIndents input = header ++ (mkList input) ++ "\n"
where
header = "indent: occurrences\n"
mkList = intercalate "\n" . map (\(o,i) -> (show i) ++ ": " ++ (show o)) .
@silverweed
silverweed / hostsup.fast
Last active July 6, 2023 07:53
Checks if LAN hosts are up in parallel
#!/bin/bash
# parallel port check via nc. Takes ~1 s per scanned service, but
# should almost not depend on the number of hosts.
# by silverweed
# FIXME: echo-ing lines from check_host may result in more lines
#+ bloated together.
# file containing the IPs to scan
HOSTLIST="$HOME/.hostlist.txt"
NC="/bin/nc"
// @author silverweed
// Finds all svg files under the current directory and appends a newline to them if they don't end with a newline already.
#define WINDOWS_LEAN_AND_MEAN
#include <windows.h>
#include <stdio.h>
#include <strsafe.h>
BOOL verbose = 0;
@silverweed
silverweed / numspell.rs
Created March 4, 2020 10:54
English number speller
use std::borrow::Cow;
type NumType = u128;
fn read_num_from_args() -> Result<NumType, Cow<'static, str>> {
let mut args = std::env::args();
let program_name = args.next().unwrap();
let num = if let Some(num) = args.next() {
if let Ok(num) = u128::from_str_radix(&num, 10) {
@silverweed
silverweed / makefile
Last active April 20, 2019 19:47
Cuda + SFML test
CC = nvcc
CFLAGS = -std=c++11 --compiler-options -Wall --compiler-options -Wextra --compiler-options -ggdb
LDFLAGS = -lsfml-graphics -lsfml-window -lsfml-system -lcurand
all: test2
%: %.o
$(CC) $(CFLAGS) $^ -o $@ $(LDFLAGS)
%.o: %.cu myutils.hpp
@silverweed
silverweed / inle.svg
Created January 22, 2019 16:55
Inle Icon
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@silverweed
silverweed / .clang-format
Last active June 4, 2018 15:05
vimrc + clang-format
---
Language: Cpp
AccessModifierOffset: -8
AlignAfterOpenBracket: DontAlign
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignEscapedNewlines: Left
AlignOperands: true
AlignTrailingComments: true