Skip to content

Instantly share code, notes, and snippets.

@lmas
lmas / refreshmonitor.sh
Created November 1, 2023 21:55
Switch between monitors using xrandr, while running bspwm
#!/bin/sh
# This script tries to automatically switch to a plugged in monitor
# and handles any quirks or issues while doing so.
# Stores current desktop (bspwm switches to some other empty desktop after switch)
desk=$(bspc wm -d | jq ".monitors[].focusedDesktopId")
# Switch active monitor
if xrandr -q | grep -q "HDMI-2 connected"; then
@lmas
lmas / justfile
Created August 28, 2023 10:23
Justfile for Go projects
COVER := ".cover"
TARGETS := "$(go list ./... | grep -v /tmp)"
# Touch go.mod in any dirs you want to "exclude" from go mod tidy,
# for example inside tmp.
# Show available recipes by default
default:
@just --list
# Run tests and log the test coverage
@lmas
lmas / cbr2cbz.sh
Created August 5, 2023 18:26
Convert CBR files to CBZ
#!/bin/sh
set -e pipefail
# Converts all CBR files in current dir to CBZ
# Source:
# https://ubuntuforums.org/showthread.php?t=1273762&s=a388d691ed1d259329dc26304528a056&p=8676006#post8676006
convert() {
dir=$(pwd)
cbr="$1"
@lmas
lmas / divider.go
Last active July 3, 2023 15:10 — forked from peterbourgon/golf.go
Separate chunks of live log output (like spaceror tailer)
package main
import (
"fmt"
"io"
"os"
"strings"
"time"
)
@lmas
lmas / oblique_strategies.md
Created April 2, 2023 17:23
List of "cards" from Oblique Strategies

List of "cards" from Oblique Strategies

(Stolen from David Wicks, who didn't specify any source license)

  • Turn it over.
  • Switch the axes.
  • Think about color.
  • Make it black and white.
  • Use the tangents.
@lmas
lmas / force_rsync.sh
Created December 23, 2022 11:33
Reject anything but rsync through ssh
#!/bin/sh
# Script to reject anything but rsync through ssh.
# Source: https://troy.jdmz.net/rsync/index.html
#
# To force run it on new ssh connections, add:
# command="/home/USER/force_rsync.sh"
# to /home/USER/.ssh/authorized_keys, at the start
# of the key line of enforced user.
@lmas
lmas / vimv
Created July 23, 2022 16:29
Batch rename files using Vi- and friends
#!/bin/sh
# Heavily based on https://github.com/thameera/vimv,
# but ported to POSIX sh with misc. improvements
# and simplifications.
set -eu
panic() {
echo "ERROR: $1" >&2
@lmas
lmas / sec_headers.md
Created July 13, 2022 16:54
HTTP security headers

List of HTTP headers for increased security.

  • /* Strict-Transport-Security max-age=31536060; includeSubDomains; preload
  • /* X-Frame-Options DENY
  • /* X-XSS-Protection 1; mode=block
  • /* X-Content-Type-Options nosniff
  • /* Referrer-Policy strict-origin-when-cross-origin
  • /* Cache-Control public, max-age=604860
  • /* Content-Security-Policy default-src 'self'; object-src 'none'; style-src 'self' 'unsafe-inline';
@lmas
lmas / hacker_news-comments.go
Created May 26, 2021 10:47
Generate an RSS feed of comment links to Hacker News front page
// Copyright © 2021 Alex
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
package main
import (
"flag"
"fmt"
@lmas
lmas / time_to_read.go
Created April 7, 2021 13:07
Calculate the average time to read a text
// Copyright © 2021 Alex
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
package internal
import (
"time"
"unicode"