Skip to content

Instantly share code, notes, and snippets.

View tomasbasham's full-sized avatar
🤓
I’d tell you a UDP joke... but you might not get it.

Tomas Basham tomasbasham

🤓
I’d tell you a UDP joke... but you might not get it.
View GitHub Profile
@tomasbasham
tomasbasham / UIImage+Scale.m
Last active February 1, 2024 19:04
Scale a UIImage to any given rect keeping the aspect ratio
@implementation UIImage (scale)
/**
* Scales an image to fit within a bounds with a size governed by
* the passed size. Also keeps the aspect ratio.
*
* Switch MIN to MAX for aspect fill instead of fit.
*
* @param newSize the size of the bounds the image must fit within.
* @return a new scaled image.
@tomasbasham
tomasbasham / Netflix.ino
Created June 12, 2016 15:05
Netflic Switch code
/**
* Netflix
*
* A program that emits an IR singal to startup
* Netflix on a smart TV, lights up an array of
* LED lights and signals a control unit that a
* button press has occurred using MQTT.
*
* Hardware: Particle Photon
* Concept Usage: Netflix and Chill Button
@tomasbasham
tomasbasham / install.sh
Last active March 27, 2017 20:27
Arduino Library Test Script
#!/usr/bin/env bash
# The MIT License (MIT)
#
# Copyright (c) 2015 Adafruit Industries
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
@tomasbasham
tomasbasham / install_tmux_osx_no_brew
Last active November 7, 2024 22:28 — forked from Fi5t/install_tmux_osx_no_brew
Install tmux on OSX WITHOUT brew
# Create a directory
mkdir ~/tmux-install
cd ~/tmux-install
# Get the files
curl -OL https://www.openssl.org/source/openssl-1.0.2l.tar.gz
curl -OL https://github.com/tmux/tmux/releases/download/2.3/tmux-2.3.tar.gz
curl -OL https://github.com/libevent/libevent/releases/download/release-2.0.22-stable/libevent-2.0.22-stable.tar.gz
# Extract them
@tomasbasham
tomasbasham / yardoc_cheatsheet.md
Created October 1, 2017 18:44 — forked from chetan/yardoc_cheatsheet.md
YARD cheatsheet

YARD CHEATSHEET http://yardoc.org

cribbed from http://pastebin.com/xgzeAmBn

Templates to remind you of the options and formatting for the different types of objects you might want to document using YARD.

Modules

Namespace for classes and modules that handle serving documentation over HTTP

SSH agent forwarding and screen

When connecting to a remote server via SSH it is often convenient to use SSH agent forwarding so that you don't need a separate keypair on that server for connecting to further servers.

This is enabled by adding the

ForwardAgent yes

option to any of your Host entries in ~/.ssh/config (or alternatively with the -A option). Don't set this option in a wildcard Host * section since any user on the remote server that can bypass file permissions can now als use keys loaded in your SSH agent. So only use this with hosts you trust.

@tomasbasham
tomasbasham / install.sh
Created May 23, 2018 12:41
rbenv install
CFLAGS='-g -O2' RUBY_CONFIGURE_OPTS=--with-openssl-dir=$(brew --prefix openssl) rbenv install
require 'digest'
require 'net/http'
password = ARGV[0] || 'Password'
hashed_password = Digest::SHA1.hexdigest password
# SHA1 hashes will be 40 characters long
prefix = hashed_password[0, 5].to_s.upcase # Get the first 5 characters
suffix = hashed_password[5..-1].to_s.upcase # Get the remaining 35 characters
require 'base64'
class SpanContext
def initialize(trace_id: '', span_id: '')
raise RuntimeError 'trace_id must be 16 bytes' unless trace_id.size == 16
raise RuntimeError 'span_id must be 8 bytes' unless span_id.size == 8
@version = [0]
@trace_id = [0] + trace_id.bytes # field id 0 + trace_id
@span_id = [1] + span_id.bytes # field id 1 + span_id
@tomasbasham
tomasbasham / edge_cache.php
Created November 3, 2021 16:21
Control Cloudflare Edge Caching
/*
* Add a specific Cloudflare edge cache HTTP header to each HTTP response
* preventing defined pages from being cached at the edge. This is done
* selectively since some pages require dynamic content based on external
* factors such as geographic location of the request. All other static
* content will continue to be cached (i.e. JavaScript, CSS, images).
*
* To control the caching behaviour at the edge add a custom metadata field
* to the page:
*