Skip to content

Instantly share code, notes, and snippets.

@4lun
4lun / s3-redirect-routing-rules.xml
Last active June 4, 2017 11:05
Redirect all requests from an S3 bucket to another domain with explicit path (example redirects all requests to newdomain.com/?referrer=olddomain). Substitute 404 code with 403 if bucket is not publicly readable. Note this all assumes there are no matching files in the bucket.
<RoutingRules>
<RoutingRule>
<Condition>
<HttpErrorCodeReturnedEquals>404</HttpErrorCodeReturnedEquals>
</Condition>
<Redirect>
<HostName>newdomain.com</HostName>
<ReplaceKeyWith>?referrer=olddomain</ReplaceKeyWith>
</Redirect>
</RoutingRule>
@4lun
4lun / letsencrypt-acme-nginx.sh
Last active March 10, 2017 10:30
Generate and install SSL certificate with letsencrypt (for nginx)
export DOMAIN="mydomain.com"
curl https://get.acme.sh | sh
bash --login
mkdir -p /etc/nginx/certs/$DOMAIN/
acme.sh --issue -d $DOMAIN -w /var/www/$DOMAIN/public/
acme.sh --install-cert -d $DOMAIN \
--certpath /etc/nginx/certs/$DOMAIN/cert.pem \
--keypath /etc/nginx/certs/$DOMAIN/key.pem \
--fullchainpath /etc/nginx/certs/$DOMAIN/fullchain.pem \
@4lun
4lun / jenkins-remote-build-trigger.md
Last active July 9, 2019 07:47
How to trigger a remote build via a URL for a Jenkins job
  1. Create new user (e.g. webhook) with the following permissions: Overall > Read, Job > Build, Job > Read & Job > Workspace. Login as the user and get their API token
  2. Under a job, enable "Trigger Builds Remotely" and set an authentication token
  3. Trigger a POST request with the following structure:

http://{USER}:{API_TOKEN}@{JENKINS_URL}/job/{JOB}/build?token={AUTHENTICATION_TOKEN}

@4lun
4lun / ubuntu-minecraft-server.sh
Created August 29, 2017 06:48
Install and run a vanilla Minecraft server (1.7.4) on a new install of Ubuntu 16.04
fallocate -l 1G /swapfile
chmod 600 /swapfile
mkswap /swapfile
swapon /swapfile
echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab
apt update
apt install -y screen default-jdk
wget https://s3.amazonaws.com/Minecraft.Download/versions/1.7.4/minecraft_server.1.7.4.jar
ln -s minecraft_server.1.7.4.jar minecraft_server.jar
screen -S minecraft
@4lun
4lun / pack-list.md
Last active April 19, 2021 16:03
Pack list for travelling and outdoor pursuits

Pack List

General

  • Bag
  • T-shirts
  • Trousers
  • Socks
  • Underwear
  • Travel adapter
  • Plug splitter
  • Various chargers
@4lun
4lun / domain.com
Last active November 20, 2020 20:06
NGINX config for using Let's Encrypt via the acme.sh client, assumes the existence of a `/var/www/.letsencrypt` directory and enforces HTTPS while allowing cert issue/renewal over HTTP
server {
listen 80;
server_name domain.com;
include letsencrypt_params;
}
server {
listen 443;
server_name domain.com;
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
brew install nvm && echo -e "\
NVM_DIR=\"$HOME/.nvm\"\n. \"/usr/local/opt/nvm/nvm.sh\"
" >> ~/.bash_profile && source ~/.bash_profile &&
nvm install v8 --default &&
brew cask install iterm2 chromium visual-studio-code 1password authy alfred
sudo rm -rf Downloads/
ln -s ~/Desktop Downloads
<html>
<head>
<title>~alun</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
body {
box-sizing: border-box;
margin: 0;
padding: 2vh 5vh 4vh;
background: #050505;
@4lun
4lun / useEffectDebug.ts
Created March 21, 2023 12:20
Simple useEffect debug hook for figuring out which dependencies have changed in React
import { DependencyList, EffectCallback, useEffect, useRef } from 'react';
const useEffectDebug = (
effect: EffectCallback,
deps: DependencyList,
label?: string,
) => {
const previous = useRef<DependencyList>();
useEffect(() => {
const changedDepIndexes: number[] = [];
@4lun
4lun / t480s-fix-trackpad.bashrc
Created June 14, 2023 09:28
Trackpad sometimes stops working on T480s under Ubuntu, this restarts the driver which "fixes" it (until it stops again) without a restart
alias fix_trackpad="sudo modprobe -r elan_i2c && sudo modprobe elan_i2c"