Skip to content

Instantly share code, notes, and snippets.

@mcorrigan
mcorrigan / JavaScript Numeric Range
Created September 12, 2014 23:30
JavaScript Range Function
// something comparable to PHP range method. Supports numbers and letters.
function range(start, end, step) {
start || alert('must have 1+ params');
if (!end) {end = start; start = 0;}
var step = step || 1;
var range = [];
var is_num = !isNaN(start);
start = !is_num ? start.charCodeAt(0) : start;
end = !is_num ? end.charCodeAt(0) : end;
step = !is_num ? Math.max(Math.round(step), 1) : step;
@mcorrigan
mcorrigan / POST Request with File Resource
Last active October 10, 2022 10:42
Creating a POST request using file handlers for file content
<?php
# base code found here: http://stackoverflow.com/questions/3085990/post-a-file-string-using-curl-in-php
$delimiter = '----WebKitFormBoundary'.uniqid();
$data = create_post($delimiter, array(
'bingo' => 'yes'
), array(
'file' => array(
'filename' => 'data.txt',
@mcorrigan
mcorrigan / encoding_error_codes.yml
Created July 7, 2016 21:14
Encoding.com Error Codes
---
ECOM00001:
description: "The AWS Access Key Id you provided does not exist."
level: alert
ECOM00002:
description: "Overtime Limit Exceeded"
level: retry
ECOM00003:
description: "The specified bucket does not exist."
level: alert
@mcorrigan
mcorrigan / toggle_headless.py
Last active July 14, 2022 02:15
SteamVR Headless Mode Toggle Python Script
#!python
# coding: utf-8
# This is a simple script to quickly switch between HMD mode and headless mode with Vive in SteamVR
# It uses symlinks to ensure that SteamVR will continue to run and always preserves the original files,
# This should be able to be rerun following updates (assuming the configs haven't structurally changes
# along with anything else) -- symlinks require running with elevated priviledges
import sys, os, ctypes, time, json, shutil
from winreg import QueryValueEx, HKEY_CURRENT_USER, OpenKey
@mcorrigan
mcorrigan / chutes_and_ladders.html
Last active July 27, 2022 03:04
A Quick Fully Computerized Game of Chutes and Ladders (Since its totally random)
<!-- this was just a rapid development program for fun -->
<html>
<body>
<h1>Chutes and Ladders!</h1>
<button onclick="beginGame()">Play Game</button>
<img src="https://thumbs.dreamstime.com/z/s-board-games-chutes-ladders-woodbridge-new-jersey-october-circa-game-shown-128701391.jpg" />
<script>
// general configs
var spin_min = 1, spin_max = 6;
var exact_space_win = true;
@mcorrigan
mcorrigan / pos_text.h
Last active September 13, 2023 03:45
Position text oled SSD1306 Arduino
void displayPositionedText(char* buf, int textSize, Position vpos, Position hpos) {
display.setTextSize(textSize);
int16_t x1, y1;
uint16_t w, h;
display.getTextBounds(buf, 0, 0, &x1, &y1, &w, &h);
int _vpos = 0, _hpos = 0;
switch (vpos) {
case CENTER:
@mcorrigan
mcorrigan / campi_ascii.py
Last active November 20, 2023 19:09
Preview Raspberry Pi Camera via Color ASCII Preview [for headless Pi]
from picamera import PiCamera
from picamera.array import PiRGBArray
import sys, curses, time, cv2
import numpy as np
import warnings
import collections
# TODO: resolve these at some point
warnings.filterwarnings(action='ignore', message='Mean of empty slice')
warnings.filterwarnings(action='ignore', message='invalid value encountered in double_scalars')
@mcorrigan
mcorrigan / Animator.cpp
Last active November 15, 2022 23:30
(Non-blocking) Sequence Animator for OLED "0.96 - SSD1306
#include <Arduino.h>
#include "Animator.h"
Animator::Animator(){
// nothing for now
}
void Animator::begin(Adafruit_SSD1306 *display, unsigned int width, unsigned int height, HardwareSerial* serial){
_display = display;
_stream = serial;
@mcorrigan
mcorrigan / lolin_c3_pico.json
Last active November 19, 2024 02:50
Lolin ESP32-C3 PlatformIO Board
{
"build": {
"arduino": {
"ldscript": "esp32c3_out.ld"
},
"core": "esp32",
"extra_flags": [
"-DARDUINO_LOLIN_C3_PICO",
"-DARDUINO_USB_MODE=1",
"-DARDUINO_USB_CDC_ON_BOOT=1"
@mcorrigan
mcorrigan / main.cpp
Last active November 10, 2023 20:14
Arduino Invertek Optidrive E3 VFD ModbusMaster Test
#include <Arduino.h>
#include <ModbusMaster.h>
#define MAX485_DE_RE 4
#define OUTPUT_MOTOR_FREQ 0x0007
#define DRIVE_STATUS 0x0006
#define DRIVE_TEMP 0x0018
ModbusMaster node;