Skip to content

Instantly share code, notes, and snippets.

Avatar

Alun Davey 4lun

View GitHub Profile
@4lun
4lun / domain.com
Last active Nov 20, 2020
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
View domain.com
server {
listen 80;
server_name domain.com;
include letsencrypt_params;
}
server {
listen 443;
server_name domain.com;
@4lun
4lun / reddit-unsubscribe-all-subreddits.js
Last active Oct 12, 2020
Unsubscribe from all subreddits
View reddit-unsubscribe-all-subreddits.js
// Visit https://www.reddit.com/subreddits/ and run the following in console (browser dev tools)
// Wait until all the buttons have visibly toggled, refresh page to confirm.
$('.fancy-toggle-button .remove').each(function(i, elem) { setTimeout(function(){ $(elem).trigger('click'); }, i*500) });
@4lun
4lun / class-names.css
Last active Nov 17, 2019
Ideas for CSS class names
View class-names.css
.box,
.sector,
.section,
.quadrant,
.crate,
.container,
.page,
.content,
.body,
.head,
View index.html
<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 / str.slug.js
Created Dec 10, 2014
Slug function in JS matching the Laravel 4 implementation (Str::slug) - Note: does not include the transliteration of a UTF-8 value to ASCII
View str.slug.js
function slug(title, separator) {
if(typeof separator == 'undefined') separator = '-';
// Convert all dashes/underscores into separator
var flip = separator == '-' ? '_' : '-';
title = title.replace(flip, separator);
// Remove all characters that are not the separator, letters, numbers, or whitespace.
title = title.toLowerCase()
.replace(new RegExp('[^a-z0-9' + separator + '\\s]', 'g'), '');
@4lun
4lun / jenkins-remote-build-trigger.md
Last active Jul 9, 2019
How to trigger a remote build via a URL for a Jenkins job
View jenkins-remote-build-trigger.md
  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}

View macos-dev-setup.sh
/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
@4lun
4lun / pack-list.md
Last active Jul 3, 2018
Pack list for travelling and outdoor pursuits
View pack-list.md

Pack List

General

  • Bag
  • T-shirts
  • Trousers
  • Socks
  • Underwear
  • Travel adapter
  • Plug splitter
  • Various chargers
@4lun
4lun / ubuntu-minecraft-server.sh
Created Aug 29, 2017
Install and run a vanilla Minecraft server (1.7.4) on a new install of Ubuntu 16.04
View ubuntu-minecraft-server.sh
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 / s3-redirect-routing-rules.xml
Last active Jun 4, 2017
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.
View s3-redirect-routing-rules.xml
<RoutingRules>
<RoutingRule>
<Condition>
<HttpErrorCodeReturnedEquals>404</HttpErrorCodeReturnedEquals>
</Condition>
<Redirect>
<HostName>newdomain.com</HostName>
<ReplaceKeyWith>?referrer=olddomain</ReplaceKeyWith>
</Redirect>
</RoutingRule>
You can’t perform that action at this time.