Skip to content

Instantly share code, notes, and snippets.

corecount="${1:-"$(nproc 2>/dev/null || echo 8)"}"
procpids=()
multiproc() {
local cmd="$(printf "%q " "$@")"
eval "$cmd" &
procpids+=($!)
echo "Spawned $!: $cmd"
if [ "${#procpids[@]}" -ge "$corecount" ]; then
local finished=0
@mortie
mortie / auto-screen-rotate.sh
Created November 17, 2018 13:32
Automatically rotate the screen.
#!/bin/sh
# Automatically rotate the screen when the device's orientation changes.
# Use 'xrandr' to get the correct display for the first argument (for example, "eDP-1"),
# and 'xinput' to get the correct input element for your touch screen, if applicable
# (for example, "Wacom HID 486A Finger").
#
# The script depends on the monitor-sensor program from the iio-sensor-proxy package.
if [ -z "$1" ]; then
@mortie
mortie / fan-speed-control.service
Last active February 4, 2022 01:49
Better Dell fan speed control
# Copy fan-speed-control.sh to `/usr/local/bin/fan-speed-control.sh`,
# make sure it's executable with `sudo chmod +x /usr/local/bin/fan-speed-control.sh`.
# Then copy this file `/lib/systemd/system/fan-speed-control.service`,
# then run `sudo systemctl enable --now fan-speed-control`.
# Check that everything looks OK with `sudo journalctl -fe -u fan-speed-control`.
[Unit]
Description=Fan speed control
[Service]
@mortie
mortie / make
Created December 5, 2018 08:41
#!/bin/sh
make_has_flags=0
for arg in "$@"; do
if [ "${arg#-}" = "-" ]; then
make_has_args=1
break
fi
done
cores=$(($(nproc) * 2))
@mortie
mortie / auto-onscreen-keyboard.sh
Created December 6, 2018 18:59
Automatically show an on-screen keyboard.
#!/bin/sh
# Automatically show an on-screen keyboard when enabling tablet mode.
# The script depends on the acpi_listen program from the acpid package,
# and the onboard program from the onboard package.
listener() {
pid=
while read -r line; do
if [ "$line" = 00000001 ]; then
@mortie
mortie / Makefile
Last active December 11, 2018 12:50
Example Makefile
SRC := $(shell find src -name '*.c')
HDR := $(shell find src -name '*.h')
OBJ := $(patsubst src/%.c,obj/%.o,$(SRC))
DEP := $(patsubst src/%.c,dep/%.d,$(SRC))
PKG_CONFIG ?= pkg-config
STRIP ?= strip
TARGET := my-project
VERSION = $(shell git describe --long --all --dirty)
@mortie
mortie / log.good.txt
Last active December 21, 2018 16:25
kernel venus logs
[ 133.464103] wlan: SCAN COMPLETED: scanned AP count=22
[ 134.686709] 1b0c000.qcom,cci supply qcom,gdscr-vdd not found, using dummy regulator
[ 134.687340] msm_cci_init:1015: hw_version = 0x10000008
[ 135.256489] 1b0c000.qcom,cci supply qcom,gdscr-vdd not found, using dummy regulator
[ 135.256891] msm_cci_init:1015: hw_version = 0x10000008
[ 135.439496] helper_vb2_buf_init, list_add_tail(ffff80001d95e208, ffff80002e077850)
[ 135.440181] helper_vb2_buf_init, list_add_tail(ffff80001d95fa08, ffff80002e077850)
[ 135.446840] helper_vb2_buf_init, list_add_tail(ffff8000176a6e08, ffff80002e077850)
[ 135.454212] helper_vb2_buf_init, list_add_tail(ffff8000176a4a08, ffff80002e077850)
[ 135.610874] helper_vb2_buf_init, list_add_tail(ffff8000176f6608, ffff80002e077850)
# /etc/systemd/logind.conf
[Login]
#HandleLidSwitch=suspend
HandleLidSwitch=ignore
#HandleLidSwitchExternalPower=suspend
HandleLidSwitchExternalPower=ignore
@mortie
mortie / build.sh
Last active April 3, 2019 18:20
Compile Electron
#!/bin/bash
set -e
# Prerequesites:
# * https://github.com/electron/electron/blob/v4.1.3/docs/development/build-instructions-linux.md#prerequisites
# * libav{codec,format,util}-dev libxss-dev libkrb5-dev
# This script downloads and builds Electron.
# Everything will happen in a 'work' directory relative to the path of the build.sh file,
# and when Electron is built, it will end up in 'work/electron-gn/src/out/Release/electron'.
let depth = 0;
// https://www.npmjs.com/package/hsv-rgb
function rgb(h, s, v) {
var s = s / 100, v = v / 100
var c = v * s
var hh = h / 60
var x = c * (1 - Math.abs(hh % 2 - 1))
var m = v - c