Skip to content

Instantly share code, notes, and snippets.

@halkyon
halkyon / create-container-from-scratch.sh
Last active November 7, 2021 06:20
Create a simple container from scratch using cgroups and namespaces
#!/bin/bash
set -eu
if [ $EUID -ne 0 ]; then
echo "This script must be run as root"
exit 1
fi
ID="cgroup_$((100 + RANDOM % 1000))"
echo "Generated cgroup name: $ID"
@halkyon
halkyon / openwrt_build.sh
Last active March 25, 2021 23:02
Build an OpenWRT target with some extra packages, either using the OpenWRT image builder, or compile from git
#!/usr/bin/env bash
set -euo pipefail
target=${1:-}
subtarget=${2:-}
profile=${3:-}
release=${4:-snapshot}
target_path=$(readlink -f "${5:-$(pwd)}")
packages="luci luci-base luci-mod-admin-full luci-proto-relay luci-app-statistics"
@halkyon
halkyon / pre-commit
Last active July 11, 2017 03:42
pre-commit script to run php-cs-fixer against changed PHP scripts
#!/bin/bash
if [ ! -f .php_cs ]; then
if [ ! -f .php_cs.dist ]; then
exit
fi
fi
EXECUTABLE_NAME="php-cs-fixer"
LOCATIONS=(
"vendor/bin/$EXECUTABLE_NAME"
@halkyon
halkyon / cleanup-win10.ps1
Last active February 6, 2024 09:09
Cleanup Windows 10 Powershell script
##
## Windows 10 cleanup script.
## Remove dodgy tracking settings, unneeded services, all apps, and optional features that come with Windows 10. Make it more like Windows 7.
## NOTE: this was tested on Creators Update (1703) and Fall Creators Update (1709). Some of this may not work as expected on newer versions.
##
## Instructions
## 1. Run this script (under Powershell as Administrator):
## powershell -ExectionPolicy Bypass .\cleanup-win10.ps1
## 2. Let it run through, you may see a few errors, this is normal
## 3. Reboot
@halkyon
halkyon / switch_php.sh
Last active September 2, 2017 00:02
Install and switch between PHP versions (5.6, 7.0, and 7.1) using deb.sury.org packages
#!/bin/bash
# todo: support fpm as well as apache
# use bash "strict mode" http://redsymbol.net/articles/unofficial-bash-strict-mode/
set -euo pipefail
IFS=$'\n\t'
if [ $EUID -ne 0 ]; then
echo "This script must be run as root"
@halkyon
halkyon / gist:ec08493c2906c1539a49
Last active June 18, 2019 23:08
BuildTask for SilverStripe to remove obsolete tables, columns and indexes from the database
<?php
/**
* Remove old tables, columns, and indexes from a SilverStripe database.
*
* Define your obsolete tables, columns and indexes in {@link $deleted_tables},
* {@link deleted_columns} and {@link deleted_indexes} and these will be deleted
* from the database.
*
* In addition to that, it will automatically remove any tables and columns prefixed with "_obsolete".
*/
@halkyon
halkyon / gist:5580709
Last active December 17, 2015 08:29
Creates a bunch of pages in SilverStripe for testing. It'll take a long time to run, but good for testing how your site performs with a huge amount of pages. Put it into your `mysite/tasks` directory, then invoke the script by running `sake dev/tasks/GeneratePagesTask flush=1`
<?php
class GeneratePagesTask extends BuildTask {
public function run($request) {
for($i = 1; $i < 10; $i++) {
$segment = sprintf('page-top-level-%d', $i);
$p1 = SiteTree::get_by_link($segment);
if(!($p1 && $p1->exists())) {
echo "Creating page $i...";