Skip to content

Instantly share code, notes, and snippets.

@peteroupc
peteroupc / QueryStringHelper.cs
Last active October 18, 2023 09:20
A C# utility class for parsing query strings.
// Written by Peter O.
// Any copyright to this work is released to the Public Domain.
// https://creativecommons.org/publicdomain/zero/1.0/
//
//
//
using System;
using System.Collections.Generic;
using System.Globalization;
@peteroupc
peteroupc / planecube.js
Last active August 25, 2023 08:12
Generates a convex hull of the half-space representation of several planes
/*
Any copyright to this file is released to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/
If you like this, you should donate
to Peter O. (original author of
the Public Domain HTML 3D Library) at:
http://peteroupc.github.io/
*/
(function(global) {
"use strict";
@peteroupc
peteroupc / LineReader.js
Last active November 22, 2022 04:05
JavaScript class for reading files line by line in HTML5 apps
/*
Written by Peter O.
Any copyright to this work is released to the Public Domain.
In case this is not possible, this work is also
licensed under Creative Commons Zero (CC0):
https://creativecommons.org/publicdomain/zero/1.0/
*/
@peteroupc
peteroupc / hlshsv.cs
Created November 16, 2012 09:08
Conversion from HLS direct to HSV and back
/* This file is in the public domain. Peter O., 2012. http://upokecenter.dreamhosters.com
Public domain dedication: http://creativecommons.org/publicdomain/zero/1.0/ */
using System;
namespace PeterO
{
public class ColorUtil
{
// Assumes hsv[0] is from 0-360, and hsv[1] and hsv[2] are from 0-1
public static double[] HsvToHls(double[] hsv){
@peteroupc
peteroupc / rubyutil.rb
Last active May 28, 2021 22:23
Utility classes and methods for Ruby.
#!/usr/bin/ruby
# Utility methods for Ruby. Peter O., 2013-2019.
# Any copyright to this work is released to the Public Domain.
# https://creativecommons.org/publicdomain/zero/1.0/
#
#
require 'digest'
require 'fileutils'
require 'json'
@peteroupc
peteroupc / assertcode.rb
Last active May 28, 2021 22:23
Replaces pseudo method calls in C# or Java source code with argument check code.
#!/usr/bin/ruby
=begin
Written by Peter O.
Any copyright to this work is released to the Public Domain.
In case this is not possible, this work is also
licensed under Creative Commons Zero (CC0):
https://creativecommons.org/publicdomain/zero/1.0/
@peteroupc
peteroupc / OggMetadata.rb
Last active December 4, 2020 01:14
Reads metadata from an Ogg file
#!/usr/bin/ruby
# Written by Peter O.
# Any copyright to this work is released to the Public Domain.
# http://creativecommons.org/publicdomain/zero/1.0/
#
# If you like this, you should donate to Peter O.
# at: http://peteroupc.github.io/
#
# Usage:
@peteroupc
peteroupc / abnfreader.rb
Last active October 12, 2019 21:18
ABNF parser and reader
class TokenSymbolParser
def initialize(token,prod)
@token=token
@prod=prod
end
def parse(str)
return _parseOne(@token,str,0,str.length)
end
private
def _parseOne(token,str,index,endIndex)
@peteroupc
peteroupc / polygonwkt.java
Last active April 20, 2017 03:38
Generates polygon WKT from an array of latitude/longitude coordinates
/*
Any copyright to this file is released to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/
If you like this, you should donate
to Peter O. at:
http://peteroupc.github.io/
*/
public static String polygonWkt(double[] latlon){
if(latlon.length%2 != 0)
@peteroupc
peteroupc / isprime.rb
Last active November 4, 2016 09:55
Ruby function for checking primality (prime number status) of 31-bit integers
#!/usr/bin/ruby
def modPow(x,pow,mod)
r = 1;
v = x;
while (pow != 0)
if ((pow & 1) != 0)
r = (r*v)%mod;
end
pow >>= 1;
if (pow != 0)