Skip to content

Instantly share code, notes, and snippets.

View mwrouse's full-sized avatar

Michael Rouse mwrouse

View GitHub Profile
@mwrouse
mwrouse / can-serial-relay.ino
Last active July 23, 2021 15:39
Arduino CAN Serial Relay
/**
* This project is an Arduino that serves as a CAN relay to a Raspberry Pi.
* It was created because of this issue https://github.com/linux-can/can-utils/issues/133
* The Arduino is responsible for sending/receiving CAN messages and passes it along over Serial.
*
* We used a custom library for this, that is where the CAN class comes from, but you can replace it with whatever CAN library
* you want to use.
*/
#include "config.h"
#include "pins.h"
@mwrouse
mwrouse / Base64Decode.pas
Last active July 16, 2021 11:42
Inno Setup (Pascal Script) Base64 Decode
// Left shift operator for Base64Decode (Inno Setup does not support << )
function BitwiseLeftShift (input: LongInt; shiftFactor: Integer): LongInt;
var
exp: LongInt; // Total to multiply by
i: Integer;
//Result: LongInt;
begin
Result := 0;
exp := 1;
@mwrouse
mwrouse / Autocomplete.js
Last active April 25, 2024 08:47
Autocompletion for an object in the monaco editor
function ShowAutocompletion(obj) {
// Disable default autocompletion for javascript
monaco.languages.typescript.javascriptDefaults.setCompilerOptions({ noLib: true });
// Helper function to return the monaco completion item type of a thing
function getType(thing, isMember) {
isMember = (isMember == undefined) ? (typeof isMember == "boolean") ? isMember : false : false; // Give isMember a default value of false
switch ((typeof thing).toLowerCase()) {
case "object":
@mwrouse
mwrouse / classList-polyfill.js
Last active April 13, 2017 14:27
classList polyfill for IE7+ and all major browsers
/**
* ClassList polyfill for IE7+ and all major browsers
* By: Michael Rouse
*
* Use:
* var my_element = document.getElementById('major-id');
*
* classList.add(my_element, 'new-class'); // Adds the class 'new-class' to the element
* classList.remove(my_element, 'old-class'); // Removes 'old-class' from the element's classes
* classList.contains(my_element, 'a-class'); // Returns true if the element has 'a-class' as a class
@mwrouse
mwrouse / EventListenerPolyfill.js
Last active June 2, 2020 00:55
JavaScript addEventListener and removeEventListener polyfill for IE6+
/**
* Event polyfill
* Michael Rouse
* December 2016
*/
function polyfillEvent(e) {
e = e || window.event;
e.eventPhase = e.eventPhase || 0;
e.defaultPrevented = e.defaultPrevented || false;
@mwrouse
mwrouse / ReadJSON.html
Last active March 1, 2023 14:19
Reading JSON File Input
<!DOCTYPE html>
<html>
<head>
<title>File Input</title>
</head>
<body>
<input type="file" id="fileInput">
<script src="index.js"></script>
</body>
@mwrouse
mwrouse / right-pad.js
Last active March 25, 2016 12:57
I also wrote a JavaScript padding function, except in one line
/**
* Right Pad
*
* str - the string to pad
* chr - the character to use as padding
* n - the desired string length
*/
function rpad(str, chr, n)
{
return ((str+='').length < n && chr) ? rpad(str + chr, chr, n) : str;
var questions = {
0: {
name: "name",
intro: true,
question: ["Hi.", "I'm Jordan Staniscia", "Might I ask what your name is?"],
answers: {
"default": {
replies: ["That's a good name.", "Names are a funny thing", "It's one of the only decisions you don't make yourself"]
},
"jordan staniscia": {