Skip to content

Instantly share code, notes, and snippets.

@bradley219
bradley219 / .gitignore
Last active May 10, 2021
PID C++ implementation
View unifi_led.sh
#!/bin/bash
USERNAME=""
IDENTITY=""
IP=""
STATE=""
usage() { echo "Usage: $0 [-u <ssh username> ] [-k <ssh identity file>] [-i <ip address>] [-s <on|off>]" 1>&2; exit 1; }
while getopts "u:k:i:s:" o; do
View num.c
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <limits.h>
#include <errno.h>
#include <getopt.h>
#define VERSION "1.1"
typedef enum {
@bradley219
bradley219 / fix_xcode_plugins
Last active Dec 11, 2019
Fix Xcode Plugin UUIDs
View fix_xcode_plugins
#!/bin/bash
UUID=`defaults read /Applications/Xcode.app/Contents/Info DVTPlugInCompatibilityUUID`
echo "UUID=$UUID"
find ~/Library/Application\ Support/Developer/Shared/Xcode/Plug-ins -name Info.plist -maxdepth 3 | xargs -I{} defaults write {} DVTPlugInCompatibilityUUIDs -array-add "$UUID"
@bradley219
bradley219 / video_to_gif.sh
Created Dec 13, 2018
Convert a video file to high quality gif
View video_to_gif.sh
#!/bin/bash
FPS=14
WIDTH=640
PALETTE=/tmp/palette.png
INPUT="$1"
OUTPUT="$2"
KEEP_PALETTE="$3"
@bradley219
bradley219 / hamming_distance.c
Created Apr 8, 2013
MySQL extension for user-defined function HAMMING_DISTANCE, which quickly calculates hamming distance between two 64-bit integers passed as arguments.
View hamming_distance.c
#ifdef STANDARD
/* STANDARD is defined, don't use any mysql functions */
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#ifdef __WIN__
typedef unsigned __int64 ulonglong; /* Microsofts 64 bit types */
typedef __int64 longlong;
#else
typedef unsigned long long ulonglong;
View sendimessage.applescript
# Usage:
# osascript sendimessage.applescript <recipient> <message>
on run {targetBuddyPhone, targetMessage}
tell application "Messages"
set targetService to 1st service whose service type = iMessage
set targetBuddy to buddy targetBuddyPhone of targetService
send targetMessage to targetBuddy
end tell
end run
@bradley219
bradley219 / readserial.c
Last active May 24, 2018
Simple utility for logging from serial port
View readserial.c
#include <unistd.h>
#include <fcntl.h>
#include <termios.h>
#include <stdio.h>
#include <sys/select.h>
#include <signal.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <stdlib.h>
@bradley219
bradley219 / focus.py
Created Nov 27, 2017
Python script for generating a focus routine gcode file. To use, set parameters in the script and execute on the command line. Pipe the output into a gcode file. Example: `./focus.py > focus.gcode`.
View focus.py
#!/usr/bin/env python
def g1_from_point(point):
return "G1 X{} Y{} Z{}\n".format(round(point[0], 5), round(point[1], 5), round(point[2], 5))
def g1_from_speed(speed):
return "G1 F{}\n".format(speed)
if __name__ == '__main__':
View tohex.py
#!/usr/bin/env python
import sys
c = sys.stdin.read(1)
while len(c) > 0:
sys.stdout.write("{0:02x}".format(ord(c)))
c = sys.stdin.read(1)