Skip to content

Instantly share code, notes, and snippets.

View paulhayes's full-sized avatar

Paul Hayes paulhayes

View GitHub Profile
@paulhayes
paulhayes / sdkmanager.bat
Created March 18, 2024 12:17
Fix for Android's SDK Manager, shipped with Unity 2021.3
@if "%DEBUG%" == "" @echo off
@rem ##########################################################################
@rem
@rem sdkmanager startup script for Windows
@rem
@rem ##########################################################################
@rem Set local scope for the variables with windows NT shell
echo "MEEP2"
slot_dim = 15.4;
thickness = 4;
length = 40;
outer_scale = (slot_dim+2*thickness)/slot_dim;
difference(){
hull() for(a=[0,90,180,270]){
rotate([45,0,a]) rotate([90,0,0])
scale(outer_scale) translate([-slot_dim/2,-slot_dim/2,10]) cube([slot_dim,slot_dim,length/outer_scale]);
@paulhayes
paulhayes / LocalOrOnlinePhotonConnect.cs
Created June 18, 2023 12:49
Check for fixed IP local server, and if not found, connect to default online photon settings.
using System.Collections;
using System.Collections.Generic;
using Photon.Pun;
using Photon.Realtime;
using UnityEngine;
public class LocalOrOnlinePhotonConnect : MonoBehaviour, IConnectionCallbacks
{
[SerializeField] ServerSettings photonOnlineSettings;
[SerializeField] Photon.Realtime.AppSettings photonOfflineSettings;
@paulhayes
paulhayes / RigidbodyTrackTransform.cs
Created October 23, 2022 21:11
Simple component for controlling a rigid bodies position and rotation using just the application of forces. Good for allowing playing manipulation of physics simulation.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class RigidbodyTrackTransform : MonoBehaviour
{
[SerializeField] Rigidbody body;
[SerializeField] Transform target;
[SerializeField] float maxSpeed = 30f;
[SerializeField] float maxRotSpeed = 720f;
@paulhayes
paulhayes / utils.scad
Last active July 17, 2022 10:55
OpenScad Polygon utilities. Includes smooth_corners and truncate_corners modules.
function normalize(v) = norm(v)==0 ? 0 : v/norm(v);
function wrap(i,l) = ((i%l)+l)%l;
function lerp(start, end, bias) = (end * bias + start * (1 - bias));
function truncate_corners(points,size) = [
for(i=[0:len(points)-1])
for(j=[-1,1]) points[i]+size*normalize(points[wrap(i+j,len(points))]-points[i])
];
using UnityEditor;
/// <summary>
/// Attribute to select a single layer.
/// </summary>
public class LayerAttribute : PropertyAttribute
{
// NOTHING - just oxygen.
}
@paulhayes
paulhayes / TinyTone.h
Last active December 3, 2021 10:44
For Atmel ATTiny13A microcontroller. Output generated on PB0 ( D0 )
#define SPEAKER_PIN PB0
static void timer_set(uint8_t OCRxn, uint8_t N);
static void timer_clear();
static void tone(uint16_t freq);
static void notone();
void enable_tone()
{
TCCR0A |= _BV(WGM01); // set timer mode to Fast PWM
# This file is executed on every boot (including wake-boot from deepsleep)
#import esp
#esp.osdebug(None)
#import webrepl
#webrepl.start()
import network
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
if not wlan.isconnected():
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 / 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: