Skip to content

Instantly share code, notes, and snippets.

View lewisd32's full-sized avatar

Derek Lewis lewisd32

  • Vancouver, BC, Canada
View GitHub Profile
@lewisd32
lewisd32 / ProgrammableBlock.cs
Created May 7, 2016 00:27
Automated assembler script for Space Engineers
String lcdName = "Assembler Control LCD";
public void Main(string argument) {
List<String> orderedResources = new List<String>();
Dictionary<String, int> desiredQuantities = new Dictionary<String, int>();
Dictionary<String, String> displayNames = new Dictionary<String, String>();
Dictionary<String, String> assemblerProducts = new Dictionary<String, String>();
StringBuilder text = new StringBuilder();
// Find config
pcb_width = 21;
pcb_length = 28;
pcb_inset_depth = 1;
base_thickness = 2;
corner_thickness = 1;
corner_x_len = 2;
corner_y_len = 4;
corner_z_height = 3;
@lewisd32
lewisd32 / iptableflip.sh
Created April 15, 2015 18:20
Snippet of Unbounce script for restarting HAProxy with zero downtime
echo "Flipping tables! (╯°□°)╯︵ ┻━┻"
num_rules=3
real=3 # exposed to the ELB as port 443
test=4 # used to install test certs for domain verification
health=5 # used by the ELB healthcheck
blue_prefix=855
green_prefix=866
#!/bin/bash
total=0
while read num; do
total=$((total+num))
done
echo $total
@lewisd32
lewisd32 / percentile.sh
Last active October 3, 2024 13:07
Calculate percentile in bash
#!/bin/bash
# stdin should be integers, one per line.
percentile=$1
tmp="$(tempfile)"
total=$(sort -n | tee "$tmp" | wc -l)
# (n + 99) / 100 with integers is effectively ceil(n/100) with floats
count=$(((total * percentile + 99) / 100))
head -n $count "$tmp" | tail -n 1
rm "$tmp"
export PS1='\[\e]0;\u@\h: \w\a\]${debian_chroot:+($debian_chroot)}\u@\h:\w$(tag)\$ '
@lewisd32
lewisd32 / gist:9695415
Created March 21, 2014 20:15
PicoBuckBracket2.scad
pcb_width = 21;
pcb_length = 28;
pcb_inset_depth = 1;
base_thickness = 2;
corner_thickness = 1;
corner_x_len = 2;
corner_y_len = 4;
corner_z_height = 3;
@lewisd32
lewisd32 / PicoBuckBracket.scad
Last active August 29, 2015 13:57
PicoBuck bracket
width = 23.5;
height = 28;
thickness = 1.5; // thickness of most of the piece
base_thickness = 3; // total thickness of base
waffle_height = 2; // height of base waffle
waffle_thickness = 0.1; // thickness of the waffle fins
waffle_grid = 2; // spacing between waffle fins
edge_height = 6; // height of the edges that go most of the way around
nib_length = 10; // length of the nib holding the PCB in place
nib_height = 2; // How high from the base the nib is
struct PeripheralCommand {
union {
struct {
uint8_t red;
uint8_t green;
uint8_t blue;
};
struct {
uint8_t hue;
uint8_t sat;