Skip to content

Instantly share code, notes, and snippets.

View itsthejb's full-sized avatar

Jonathan Crooke itsthejb

View GitHub Profile
@itsthejb
itsthejb / reboot-on-network-down.sh
Last active September 11, 2018 17:33
Reboot server on no network
#!/bin/bash
RETRIES=3
SLEEP=60
TEST_HOST="google.com"
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root"
exit 1
fi
@itsthejb
itsthejb / mask-convert.py
Created January 26, 2018 12:41
Convert an .hcmask mask file to a plain mask
#!/usr/bin/env python3
import sys
import textwrap
if len(sys.argv) != 2:
print("Usage: {} <.hcmask>".format(sys.argv[0]))
exit(1)
with open(sys.argv[1], "r") as f:
@itsthejb
itsthejb / dir-packer.py
Last active November 1, 2018 07:21
Pack dirs to maximise fill space (Packer problem)
#!/usr/bin/env python3
import sys
import shutil
from functools import reduce
from bisect import insort
try:
from os import scandir, walk
except ImportError:
@itsthejb
itsthejb / OptionalExt.swift
Created June 15, 2017 07:23
someAnd, noneOr
extension Optional {
func someAnd(_ closure: (Wrapped) -> Bool) -> Bool {
if case .some(let v) = self, closure(v) == true { return true }
return false
}
func noneOr(_ closure: (Wrapped) -> Bool) -> Bool {
switch self {
case .some(let v):
return closure(v)
@itsthejb
itsthejb / main.swift
Created April 17, 2017 15:18
Simple Async Swift commandline tool outline
#!/usr/bin/swift
import Foundation
var keepAlive = true
dump(ProcessInfo().arguments)
let runLoop = RunLoop.current
let distantFuture = Date.distantFuture
@itsthejb
itsthejb / dirless.py
Last active March 11, 2017 13:45
Python script to return directories with sizes less than specified minimum
#!/usr/bin/env python
import sys
import os
from functools import reduce
def sized(source, size):
m = {}
def fileSize(root, path):
@itsthejb
itsthejb / plex-trailers.sh
Last active January 29, 2024 14:39 — forked from jdpace/plex-trailiers.sh
Plex trailers
#!/bin/bash
# downloads all missing trailers - it goes through all your movies and matchs them up with an entry
# in plex, grabs the imdb id from plex, and then parses the trailer url from the imdb site, then passes
# that to youtube-dl to download the trailer, it skips entries that dont have a matching imdb entry
# or if the trailer already exists
# must have 'sqlite3' and 'youtube-dl' packages (apt-get install sqlite3 youtube-dl)
# set 'mpath' and 'pms' accordingly
if [ "$#" -ne 1 ]; then
echo "Usage: $0 <media path>"
@itsthejb
itsthejb / clean-sims.rb
Last active February 17, 2016 07:59 — forked from jfro/clean-sims.rb
Quick script to remove stale simulator device folders unused by Xcode, lists invalid devices if run without flags
#!/usr/bin/ruby
require 'fileutils'
require 'optparse'
xcodePath = %x{xcode-select -print-path}
puts "Checking simulator devices against Xcode: #{xcodePath}"
options = {}
OptionParser.new do |opts|
@itsthejb
itsthejb / buildCommits.sh
Created November 7, 2015 18:58
Set bundle build number from count of Git commits + offset
PLIST=${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.app/Info.plist
OFFSET=300
COUNT=$(expr $(git rev-list HEAD --count) + $OFFSET)
/usr/libexec/PlistBuddy -c "Set CFBundleVersion $COUNT" "$PLIST"
@itsthejb
itsthejb / appTransport.sh
Last active February 17, 2016 15:07
Run Script Phase: Disable App Transport Security for Debug Config
if [ "${CONFIGURATION}" == "Debug" ]; then
/usr/libexec/PlistBuddy -c "Set NSAppTransportSecurity:NSAllowsArbitraryLoads true" ${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.app/Info.plist
fi