Skip to content

Instantly share code, notes, and snippets.

@kongmunist
kongmunist / index.html
Last active November 16, 2020 04:41
Basic HTML page
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Accelerometer Demo</title>
<style>
.indicatorDot{
width: 30px;
height: 30px;
var px = 50; // Position x and y
var py = 50;
var vx = 0.0; // Velocity x and y
var vy = 0.0;
var updateRate = 1/60; // Sensor refresh rate
function getAccel(){
DeviceMotionEvent.requestPermission().then(response => {
if (response == 'granted') {
// Add a listener to get smartphone orientation
@kongmunist
kongmunist / basicsquare.ino
Last active December 23, 2020 08:10
Arduino Variable Duty-Cycle Square Wave Generator
#define LED_pin 9
// Track LED state
bool LED_state = false;
// Set frequency of LED
float blinkrate = 1; // In Hz
float delay_between_switch = 500.0/blinkrate; // Blink at N Hz means you switch every 1s/(N/2)
// Track blinking cycle times of LED
@kongmunist
kongmunist / face_tracking_ppg.py
Last active December 27, 2022 04:28
Webcam Photoplethysmyography
# Must be run in console to work properly
import numpy as np
import cv2
import time
from scipy import signal
import matplotlib.pyplot as plt
import matplotlib
import threading
import scipy.signal as sig
@kongmunist
kongmunist / base.html
Last active February 22, 2024 01:52
Code for "Accessing Smartphone Cameras and Webcams with Javascript": https://kongmunist.medium.com/ml-in-browser-accessing-smartphone-cameras-with-javascript-86c9a9c6a20
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Face Mesh Demo by Andy Kong</title>
<!-- Import latest version of TF.js-->
<script src="https://cdn.jsdelivr.net/npm/@tensorflow/tfjs"></script>
<!-- Facemesh model import -->
@kongmunist
kongmunist / PPG_FFT.js
Last active May 27, 2021 01:19
Code for "Face Tracking With Javascript On Any Device With A Browser (Mobile or Desktop)" https://kongmunist.medium.com/face-tracking-with-javascript-on-any-device-with-a-browser-mobile-or-desktop-48aa561fd9d5
// PPG Demo by Andy Kong
// FFT function in Javascript
// - Make sure to include the fft.js in a <script> tag in the HTML header.
// - We initialize the FFT object in Javascript using this command in the main
// fft = new window.kiss.FFTR(maxHistLen);
async function calcFFT(data){
// Remove offset
@kongmunist
kongmunist / infoglobe_esp_demo.ino
Last active November 28, 2022 01:02
Custom control code for the Olympia Infoglobe
// Andy Kong 11/13/22
// Code to control the Olympia Infoglobe message and transitions
// USAGE:
// Type a message > 2 chars into Serial and this script will try to write it out into the Infoglobe's IR LED attached to Pin D2
// To send a String X to the Infoglobe, call infoAddMsg(X);
// Hardware setup can be found here:
// https://andykong.org/blog/infoglobetutorial1/
// https://andykong.org/blog/infoglobetutorial2/
@kongmunist
kongmunist / SerialLogger.java
Created May 20, 2023 19:55
Serial Logging class written for Java/Processing, integrates cleanly on UNIX/MacOS since it relies on unix style system commands
class SerialLogger {
public String portname;
public String filename;
public Process p;
SerialLogger(String portname, String filename) {
this.portname = portname;
this.filename = sketchPath() + "/data/" + filename + ".csv";
}
// From the blog post andykong.org/blog/icloudconfusion/
function boxTops(){
HTMLCollection.prototype.toArray = function() { return Array.from(this); }
// Select all the time badges and parse out their total runtime in seconds
a = document.getElementsByClassName('video-text-badge').toArray()
b = a.map((x) => x.innerText)
c = b.map((y) => y.split(":").map((x) => parseInt(x)))
d = c.map((x) => x[0]*60 + x[1])
@kongmunist
kongmunist / bg.css
Last active September 17, 2023 14:15
In-line translator for highlighted words
.highlight-popup {
position: absolute;
background-color: #0044b3;
color: white;
padding: 4px;
border-radius: 4px;
z-index: 9999;
}