Skip to content

Instantly share code, notes, and snippets.

@benrules2
benrules2 / Markov.py
Created January 5, 2017 23:35
Markov Chain message generator
import random
import sys
def build_chain(text, chain = {}):
words = text.split(' ')
index = 1
for word in words[index:]:
key = words[index - 1]
if key in chain:
chain[key].append(word)
(.venv) beneagan@Bens-MacBook-Pro-2 voiceharness % python process_request.py
/Users/beneagan/projects/voiceharness/.venv/lib/python3.9/site-packages/urllib3/__init__.py:35: NotOpenSSLWarning: urllib3 v2 only supports OpenSSL 1.1.1+, currently the 'ssl' module is compiled with 'LibreSSL 2.8.3'. See: https://github.com/urllib3/urllib3/issues/3020
warnings.warn(
Chatbot is ready! Type 'exit' to quit.
You: turn off basement lights
0:I will first list the devices in the basement. Then, I will turn off the basement lights.
Traceback (most recent call last):
File "/Users/beneagan/projects/voiceharness/process_request.py", line 171, in <module>
chatbot.process_user_interaction(message = user_input, streaming_callback = streaming_callback)
File "/Users/beneagan/projects/voiceharness/process_request.py", line 82, in process_user_interaction
@benrules2
benrules2 / flicker.py
Last active October 14, 2024 17:21
Causes Philips Hue lights to flicker
from qhue import Bridge
import time
import random
import sys
bridge_ip = "<hue_ip_address>"
username = "<username>"
my_lights = [light_id_1, light_id_2]
def flicker(bridge, elapsed_time, lights_list = [], transition = 10):
@benrules2
benrules2 / orbits.py
Created February 10, 2017 23:19
Python RK4 orbits
import math
import random
import matplotlib.pyplot as plot
from mpl_toolkits.mplot3d import Axes3D
class point:
def __init__(self, x,y,z):
self.x = x
self.y = y
self.z = z
import water
if __name__ == "__main__":
water.auto_water()
<!DOCTYPE html>
<head>
<title>{{ title }}</title>
</head>
<body>
<h1>PLANT HELPLINE</h1>
<h2>The date and time on the server is: {{ time }}</h2>
<h2> {{ text }} </h2>
<a href="/auto/water/ON"><button>Turn ON Auto Watering</button></a>
# External module imp
import RPi.GPIO as GPIO
import datetime
import time
init = False
GPIO.setmode(GPIO.BOARD) # Broadcom pin-numbering scheme
def get_last_watered():
@benrules2
benrules2 / Gravity.py
Last active November 14, 2023 16:39
Python N-Body Orbit Simulation
import math
import random
import matplotlib.pyplot as plot
from mpl_toolkits.mplot3d import Axes3D
class point:
def __init__(self, x,y,z):
self.x = x
self.y = y
@benrules2
benrules2 / AnimateBilly.h
Last active October 13, 2022 06:43
Billy Bass
#include <AFMotor.h>
#define NUM_MOTORS 3
AF_DCMotor head(1, MOTOR12_1KHZ); // create motor #2, 64KHz pwm
AF_DCMotor mouth(2, MOTOR12_1KHZ);
AF_DCMotor tail(3, MOTOR34_1KHZ);
void runMotorOnOff(AF_DCMotor motor, int aniDelay = 500){
motor.run(FORWARD);
@benrules2
benrules2 / README_UBC.md
Created October 14, 2021 20:42
UBC Animal Welfare Project Brief

UBC Animal Welfare Project - Using nest cameras to collect behavioural animal data

Currently, we are running ~ 10 nest cameras simultaneously to collect continuous behavioural data on cats in shelters. As Nest will not allow us to download our stored continuous video streams, we are pulling our data from the home.nest.com website by 1) making “clips” of individual hours to download and/or 2) creating time-lapse of 12-hour chunks to be later behaviourally coded. Both solutions involve a team member working full-time to pulling data manually from the website and having access to the continuous data would remove this need.

Modify this code so it dumps many videos to many video files, instead of just one to one (we have 10-12 nest cameras running @ once) Simplify the auth process so it can be started more easily without copy pasting from cookies in the browser networking inspection tabs. It is tricky to snoop through the cookies and find the data we need to get authenticated. Launch this as a service so it i