Skip to content

Instantly share code, notes, and snippets.

View adrianseeley's full-sized avatar

Adrian Seeley adrianseeley

View GitHub Profile
@adrianseeley
adrianseeley / LTTBD.cs
Created May 3, 2015 13:22
Largest-Triangle-Three Bucket Downsampling Graphs in C# (For an Array of Floats) http://i.imgur.com/UwhvV45.png
public float[] Downsample(float[] array, int Length)
{
int insert = 0;
float[] window = new float[Length];
float[] window_x = new float[Length];
int bucket_size_less_start_and_end = Length - 2;
float bucket_size = (float)(array.Length - 2) / bucket_size_less_start_and_end;
int a = 0;
int next_a = 0;
@adrianseeley
adrianseeley / Ease.cs
Created December 9, 2012 00:17
C# Ease Library :: a C# Snippet for Easing
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace YOUR_NAMESPACE_HERE_BRO
{
static class Ease
{
public static float LINEAR(float CurrentStep, float TotalSteps, float StartValue, float ValueChange)
@adrianseeley
adrianseeley / glutil.js
Last active March 22, 2023 06:10
QP GPU (queue-pee gee-pee-you, or just Q-P for short) Quantum Particles via Graphics Processing Unit
window.onerror = function (msg, url, lineno) {
alert(url + '(' + lineno + '): ' + msg);
}
function createShader (str, type) {
var shader = gl.createShader(type);
gl.shaderSource(shader, str);
gl.compileShader(shader);
if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS))
throw gl.getShaderInfoLog(shader);
@adrianseeley
adrianseeley / Ease.cs
Created February 1, 2023 11:18
Updated Ease
/// <summary>
/// Use:
/// 1. Create a new instance of the ease class where steps are time, and values are
/// the value you want to ease over that time.
/// For example moving 100 pixels in 3 seconds:
///
/// Ease myEase = new Ease
/// (
/// currentStep: 0f,
/// totalSteps: 3f,
@adrianseeley
adrianseeley / HTML5Jumper.html
Created November 30, 2012 20:12
HTML5 Canvas Dynamic Content + Follow Mouse
<html>
<div align = 'center'>
<canvas
id = 'c'
width = '800'
height = '600'
style = 'border:1px solid #000000;'>
</canvas>
<script>
@adrianseeley
adrianseeley / encrypt.js
Last active October 19, 2022 05:44
File Crypto Stream
const args = process.argv.slice(2);
const crypto = require('crypto');
const algorithm = 'aes-256-ctr';
const password = 'seelflix';
const fs = require('fs');
const path = require('path');
function read_dir (dir) {
return fs.statSync(dir).isDirectory() ? Array.prototype.concat(...fs.readdirSync(dir).map(f => read_dir(path.join(dir, f)))) : dir;
};
@adrianseeley
adrianseeley / Python Open AI Gym Ubuntu Setup
Last active July 28, 2022 21:45
Python Open AI Gym Ubuntu Setup
sudo apt-get update
sudo apt-get install python3.6
sudo apt install python3-pip
sudo apt-get -y install cmake
sudo apt install zlib1g-dev
sudo apt-get install p7zip-full
pip3 install numpy
pip3 install sklearn
pip3 install gym
pip3 install gym[Box2D]
positive_width = 185;
positive_length = 370;
positive_thick = 3;
lip_height = 3;
lip_width = 3;
negative_oversize = 3;
double_negative_oversize = 3;
module positive()
@adrianseeley
adrianseeley / pso.js
Last active June 5, 2021 12:03
JavaScript Normalized Particle Swarm Optimization Implementation - Search for an N-dimensional vector of components between -1 and +1 that optimizes a given function to a fitness of 0.
// based on http://msdn.microsoft.com/en-us/magazine/hh335067.aspx
// usage example at bottom
function pso (number_of_dimensions, function_to_optimize, number_of_particles, number_of_iterations, fitness_threshold, inertia_weight, cognitive_weight, social_weight) {
var particles = [];
var swarm_best_position = [];
var swarm_best_fitness = null;
for (var p = 0; p < number_of_particles; p++) {
particles.push({
particle_position: [],
@adrianseeley
adrianseeley / compute.html
Last active April 27, 2021 18:18
WEBGL COMPUTE SHADER SETUP
<!DOCTYPE html>
<html>
<canvas id="c" width="128" height="128"></canvas>
<script src="glutil.js"></script>
<script id="vshader" type="text/plain">
attribute vec2 vtxpos;
varying vec2 texpos;
void main() {
texpos = (vtxpos / 2.) + vec2(0.5, 0.5);
gl_Position = vec4(vtxpos, 0, 1);