Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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.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 / 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/
@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 / typography.less
Last active December 26, 2015 08:19
LESS functions for enabling beautiful typography in Web pages
/////////////////////////////////////////////////////////////
//
// LESS functions for enabling beautiful typography
// in Web pages. Written by Peter O., 2013-2015.
//
// 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.dreamhosters.com/articles/donate-now-2/