Skip to content

Instantly share code, notes, and snippets.

View maxmilton's full-sized avatar
✌️
(@^◡^)

Max Milton maxmilton

✌️
(@^◡^)
View GitHub Profile
#!/bin/sh -e
# A Simple Script to Create systemd-nspawn Alpine Container
# https://wildwolf.name/a-simple-script-to-create-systemd-nspawn-alpine-container/
MIRROR="http://dl-cdn.alpinelinux.org/alpine"
#VERSION="latest-stable"
VERSION="edge"
[ "$(id -u)" -ne "0" ] && echo "You need to be root" >&2 && exit 1
@maxmilton
maxmilton / zig-up
Last active December 21, 2022 22:57
Zig master branch build version updater bash script.
#!/bin/bash
set -Eeuo pipefail
trap cleanup SIGINT SIGTERM ERR EXIT
# Zig Update; Check and download the latest zig master branch build
# Inspired by: https://gist.github.com/MasterQ32/1f27081d8a7dd109fc290bd6729d97a8
ROOT_DIR=/usr/local/bin
TMP_DIR=/tmp/zig-up
REPO_URL=https://ziglang.org/download/index.json
@maxmilton
maxmilton / cloudflare-trace.js
Last active November 16, 2021 00:16
Get client IP etc. from cloudflare trace (client-side; in the browser)
// XXX: Use '/cdn-cgi/trace' if the site is on cloudflare to avoid CORS issues
// otherwise can use 'https://www.cloudflare.com/cdn-cgi/trace'
const trace = await fetch('https://www.cloudflare.com/cdn-cgi/trace')
.then(x=>x.text())
.then(x=>new URLSearchParams(x.replace(/\n/g, '&')));
console.log(trace.get('ip'))
// ------------------------------------------------------------
@maxmilton
maxmilton / pagination_example.sql
Created August 15, 2021 06:17 — forked from ssokolow/pagination_example.sql
Reasonably efficient pagination without OFFSET (SQLite version)
-- Reasonably efficient pagination without OFFSET
-- SQLite version (Adapted from MS SQL syntax)
-- Source: http://www.phpbuilder.com/board/showpost.php?p=10376515&postcount=6
SELECT foo, bar, baz, quux FROM table
WHERE oid NOT IN ( SELECT oid FROM table
ORDER BY title ASC LIMIT 50 )
ORDER BY title ASC LIMIT 10
@maxmilton
maxmilton / script-template.sh
Created February 1, 2021 02:42 — forked from m-radzikowski/script-template.sh
Minimal safe Bash script template - see the article with full description: https://betterdev.blog/minimal-safe-bash-script-template/
#!/usr/bin/env bash
set -Eeuo pipefail
trap cleanup SIGINT SIGTERM ERR EXIT
script_dir=$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd -P)
usage() {
cat <<EOF
Usage: $(basename "${BASH_SOURCE[0]}") [-h] [-v] [-f] -p param_value arg1 [arg2...]
! brave://adblock/
! https://help.eyeo.com/adblockplus/how-to-write-filters
! TODO: Add || to the begining of exceptions where it makes sense
! Unwanted or bandwidth draining resources
*$font
*$media
*$object
*$other
const webpack = require('webpack');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const config = require('sapper/webpack/config.js');
const { svelteMinifyHtml, sveltePostcss } = require('./utils.js');
const mode = process.env.NODE_ENV;
const isDev = mode === 'development';
module.exports = {
entry: config.client.entry(),
@maxmilton
maxmilton / gist:60203b02683769adb531a287f9b7c0ae
Created March 7, 2018 17:33 — forked from lttlrck/gist:9628955
rename git branch locally and remotely
git branch -m old_branch new_branch # Rename branch locally
git push origin :old_branch # Delete the old branch
git push --set-upstream origin new_branch # Push the new branch, set local branch to track the new remote
@maxmilton
maxmilton / asynchronous-sentry-js-error-tracking.html
Last active April 27, 2020 15:43
How to load the Sentry JavaScript error tracking script 'raven.js' asynchronously and still capture errors before the script is loaded.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Asynchronous Sentry JavaScript Error Tracking</title>
<!-- putting your CSS near the top is always a good idea -->
<link rel="stylesheet" href="/app.css"></link>