Skip to content

Instantly share code, notes, and snippets.

View cms-codes's full-sized avatar

Chris Slothouber cms-codes

View GitHub Profile
@cms-codes
cms-codes / camView.py
Last active February 26, 2017 07:16
Using PyQt4 and OpenCV, runs a thread to suck in a MJPEG stream and display it in a text label. Based on an orphaned solution at http://stackoverflow.com/questions/35103302/what-is-the-best-way-to-display-a-videostream-in-pyqt4#35316662
import sys
import cv2
from PyQt4 import QtGui, QtCore, uic
class videoThread(QtCore.QThread):
# Requires IP address of streaming server
def __init__(self,address):
super(videoThread,self).__init__()
self.ip = address
from PyQt4 import QtGui, QtCore
import urllib2, urllib2_ssl
import thread
import ssl
import sys
import collections
import time
import httplib
@cms-codes
cms-codes / passive_poll.py
Last active August 22, 2017 21:21
Experimenting with Python and sqlite3 to create a passive check to poll resource producing nodes. Initially using the cam nodes as producer. Making use of nominal context management in transacting with the sqlite.
import sys
import time
import os
import contextlib
from web_connection import the_https_request
from db_connection import the_sqlite_connection
from fs_connection import the_resource_path
def query(sql, args):
# Can a query function handle both inserts and selects?
import itertools
import math
from decimal import Decimal, getcontext
getcontext().prec = 30
class Vector:
CANNOT_NORMALIZE_ZERO_VECTOR_MSG = 'Cannot normalize the zero vector'
@cms-codes
cms-codes / ssd1322.h
Last active February 14, 2018 13:52
SSD1322 commands
#define SSD_EN_GRAYSCALE 0x000
#define SSD_COL_START_END 0x015
#define SSD_WRITE 0x05C
#define SSD_ROW_START_END 0x075
#define SSD_START_LINE 0x0A1
#define SSD_ALL_OFF 0x0A4
#define SSD_ALL_ON 0x0A5
#define SSD_NORMAL 0x0A6
#define SSD_INVERSE 0x0A7
#define SSD_SET_VDD 0x0AB
class Frame():
def __init__( self, width, factor ):
self.width = width
self.factor = factor
def xy_to_index( self, x, y ):
row_offset = ( y << self.factor )
# two pixels per byte; index origin = 0
index = ( row_offset - self.width ) + ( x >> 1 ) + ( x & 1 ) - 1
@cms-codes
cms-codes / stepper_position_pot.ino
Created June 23, 2018 20:00
Reads an 8 bit value (0 - 254) from the analog to digital converter and moves two stepper motors to a relative position within the motor's range (0 - 63). You could also use the Arduino map() function to translate the different ranges.
#include <AccelStepper.h>
// Define a stepper and the pins it will use
//AccelStepper stepper; // Defaults to AccelStepper::FULL4WIRE (4 pins) on 2, 3, 4, 5
AccelStepper xAxis(1, 4, 3); // pin 3 = step, pin 6 = direction
AccelStepper yAxis(1, 6, 5); // pin 3 = step, pin 6 = direction
#define Xpin A0
#define Ypin A3
void setup()
@cms-codes
cms-codes / orange_you_glad.py
Created July 28, 2018 03:18
So I wanted to test instantiating an object inside another object and the object's constructor requires a reference of the object creating it so I pass it self
class Tree:
def __init__(self):
self.oranges = []
def grow_orange(self):
# Creating an object by passing it self
orange = Orange(self)
self.add_orange(orange)
#include <SPI.h>
#include "RF24.h"
//#include <SoftwareSerial.h>
#include <avr/sleep.h>
// Set packet data structure
struct data_t {
byte stn_id;
byte msg_type;
unsigned short msg_value;
@cms-codes
cms-codes / Lab6.c
Last active November 12, 2018 00:15
/********* Lab6 *******
* Course: PROG1955-1
* Title: Lab6
* Purpose: Store the last name and first name of students in a dynamic
structure using a linked list
* Date: 2018-11-10
* Author:
* File: Lab6.c
*/