Skip to content

Instantly share code, notes, and snippets.

View k4kfh's full-sized avatar

Hampton k4kfh

View GitHub Profile
@k4kfh
k4kfh / pointslope.py
Last active August 29, 2015 14:27
Point Slope Form Equation Builder
#!/usr/bin/env python
print("Hampton [k4kfh] - blog.evilgeniustech.com")
firstx = float(input("What is the first X coordinate? "))
firsty = float(input("What is the first Y coordinate? "))
print("Ordered pair for first point: (%d, %d)") % (firstx, firsty)
secondx = float(input("What is the second X coordinate? "))
secondy = float(input("What is the second Y coordinate? "))
@k4kfh
k4kfh / buildDropdown.js
Last active September 20, 2015 23:05
buildDropdown.js is a simple JavaScript program that can build an HTML <select> dropdown from a JavaScript array variable.
//BUILDDROPDOWN.JS
//by Hampton [evilgeniustech.com]
//buildDropdown.js is a useful script that makes it easy to build an HTML dropdown <select> tag from a JavaScript array.
//How to use:
//The function accepts 2-3 parameters.
// - id >>> this is the HTML ID of the select element you wish to modify, as a string of course.
// - list >>> this is the JavaScript array you want to use with the dropdown.
// - clear >>> this is a boolean which decides whether or not the script removes existing dropdown choices. For example, if I called this with clear = true, it would delete any existing <option> tags and start fresh. If it is false or undefined, it simply appends the new <option> tags to the existing ones, if any.
@k4kfh
k4kfh / example.js
Created November 9, 2015 03:58
example-decoder-constructor
emd567:function(address, trainPosition) {
//ESU LokSound Select V4
//decoder object for ESU official EMD 567 Sound project
//By Hampton Morgan - k4kfh@github - May 2015
//evilgeniustech.com
train[trainPosition].throttle = new jmri.throttle(address, trainPosition) //we use the train position as the throttle name for future lookup purposes
//FUNCTIONS
this.f = new Object();
@k4kfh
k4kfh / prototype.js
Last active November 28, 2015 05:49
ZephyrCab prototype Example
prototype: {
"builder": "EMD", //This is displayed to the client and can be anything
"name": "F7-A", //This is also displayed to the client and can be anything
"type": "locomotive", //This must be "locomotive"
"weight": 250000, //Weight of the locomotive in lbs
"maxHP": 1500, //Horsepower of the locomotive
"notchRPM": [300, 362, 425, 487, 550, 613, 675, 738, 800], //This is an array of RPMs for the notch values. Start with idle, end with RUN8, for a total of 9 array items.
"notchMaxSpeeds": [null, 7.5, 15, 22.5, 30, 37.5, 45, 52.5, 60], //This is an array of max speeds for the notch values. Set the first item to null. This is so we can look things up by just feeding the notch into it, but the max speed for IDLE is obviously zero.
"engineRunning": 0, //This is NOT A BOOLEAN! This is a binary value (0 is off, 1 is on). You should set this to 0, sim.js will redefine it as needed.
@k4kfh
k4kfh / decoders.js
Last active November 26, 2015 05:10
ZephyrCab decoder Example
decoders = {
//This is EXACTLY the same string value recieved from JMRI for the decoderFamily attribute.
"ESU LokSound Select": {
//This is EXACTLY the same string value recieved from JMRI for the decoderModel attribute.
"LokSound Select EMD 567": function (address, trainPosition) {
//First thing we do is create the throttle object. Make sure you use jmri.throttleName.generate() for the name! That function generates a unique name for each throttle, and if you don't use it you'll probably run into issues.
train.all[trainPosition].throttle = new jmri.throttle(address, jmri.throttleName.generate()); //we use the train position as the throttle name for future lookup purposes
/*
Functions:
@k4kfh
k4kfh / timestamp.js
Last active November 30, 2015 03:50
Simple timestamp system in JavaScript; returns current time in hr:min:sec format
timestamp = function(type) {
if (type == undefined) {
type = 24;
}
if (type == 24) {
var currentDate = new Date();
var hours = currentDate.getHours();
var minutes = currentDate.getMinutes();
var seconds = currentDate.getSeconds();
var finalString = hours + ":" + minutes + ":" + seconds;
@k4kfh
k4kfh / canvasCopy.js
Created March 21, 2016 22:47
Simple script for getting the answers from a Canvas quiz and pasting them into the input of another attempt. Only useful if your teachers allow multiple attempts on a quiz, and it doesn't cheat, it's just a time saver.
//OLD ATTEMPT CODE
//run this on the old attempt page to spit out all your answers in an array.
//copy the array to your clipboard
var answerList = [];
$(".question_input").each(function() {
answerList.push($(this).val())
})
//NEW ATTEMPT CODE
//put in your answers in global variable answerList
@k4kfh
k4kfh / arduinoWelder.ino
Created February 21, 2017 22:38
Non-blocking Arduino Arc Welder Simulator
unsigned long currentMillis = 0;
unsigned long previousMillisArc = 0;
unsigned long previousMillisFlicker = 0;
int timeArcOff = 3000;
int timeArcOn = 3000;
bool arc = false; //whether there's an arc right now or not
int ledState = LOW;
const int ledPin = 2;
int timeFlickerOn = 50;
int timeFlickerOff = 170;
@k4kfh
k4kfh / http-proxy-test.py
Created July 7, 2017 19:13
This script will make HTTP requests on a regular basis and log any errors to a file with a timestamp. Useful for testing proxies.
# PROXY TESTER
# Run this script with an array of URLs and it will make HTTP requests. Whenever it encounters an error it will timestamp it and log it
#import libs
import urllib2
import hashlib
import sys
import time
import datetime
#config
@k4kfh
k4kfh / make-directories.py
Created July 27, 2017 20:34
Recursive, random directory creation with Python
import os,sys,uuid
global injectedLegitFile
injectedLegitFile = True
def fillDirectoryWithFiles(path, numFiles, size):
file_names = [(str(uuid.uuid4())[:10] + ".xlsx") for i in range(0,numFiles)]
#print file_names
for name in file_names:
fileObject = open(path+"/"+name,"w+")
fileObject.write(os.urandom(size))