Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Chris Jones cmsj

🏠
Working from home
View GitHub Profile
@cmsj
cmsj / Code.gs
Created August 25, 2023 09:30
Google Script thread muter
View Code.gs
// Enforce thread muting
// When you mute a thread in Gmail, it adds a "Muted" label
// Unfortunately, it doesn't really completely mute the thread - e.g. emails added to the thread will still be marked as unread and show up against folder counts
//
// This script will ensure that all emails appearing on muted threads, will be marked read, and archived.
//
// By default it will only look for emails that are less than 3 days old, to limit the size of the query results. You can adjust that if you want to
var age_max="3d"
function enforceMutes() {
@cmsj
cmsj / ansible-dropbear-initramfs.md
Last active August 26, 2023 03:29
Ansible to add dropbear (ie an SSH server) to your initramfs, for unlocking encrypted root partitions
View ansible-dropbear-initramfs.md

This is some Ansible (for Ubuntu 22.04) to install and configure your initramfs to run dropbear (ie an SSH server).

Super handy if you have an encrypted root partition and don't have physical access to the machine to enter the encryption passphrase on the console.

Notes:

  • You'll need to put your actual public SSH keys, instead of the blahblah placeholder I have here
  • I set dropbear to run on port 31337 so the hostkey doesn't clash with the main OS' key in your ~/.ssh/known_hosts
  • This expects to be able to trigger two Ansible handlers when it makes changes, they are listed separately at the bottom
  • You'll need to change the GRUB_CMDLINE_LINUX_DEFAULT line below to have the actual IP/gateway/NIC/hostname you want the kernel to configure
  • After you ssh in when the machine is booting, the command to actually unlock the root filesystem is: cryptroot-unlock
@cmsj
cmsj / automatic-zfs-volume-keys.yaml
Created August 24, 2023 23:55
Loading zfs encryption keys at boot
View automatic-zfs-volume-keys.yaml
- name: Install ZFS tools/utilities
apt:
name: "{{ item }}"
state: present
with_items:
- zfsutils-linux
- name: Install tank encryption key
copy:
dest: /etc/zfs/tank.key
@cmsj
cmsj / smbpassword-ansible.md
Created August 24, 2023 23:37
Setting Samba passwords with Ansible
View smbpassword-ansible.md

Scenario: You want to create a user in Linux, and set a Samba password for it, all from Ansible:

Notes:

  • This will not update the Samba password if you change the variable.

To create the encrypted vault string, run: ansible-vault encrypt_string --ask-vault-password 'some_password'

- name: Create OS group
@cmsj
cmsj / bpytop-console.yml
Last active August 24, 2023 23:17
Replace getty on tty1 with bpytop, using Ansible, on Ubuntu 22.04
View bpytop-console.yml
- name: Install bpytop
apt:
name: bpytop
state: present
- name: Create bpytop configuration directory
ansible.builtin.file:
path: /opt/bpytop
state: directory
owner: nobody
@cmsj
cmsj / cmsj_docker_tool.sh
Created August 24, 2023 10:13
cmsj_docker_tool.sh
View cmsj_docker_tool.sh
#!/bin/bash
# A simple tool for managing docker containers
# Drop this in your path somewhere and chmod +x it, then create symlinks to it with the names:
# clog - show the logs for a container
# cblip - restart a container and then show its logs
# cgo - run a command inside a container (defaults to /bin/sh)
# Usage for each is: <command> CONTAINER_NAME
CMD="$(basename $0)"
@cmsj
cmsj / slm.py
Created April 19, 2023 17:04
Quick hack to run SLM locally
View slm.py
# pip install the following, and make sure you have a pytorch that supports CUDA.
# accelerate
# bitsandbytes
# transformers
# IPython
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
from IPython.display import Markdown, display
View slm.py
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
from IPython.display import Markdown, display
def hr(): display(Markdown('---'))
def cprint(msg: str, color: str = "blue", **kwargs) -> str:
if color == "blue": print("\033[34m" + msg + "\033[0m", **kwargs)
elif color == "red": print("\033[31m" + msg + "\033[0m", **kwargs)
elif color == "green": print("\033[32m" + msg + "\033[0m", **kwargs)
elif color == "yellow": print("\033[33m" + msg + "\033[0m", **kwargs)
@cmsj
cmsj / kyber.lua
Last active February 13, 2023 09:47
Proxmark3 (iceman) Lua script to easily write Galaxy's Edge kyber crystal data to EM4305 rfid tags
View kyber.lua
local cmds = require('commands')
local getopt = require('getopt')
local bin = require('bin')
local utils = require('utils')
local cmds = require('commands')
local ansicolors = require('ansicolors')
copyright = 'Various copyrights - Based on hf_mfu_amiibo_sim.lua'
author = 'Chris Jones <cmsj@tenshu.net>'
version = 'v2.0'
View led_effects.ino
#include <Adafruit_NeoPixel.h>
#include <Adafruit_DotStar.h>
// led_effects
// by Chris Jones <cmsj@tenshu.net>
// Released under the MIT License.
// RGB LED built in to the Trinket M0
Adafruit_DotStar dot = Adafruit_DotStar(1, INTERNAL_DS_DATA, INTERNAL_DS_CLK, DOTSTAR_BGR);