Skip to content

Instantly share code, notes, and snippets.

View bangarharshit's full-sized avatar

Harshit Bangar bangarharshit

  • Twitter
View GitHub Profile
@rjrjr
rjrjr / java-sealed-class
Last active March 4, 2023 22:10
Poor Man's Sealed Classes (visitor pattern)
/**
* For Java developers all excited by and jealous of Kotlin's sealed classes.
* Do this when you wish you could put parameters on an enum.
*/
public class PoorMan {
interface Event {
<T> T dispatch(EventHandler<T> handler);
}
interface EventHandler<T> {
@krypton
krypton / colormeter.js
Created April 16, 2012 17:22
Calculate difference in percentage between 2 hex colors
function color_meter(cwith, ccolor) {
if (!cwith && !ccolor) return;
var _cwith = (cwith.charAt(0)=="#") ? cwith.substring(1,7) : cwith;
var _ccolor = (ccolor.charAt(0)=="#") ? ccolor.substring(1,7) : ccolor;
var _r = parseInt(_cwith.substring(0,2), 16);
var _g = parseInt(_cwith.substring(2,4), 16);
var _b = parseInt(_cwith.substring(4,6), 16);