Skip to content

Instantly share code, notes, and snippets.

View rossmacarthur's full-sized avatar
🦀

Ross MacArthur rossmacarthur

🦀
  • Cape Town, South Africa, Earth, Milky Way
  • 17:31 (UTC +02:00)
View GitHub Profile
@rossmacarthur
rossmacarthur / github-labels-import.js
Last active November 29, 2023 09:13 — forked from jamesperrin/github-labels-import.js
JavaScript file for importing GitHub labels from a JSON object.
/**
* 1. Update the labels JSON object.
* 2. Open web browsers
* 3. Navigate to desired GitHub repository.
* 4. Navigate to Issues tab.
* 5. Navigate to Labels link.
* 6. Open web browswer Developer Tools
* 7. Navigate to the Console window.
* 8. Copy and Paste the below code snippets into the Console window.
*/
@rossmacarthur
rossmacarthur / usb_hid.h
Created July 7, 2020 16:49
Nintendo Pro Controller USB descriptor as C header
// Result of running https://gist.github.com/ToadKing/b883a8ccfa26adcc6ba9905e75aeb4f2
// through https://github.com/abend0c1/hidrdd
//
//--------------------------------------------------------------------------------
// Decoded Application Collection
//--------------------------------------------------------------------------------
/*
05 01 (GLOBAL) USAGE_PAGE 0x0001 Generic Desktop Page
15 00 (GLOBAL) LOGICAL_MINIMUM 0x00 (0) <-- Info: Consider replacing 15 00 with 14
@rossmacarthur
rossmacarthur / index.js
Last active January 31, 2019 07:46 — forked from MoOx/index.js
Export/import github labels
// go on you labels pages
// eg https://github.com/cssnext/cssnext/labels
// paste this script in your console
// copy the output and now you can import it using https://github.com/popomore/github-labels !
var labels = [];
[].slice.call(document.querySelectorAll(".label-link"))
.forEach(function(element) {
labels.push({
name: element.textContent.trim(),
@rossmacarthur
rossmacarthur / iter-window.py
Created November 29, 2018 12:35
A windowed iterator with a configurable window and step size in Python.
class Window:
def __init__(self, *args, window=2, step=1):
self.iterator = iter(*args)
self.window = window
self.step = step
self.buffer = ()
def __iter__(self):
return self
@rossmacarthur
rossmacarthur / docker-destroy-all.sh
Last active September 6, 2018 15:08 — forked from JeffBelback/docker-destroy-all.sh
Destroy all Docker Containers and Images
#!/usr/bin/env bash
containers=$(docker ps -a -q)
# Stop all containers
if [ ! -n "$containers" ]; then
docker stop $containers
docker rm $containers
fi
@rossmacarthur
rossmacarthur / nested.py
Created August 27, 2018 08:36
Pickle nested classes in Python
import inspect
import pickle
def allow_picklable_inner_classes(cls):
for name in dir(cls):
inner = getattr(cls, name)
if not name.startswith('_') and inspect.isclass(inner):
new_name = '{}.{}'.format(cls.__name__, inner.__name__)
@rossmacarthur
rossmacarthur / dictset.py
Created August 8, 2018 11:40
A Python dictionary type that allows set operations for nested dictionaries.
class DictSet(dict):
"""
A dictionary type that allows set operations for nested dictionaries.
"""
def __or__(self, other):
return self.union(other)
def __and__(self, other):
return self.intersection(other)
@rossmacarthur
rossmacarthur / pkg-size.sh
Created November 21, 2017 13:21
Check download size of APT package/s
#!/usr/bin/env bash
package_and_size() {
local size=$(apt-get -y --print-uris install $1 | sed -n -e 's/Need to get \(.*\) of archives./\1/p')
printf "%-30s%s\n" "${1}" "${size}"
}
for pkg in "$@";
do
package_and_size $pkg