Skip to content

Instantly share code, notes, and snippets.

@minism
minism / color.py
Created January 10, 2012 18:39
python terminal colors
# Terminal color definitions
class fg:
BLACK = '\033[30m'
RED = '\033[31m'
GREEN = '\033[32m'
YELLOW = '\033[33m'
BLUE = '\033[34m'
MAGENTA = '\033[35m'
CYAN = '\033[36m'
@minism
minism / binary.lua
Created September 5, 2012 22:31
lua binary data packing
-- Fast functions for working with binary data
return {
decode_uint8 = function(str, ofs)
ofs = ofs or 0
return string.byte(str, ofs + 1)
end,
decode_uint16 = function(str, ofs)
ofs = ofs or 0
local a, b = string.byte(str, ofs + 1, ofs + 2)
@minism
minism / MapOutputNodeView.cs
Created October 10, 2021 00:44
NodeGraphProcessor - NodeView with texture preview example
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using UnityEditor.UIElements;
using UnityEditor.Experimental.GraphView;
using UnityEngine.UIElements;
using GraphProcessor;
[NodeCustomEditor(typeof(MapOutputNode))]
@minism
minism / gist:1928314
Created February 28, 2012 01:10
Git merge theirs
# in case branchA is not our current branch
git checkout branchA
# make merge commit but without conflicts!!
# the contents of 'ours' will be discarded later
git merge -s ours branchB
# make temporary branch to merged commit
git branch branchTEMP
SRCS=$(wildcard *.c)
OUTDIR=dist
TARGET=$(OUTDIR)/app
all: $(TARGET) $(TARGET).exe
clean:
rm -f $(OUTDIR)
$(OUTDIR):
@minism
minism / gist:0e8cf6a653bed32bf887ed57a59a7971
Created April 25, 2020 08:22
Simple https nginx config to route to docker containers by subdomain
upstream foo {
server foo-container:80;
}
upstream bar {
server bar-container:3000;
}
map $subdomain $container {
foo foo;
@minism
minism / type_checking.py
Created October 31, 2013 00:39
Python runtime type checking concept
# Runtime type checking concept
from functools import wraps
def signature(*types):
def decorator(func):
@wraps(func)
def wrapper(*args, **kwargs):
for i, t in enumerate(types):
if i >= len(args):
import random
import pprint
import sys
# 7 Prisoners, 1 designated counter
prisoners = [
{"seen": False, "is_counter": False, "messaged": False},
{"seen": False, "is_counter": False, "messaged": False},
{"seen": False, "is_counter": False, "messaged": False},
@minism
minism / truncate_auto_tables.sql
Created February 12, 2013 20:38
Truncate autopopulated django tables to prepare loaddata
SET FOREIGN_KEY_CHECKS=0;
truncate table `auth_user_user_permissions`;
truncate table `auth_permission`;
truncate table `django_content_type`;
SET FOREIGN_KEY_CHECKS=1;
@minism
minism / .bashrc
Last active December 11, 2015 04:59
# Returns "*" if the current git branch is dirty.
_parse_git_dirty()
{
[[ $(git diff --shortstat 2> /dev/null | tail -n1) != "" ]] && echo "*"
}
# Get the current git branch name (if available)
_git_prompt()
{
local ref=$(git symbolic-ref HEAD 2>/dev/null | cut -d'/' -f3)