Skip to content

Instantly share code, notes, and snippets.

@Higgs1
Higgs1 / gist:9221555
Created February 26, 2014 01:18
My custom Minecraft launcher
#!/usr/bin/env bash
cd "$(dirname "$(realpath "$0")")"
source minecraft.properties
exec java -cp minecraft.zip -Djava.library.path=natives -Dfml.ignoreInvalidMinecraftCertificates=true -Dfml.ignorePatchDiscrepancies=true net.minecraft.launchwrapper.Launch --tweakClass cpw.mods.fml.common.launcher.FMLTweaker --assetsDir assets --gameDir data --username $username --session $session --version $version
@Higgs1
Higgs1 / README.md
Last active August 29, 2015 14:08
Python 3.4 API for DeckBrew.com's MTG card search.

Replace all duplicate url parameters with a list of values.
Boolean values must be written as 'true' or 'false'.
Typeahead call has a slightly different pattern, for convenience.
All paginated API calls are wrapped into a generator.
All non-paginated API calls are cached.
Errors throw DeckBrewError.

Python: db = DeckBrewAPI()

HTTP: GET /mtg/cards

@Higgs1
Higgs1 / a85decode_yz.js
Last active August 29, 2015 14:09
Ascii85 codecs for Javascript
/* This decoder supports both space and null byte folding,
and completely ignores all invalid characters (whitespace, misplaced x's and z's, etc).
Does not handle Adobe's <~ ~> frame.
Licensed under CC0. */
function a85decode(ascii85) {
for (var a = String, b = a.fromCharCode, c = ascii85.length, d = "", e = 0, f = 0, g = 0, h, i; i = a.charCodeAt(ascii85, e++) - 33, e <= c;
0 <= i && 85 > i ? (g = 85 * g + i, 4 < ++f && (h = b(g & 255), h = b((g >>>= 8) & 255) + h, h = b((g >>= 8) & 255) + h, d += b(g >> 8) + h, f = g = 0)) : f || (d += 88 == i ? " " : 89 == i ? "\0\0\0\0" : ""));
if (!f) return d;
for (e = 5 - f; g = 85 * g + 84, --e;);
return h = b(g & 255), h = b((g >>>= 8) & 255) + h, h = b((g >>= 8) & 255) + h, (d + b(g >> 8) + h).substring(0, d.length +-- f);
@Higgs1
Higgs1 / gist:369c249f7f4bd7ab2244
Created December 21, 2014 20:12
Python switch statement
class switch:
def __init__(_,o):_._,_.o=0,o
def __iter__(_):yield _.__
def __(_,*o):
if _._ or not o:return 1
elif _.o in o:_._=1;return 1
"""
Usage:
import string
@Higgs1
Higgs1 / gist:fee62d230bd87257e0b0
Last active August 29, 2015 14:11
UUID for Python 3
# Simple UUID class for python. Doesn't currently create random UUIDs.
# Supports conversion between byte, octal, integer, hexadecimal, RFC formatted,
# base64 (with or w/o padding), base85, and ascii85 representations.
# Supports various math and boolean operations as if it were an integer.
import functools, builtins, base64, struct, re
Q=0xFFFFFFFFFFFFFFFF
@functools.total_ordering
class UUID:
@Higgs1
Higgs1 / gist:16c8447fcbcf39d6f7df
Last active August 29, 2015 14:17
Javascript RGB ⇔ HSV
// Returns [hue, sat, val]. All 6 values are between 0...1.
function rgb2hsv(r, g, b) {
var v = Math.max(r, g, b),
x = v - Math.min(r, g, b);
return [
( x == 0 ? 0 :
v == g ? (b - r) / x + 2 :
v == b ? (r - g) / x + 4 :
(g - b) / x + 6
@Higgs1
Higgs1 / gist:f2a53a5e77a902d1e00e
Last active August 29, 2015 14:17
CoffeeScript RGB ⇔ HSV
# Returns [hue, sat, value] when given red, green, blue. All 6 values are between 0...1.
rgb2hsv = (r, g, b) ->
v = Math.max r, g, b
x = v - Math.min r, g, b
[
( if x is 0
0
else if v is r
(g - b) / x
else if v is g
@Higgs1
Higgs1 / gist:0efe62a05fa12d3333dc
Last active August 29, 2015 14:17
CoffeeScript UTF8 Codec
# Converts UCS2 to UTF8
utf8_encode = (s) ->
unescape encodeURIComponent s
# Converts UTF8 to UCS2
utf8_decode = (s) ->
decodeURIComponent escape s
@Higgs1
Higgs1 / gist:e49068823a8779a83dd6
Created March 20, 2015 22:04
CoffeeScript Sum Function
sum = (arr, start = 0) ->
arr.reduce (x, y) ->
x + y
, start
@Higgs1
Higgs1 / gist:24691a16f5cf98bb58a2
Last active August 29, 2015 14:17
CoffeeScript Bitwise Left Rotate
rotl = (a, b) ->
a << b | a >>> 32 - b