Skip to content

Instantly share code, notes, and snippets.

@pieman72
pieman72 / esheep.php
Created July 2, 2014 10:15
E-Sheep! They're what computers dream about.
<?// Generate a random image based on a key
$key = sha1(isset($_GET['s']) ? $_GET['s'] : rand());
$WIDTH = isset($_GET['w']) ? $_GET['w'] : 150;
$HEIGHT = isset($_GET['h']) ? $_GET['h'] : 150;
// Globals
$MAX_SAT_LOSS = 0.4; // 0 - 1.0
$MAX_LUM_SKEW = 0.25; // 0 - 0.5
$COLORS = array();
$IMG = imagecreatetruecolor($WIDTH, $HEIGHT);
@pieman72
pieman72 / git.makefile
Last active August 29, 2015 14:16
A starter makefile with git recipes
# Colorize output
COLORS:=$(shell tput colors 2> /dev/null)
ifeq ($(COLORS), 256)
COLOR_RESET=\033[0;39;49m
COLOR_BOLD=\033[1m
COLOR_ULINE=\033[4m
COLOR_BOLD_OFF=\033[0;21m
COLOR_ULINE_OFF=\033[0;24m
COLOR_NORM=\033[0;39m
COLOR_GREN=\033[38;5;118m
@pieman72
pieman72 / hex_to_ansi
Last active October 18, 2024 17:31
Hex to ANSI color code converter
function hex_to_ansi(){
# Get the individual color components as decimals
HEX=$(echo "$1" | tr -d '#' | tr '[:lower:]' '[:upper:]')
DIGITS=$(( ${#HEX} / 3 ))
R=$(( 16#${HEX:$(( DIGITS * 0 )):$DIGITS} ))
G=$(( 16#${HEX:$(( DIGITS * 1 )):$DIGITS} ))
B=$(( 16#${HEX:$(( DIGITS * 2 )):$DIGITS} ))
# Handle grey ramp
if [ "`echo $(( R-G )) | tr -d '-'`" -lt 16 ]\
@pieman72
pieman72 / CheckBraces.java
Created August 3, 2015 07:21
A quick java program to check proper matching of braces in a file.
import java.io.*;
public class CheckBraces{
// Print errors and set exit status
public static void die(String msg){
System.err.println(msg);
System.exit(1);
}
// Process a file named with a CLI arg