Skip to content

Instantly share code, notes, and snippets.

View paulhayes's full-sized avatar

Paul Hayes paulhayes

View GitHub Profile
@paulhayes
paulhayes / pyboard.py
Created February 27, 2021 18:35
Modified version of Adafuit Ampy pyboard.py for W600 as created by @vshymanskyy
#!/usr/bin/env python
"""
pyboard interface
This module provides the Pyboard class, used to communicate with and
control the pyboard over a serial USB connection.
Example usage:
@paulhayes
paulhayes / sectorArcPath.js
Last active February 25, 2021 10:32
Sector Arc for SVG Path
let sectorArcPath = function(x,y,r,startAngle,endAngle){
endAngle = startAngle + ((endAngle-startAngle)%360);
let startX, startY, endX, endY;
startX = x+r*Math.sin(startAngle*Math.PI/180);
startY = y-r*Math.cos(startAngle*Math.PI/180);
endX = x+r*Math.sin(endAngle*Math.PI/180);
endY = y-r*Math.cos(endAngle*Math.PI/180);
let b= startY < endY ? 1 : 0;
let obtuse = Math.abs(startAngle-endAngle)>180?1:0;
let startSmaller = startAngle<endAngle ? 1 : 0;
@paulhayes
paulhayes / SaveRenderTextureToFile.cs
Last active October 30, 2020 13:55 — forked from krzys-h/SaveRenderTextureToFile.cs
[Unity] Save RenderTexture to image file
using UnityEngine;
using UnityEditor;
public class SaveRenderTextureToFile {
[MenuItem("Assets/Save RenderTexture to file")]
public static void SaveRTToFile()
{
RenderTexture rt = Selection.activeObject as RenderTexture;
Texture2D tex = new Texture2D(rt.width, rt.height, TextureFormat.RGB24, false);
@paulhayes
paulhayes / floored-division-modulo-2.js
Last active February 11, 2020 17:52
floored division modulo, where negative dividend behaves like python, i.e seamlessly into the negative range. http://jsben.ch/bU17G
//faster
const mod = (n,d)=>n-d*Math.floor(n/d)
@paulhayes
paulhayes / zigzag.h
Created February 11, 2020 17:04
zigzag oscillating function
int zigzag(int t, int scale){
return abs(scale-((t+scale)%(2*scale)));
}
[
{
"id": "68139e86.85018",
"type": "tcp in",
"z": "d29d489d.a5eb08",
"name": "tcp in",
"server": "server",
"host": "",
"port": "9000",
"datamode": "stream",
let sphereRadius = 500/2;
let baseRadius = 240/2;
let height = 26.4;
function main () {
return cylinder({r1:baseRadius,r2:baseRadius-8,start:[0,0,0],end:[0,0,height],fn:120}).subtract(
sphere({r:sphereRadius,fn:120}).translate([0,0,sphereRadius+0.6])
);
}
@paulhayes
paulhayes / readline.cpp
Last active May 4, 2019 07:12
Serial line reading for arduino
#include <Arduino.h>
bool lineMatches(char *buffer,const char *comp, int len){
return len>0 && strcmp(buffer,comp)==0;
}
bool lineStarts(char *buffer,const char *comp, int len){
if(len==0){
return false;
}
@paulhayes
paulhayes / HW-677_CH340-example.py
Last active April 17, 2019 12:40
HW-677 CH340 USB Relay Module
import sys
import serial
import time
ser = serial.Serial("COM1", 9600)
#Open Relay
ser.write( b'\xA0\x01\x01\xA2' )
time.sleep(1)
brew install ffmpeg
find . -name "*.mp4" -exec ffmpeg -i {} -ar 44000 -acodec pcm_s16le {}.wav \;