Skip to content

Instantly share code, notes, and snippets.

@cosinekitty
cosinekitty / picrunch.py
Created December 28, 2019 20:54
Python program to calculate pi to one million digits after the decimal point.
#!/usr/bin/env python3
#
# picrunch.py - by Don Cross
#
# Use Machin's Formula
# pi = 4*(4*arctan(1/5) - arctan(1/239))
# to calculate pi to one million places after the decimal.
#
import sys
#include <cstdio>
#include <cmath>
#include <string>
#include "raylib.h"
#include "waterpool.hpp"
const int WIDTH = 160;
const int HEIGHT = 160;
using PoolType = Sapphire::WaterPool<WIDTH, HEIGHT>;
@cosinekitty
cosinekitty / vcvbuild.sh
Last active February 26, 2024 22:04
Script for building VCV Rack 2.4.1 with my improved (low-latency) PulseAudio anti-glitching fix applied.
#!/bin/bash
Fail()
{
echo "vcvbuild.sh: $1"
exit 1
}
CloneVcv()
{
@cosinekitty
cosinekitty / glitchfix.sh
Created November 27, 2022 00:23
Build VCV Rack with and without audio glitch fix
#!/bin/bash
#-------------------------------------------------------------------------------
#
# glitchfix.sh - Don Cross <cosinekitty@gmail.com>
#
# Script that builds two copies of VCV Rack 2.2.0,
# one from original source code, another with the
# following fix for a glitching issue when sending
# output audio to PulseAudio on Linux:
#
@cosinekitty
cosinekitty / LocationToPoint.js
Created December 5, 2019 02:06
Converting GPS coordinates to Cartesian coordinates and normal vector.
function LocationToPoint(c)
{
// Convert (lat, lon, elv) to (x, y, z).
var lat = c.lat * Math.PI / 180.0;
var lon = c.lon * Math.PI / 180.0;
var radius = EarthRadiusInMeters(lat);
var clat = GeocentricLatitude(lat);
var cosLon = Math.cos(lon);
var sinLon = Math.sin(lon);
@cosinekitty
cosinekitty / randomvector.py
Created July 19, 2020 19:37
Python function for generating unbiased direction unit vectors
import math
import numpy
def randomvector(n):
components = [numpy.random.normal() for i in range(n)]
r = math.sqrt(sum(x*x for x in components))
v = [x/r for x in components]
return v
function abs(x) {
return Math.abs(v(x));
}
function v(x) {
if (typeof x !== 'number') {
console.trace();
throw `Not a numeric type: ${x}`;
}
if (isNaN(x)) {
console.trace();
throw 'NAN result';
}
#include <stdio.h>
#include <math.h>
double Distance(double x, double y)
{
/* Intentional bug for illustration... */
return sqrt(-1.0);
}
int main()
function Polar(x, y) {
return {
angle: Math.atan2(y, x),
radius: Math.sqrt(x*x + y*y)
};
}