Skip to content

Instantly share code, notes, and snippets.

@peteroupc
peteroupc / GuidToDecimalString.cs
Last active August 29, 2015 14:00
Converts a GUID to a decimal number string
/*
Written in 2013 by Peter O.
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/
*/
public static string GuidToDecimalString(Guid guid) {
@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 / 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 / kineticjsbbox.js
Created November 15, 2012 00:59
Calculates the bounding box of a KineticJS path
/* This file is in the public domain. Peter O., 2012. http://upokecenter.dreamhosters.com
Public domain dedication: http://creativecommons.org/publicdomain/zero/1.0/legalcode */
/* NOTE: Currently supports lines only */
function RectAccum(){
this.left=0;
this.top=0;
this.right=0;
this.bottom=0;
@peteroupc
peteroupc / gist:4187083
Last active October 13, 2015 11:17
Gets a timing function from a "transition-timing-function" string
// Gets a timing function from a "transition-timing-function" string
// Written by Peter O. in 2012, released to the public domain
// Returns the function itself if the object passed in is a Function object,
// or the "ease" function if the object is null or undefined
// This file is in the public domain. Peter O., 2012. http://upokecenter.dreamhosters.com
// Public domain dedication: http://creativecommons.org/publicdomain/zero/1.0/
function getTimingFunction(f){
if(typeof f=="undefined" || f==null)f="ease";
if(typeof f=="function" || (f && f.constructor==Function))return f;
if(f=="step-start")return function(v){ return (v>0) ? 1.0 : 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 / ReflectionUtil.cs
Last active December 12, 2015 01:28
Reflection utility methods
// This file is in the public domain. Peter O., 2013. http://upokecenter.dreamhosters.com
// Public domain dedication: http://creativecommons.org/publicdomain/zero/1.0/
using System;
using System.Reflection;
namespace PeterO
{
public static class ReflectionUtil {
@peteroupc
peteroupc / Reflection.java
Created February 1, 2013 12:52
Reflection utility methods
// This file is in the public domain. Peter O., 2013. http://upokecenter.dreamhosters.com
// Public domain dedication: http://creativecommons.org/publicdomain/zero/1.0/
package com.upokecenter.util;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
public final class Reflection {
@peteroupc
peteroupc / gist:5191297
Last active December 15, 2015 02:59
Snippet that generates a color gradient
// Written by Peter O. 2013. In the public domain.
// http://creativecommons.org/publicdomain/zero/1.0/
Color BlendColors(Color crDst, Color crSrc, byte alpha){
switch(alpha){
case 0x00:return crDst;
case 0xFF:return crSrc;
default:{
int r,g,b,a;
r=crDst.R;
@peteroupc
peteroupc / QueryStringHelper.java
Created May 23, 2013 03:12
A Java utility class for parsing query strings.
package com.upokecenter.util;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
// Written by Peter O. in 2013.
// Any copyright is dedicated to the Public Domain.
// http://creativecommons.org/publicdomain/zero/1.0/