Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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)
@peteroupc
peteroupc / CSVBuilder.rb
Last active October 22, 2015 18:51
Utility class for generating CSV files
require 'csv'
class CSVBuilder
# Initializes the CSV builder.
def initialize
@keys=[]
@items=[]
end
# Ignores certain keys previously
# added when writing the CSV.
@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 / 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 / jcbor.rb
Last active August 29, 2015 14:04
Ruby JSON-to-CBOR converter, also intended to demonstrate an issue
# Written by Peter O. in 2014.
# Any copyright is dedicated to the Public Domain.
# http://creativecommons.org/publicdomain/zero/1.0/
#
# If you like this, you should donate to Peter O.
# at: http://upokecenter.com/d/
require 'json'
module JCBOR
@peteroupc
peteroupc / utf7.js
Last active August 29, 2015 14:02
UTF-7 decoder in JavaScript
/*
Written by Peter O. in 2014.
Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/
If you like this, you should donate to Peter O.
at: http://upokecenter.com/d/
*/
var CodeUnitAppender = function() {
this.surrogate = -1;
this.lastByte = -1;
@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/