Skip to content

Instantly share code, notes, and snippets.

View igilham's full-sized avatar

Ian Gilham igilham

View GitHub Profile
@igilham
igilham / randline.sh
Created January 5, 2011 16:05
Read a random line from a text file
shuf -n 1 oblique.txt
# or
rl -c 1 oblique.txt
# or
sed -n $((RANDOM%$(wc -l < leader.txt)+1))p oblique.txt
@igilham
igilham / requires.sh
Created February 22, 2018 12:08
Prelude in bash scripts to declare installed command requirements
#!/bin/bash
# Declare requirements in bash scripts
set -e
function requires() {
if ! command -v $1 &>/dev/null; then
echo "Requires $1"
exit 1
fi
@igilham
igilham / test-urls.sh
Last active February 22, 2024 15:54
Test if a list of files (URLS) exist on a web server
#!/bin/bash
# List missing files from a web server. Missing means we get a non-200 response.
BASE="http://www.example.com"
FILES="index.html
about.html"
for ITEM in ${FILES}; do
URL="${BASE}/${ITEM}"
{
"AWSTemplateFormatVersion": "2010-09-09",
"Description": "AWS CloudFormation deploys a Windows machine used for Steam",
"Parameters": {
"AWSAMI": {
"Description": "Choose the AMI ID for your Steam machine. This should be a Windows Server 2012 R2 instance and the ID will look like ami-XXXXXXXX",
"Type": "AWS::EC2::Image::Id"
},
"AWSSubnet": {
"Description": "Choose a subnet for the Steam instance.",
@igilham
igilham / fzkill
Created July 23, 2021 10:52
Fuzzy Kill script. Use `fzf` to locate a process to kill.
#!/bin/sh
# Fuzzy find and kill a process. Supports signal codes (-9 etc.)
set -e
pid="$(ps -ef | fzf | awk '{ print $2}')"
kill $@ ${pid}
@igilham
igilham / aws-wormhole-login.sh
Last active April 14, 2021 10:57
Fetch AWS credentials for CLI usage via Wormhole
#!/bin/bash
# reconfigure AWS CLI credentials
set -e
function requires() {
if ! command -v "$1" &>/dev/null; then
echo "Requires $1"
exit 1
fi
@igilham
igilham / proxy.py
Last active November 11, 2020 11:08
Enable/Disable company proxy settings on MacOS
#!/usr/bin/env python3
from argparse import ArgumentParser
import os
import subprocess
proxy_host = os.getenv('PROXY_HOST', default='http-gw.mycompany.com')
proxy_port = os.getenv('PROXY_PORT', default='80')
base_java_opts = os.getenv("BASE_JAVA_OPTS", "")
on_network = "MyCompany On Network"
@igilham
igilham / CameraFollow.cs
Last active October 8, 2020 16:11
Really basic Unity camera script to follow the player object.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
// Simple camera follow system
public class CameraFollow : MonoBehaviour
{
// The target to follow
public Transform Target;
// Position offset from target
@igilham
igilham / ReadOnlyAttribute.cs
Created October 8, 2020 08:28
Unity Editor ReadOnly Attribute
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
public class ReadOnlyAttribute : PropertyAttribute
{
}
[CustomPropertyDrawer(typeof(ReadOnlyAttribute))]
@igilham
igilham / yiq-color-balance.py
Last active November 14, 2019 11:32
Works out the YIQ values of a given RGB colour and suggests a pallet of similar colours with the same chrominance. This can be used on legacy TV platforms to reduce chroma crawl, where colours bleed into each other.
#!/usr/bin/env python
import sys
def rgb2Yiq(red, green, blue):
y = int((0.299 * red) + (0.587 * green) + (0.114 * blue))
i = int((0.596 * red) - (0.275 * green) - (0.321 * blue))
q = int((0.212 * red) - (0.528 * green) + (0.311 * blue))
return (y, i, q)