Skip to content

Instantly share code, notes, and snippets.

View andsens's full-sized avatar

Anders Ingemann andsens

View GitHub Profile
@andsens
andsens / benchmark-ec2-boottime.sh
Created October 1, 2012 19:02
Starts a single instance and measures the time until SSH connectivity
#!/bin/bash -e
# These need to be set.
#export EC2_HOME="/path/to/ec2-api-tools"
#export AWS_ACCESS_KEY='XXXXXXXXXXXXXXXXXXXX'
#export AWS_SECRET_KEY='XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
#export PATH="$PATH:${EC2_HOME}/bin"
ami_id='ami-123abc12'
availability_zone='eu-west-1a'
keypair="johndoe@example.com"
#!/usr/bin/env bash
# Inspired by https://blog.nimamoh.net/yubi-key-gpg-wsl2/
# Guide:
# Install GPG on windows & Unix
# Add "enable-putty-support" to gpg-agent.conf
# Download wsl-ssh-pageant and npiperelay and place the executables in "C:\Users\[USER]\AppData\Roaming\" under wsl-ssh-pageant & npiperelay
# https://github.com/benpye/wsl-ssh-pageant/releases/tag/20190513.14
# https://github.com/NZSmartie/npiperelay/releases/tag/v0.1
# Adjust relay() below if you alter those paths
@andsens
andsens / bootstrap_homeshick.sh
Last active December 27, 2023 12:47
Script that can set up an entire user account with homeshick automatically
#!/bin/bash -ex
# Paste this into ssh
# curl -sL https://gist.github.com/andsens/2913223/raw/bootstrap_homeshick.sh | tar -xzO | /bin/bash -ex
# When forking, you can get the URL from the raw (<>) button.
### Set some command variables depending on whether we are root or not ###
# This assumes you use a debian derivate, replace with yum, pacman etc.
aptget='sudo apt-get'
chsh='sudo chsh'
@andsens
andsens / dump.sh
Last active October 24, 2023 07:04
Backup all MySQL databases into separate files
#!/bin/sh
## backup each mysql db into a different file, rather than one big file
## as with --all-databases. This will make restores easier.
## To backup a single database simply add the db name as a parameter (or multiple dbs)
## Putting the script in /var/backups/mysql seems sensible... on a debian machine that is
## Create the user and directories
# mkdir -p /var/backups/mysql/databases
# useradd --home-dir /var/backups/mysql --gid backup --no-create-home mysql-backup
## Remember to make the script executable, and unreadable by others
@andsens
andsens / notebook.sh
Last active October 26, 2022 11:38
Bash notebook for nifty things
#!/usr/bin/env bash
# wait for backgrounded jobs and propagate $?>0.
local pid
while read -r pid; do wait "$pid"; done < <(jobs -p)
# wait for backgrounded jobs, propagate $?>0, and exit early on failure.
while (($(jobs -p | wc -l) > 0)); do
if wait -n; then
:
[log]
date = relative
[format]
pretty = shortlog
[pretty]
shortlog = format:%C(auto,yellow)%h%C(auto,magenta)% G? %C(auto,blue)%>(12,trunc)%ad %C(auto,green)%<(7,trunc)%aN%C(auto,reset)%s%C(auto,red)% gD% D
@andsens
andsens / patch-bluetooth-driver.sh
Created February 2, 2021 07:34
Patches the linux bluetooth driver to handle dongles that report they are CSR, but really aren't
#!/usr/bin/env bash
# https://askubuntu.com/questions/1168123/how-do-i-get-my-bluetooth-device-working/1192200#1192200
set -e
SCRIPTDIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
main() {
local kernver
kernver=$(uname -r)
sudo apt update
@andsens
andsens / debian-init.sh
Last active October 5, 2021 09:38
This is a generic init-script, easily modifiable to suit your needs. It uses quite a lot of lsb init-functions and adheres to the lsb standards.
#!/bin/sh
### BEGIN INIT INFO
# Provides: generic-prog
# Required-Start: $local_fs $remote_fs $network
# Required-Stop: $local_fs $remote_fs $network
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Generic Program
# Description: Generic Program is a generic program to do generic things with
### END INIT INFO
@andsens
andsens / Component.tsx
Created April 18, 2020 07:46
FragmentReference reproduce for relay-tools/relay-compiler-language-typescript
import { ComponentPaginationQuery } from "./artifacts/ComponentPaginationQuery.graphql";
import { Component_items$key } from "./artifacts/Component_items.graphql";
export function Component(props: { itemsFragment: Component_items$key }) {
const {
data: { items },
} = usePaginationFragment<ComponentPaginationQuery, Component_items$key>(
graphql`
fragment Component_items on Viewer
@argumentDefinitions(
@andsens
andsens / naval_fate.sh
Created July 29, 2019 22:26
Demonstration of docopt.sh
#!/usr/bin/env bash
DOC="Naval Fate.
Usage:
naval_fate.sh ship <name> move <x> <y> [--speed=<kn>]
naval_fate.sh ship shoot <x> <y>
Options:
--speed=<kn> Speed in knots [default: 10].