Skip to content

Instantly share code, notes, and snippets.

@chrisforbes
chrisforbes / glapify.py
Last active August 29, 2015 14:08
Quick hack to convert GL extension specs to Mesa's glapi xml
#!/usr/bin/env python
import sys
outmode = 0
mode = 0
data = ''
def glify(name):
return 'GL' + name if name not in ('const', 'void') else name
@chrisforbes
chrisforbes / erk
Created August 14, 2014 09:35
erk
#!/bin/bash
#
# Attach reviewed-by etc tags to the latest commit.
#
set -e
progname=$(basename "$0")
function usage () {
@chrisforbes
chrisforbes / clip.py
Created May 1, 2013 10:25
New clip shader design
# Python impl of the new gen4/5 clip shader algorithm,
# to explore it in a a slightly easier form than GEN assembly.
# just some simple 4-wide vector instructions
def swiz4(x, a, b, c, d):
return (x[a], x[b], x[c], x[d])
def add4(x, y):
return (x[0] + y[0], x[1] + y[1], x[2] + y[2], x[3] + y[3])
def neg4(x):
return (-x[0], -x[1], -x[2], -x[3])
@chrisforbes
chrisforbes / update.sh
Created November 7, 2012 01:52
mesa gl3 prettifier
#!/bin/bash
set -e
mkdir -p raw out
rm raw/GL3.txt
wget -cO raw/GL3.txt http://cgit.freedesktop.org/mesa/mesa/plain/docs/GL3.txt
sed -i 's!\(GL_\)\?\(ARB\|NV\|AMD\|EXT\|KHR\|GLX\)_\([^ )]\+\)!<a href="http://www.opengl.org/registry/specs/\2/\3.txt">\0</a>!g' raw/GL3.txt
cat > raw/preamble << EOT
<!doctype html>
@chrisforbes
chrisforbes / faster.css
Created December 8, 2011 19:04
Faster version of NZ basic layers map setup
@water: #004466;
Map { background-color: @water; }
#base-coastline, #islands { polygon-fill: #ccc; }
#rivers, #lakes { polygon-fill: @water; }
#roads { ::a { line-color: #ccc; line-width: 2.5px }
line-color: #888; }
#roads[hway_num != ''] { ::a { line-width: 3.5px; }
line-width: 2.5px; }
@chrisforbes
chrisforbes / gist:1193568
Created September 4, 2011 21:51
Python makes parsing the OpenRA Game List EASY!
>>> import yaml
>>> import urllib2
>>> content = urllib2.urlopen('http://master.open-ra.org/list.php').read()
>>> y = yaml.load(content.replace('\t',' '))
>>> print y
{'Game@0': {'Map': '700c39e1f70c06ee7a9dd119720234c3132231a0', 'Mods': 'ra', 'Name': 'OpenRA', 'Address': '82.124.81.35:1234', 'Players': 1, 'State': 2, 'TTL': 195, 'Id': 202253}, 'Game@1': {'Map': 'f9ce9066950638c1b10e9d2d34071a4adacb8071', 'Mods': 'ra@playtest-20110904', 'Name': 'not down', 'Address': '174.52.251.86:1234', 'Players': 6, 'State': 1, 'TTL': 299, 'Id': 202278}}
>>> y['Game@0']['Map']
'700c39e1f70c06ee7a9dd119720234c3132231a0'
@chrisforbes
chrisforbes / bot.py
Created August 29, 2011 03:44
Really simple IRC bot using Twisted
#!/usr/bin/env python2
"""A really simple IRC bot."""
import sys
from twisted.internet import reactor, protocol
from twisted.words.protocols import irc
class Bot(irc.IRCClient):
def _get_nickname(self):
// format80 roundtrip
var bytes = new List<byte>();
for (var q = 0; q < 4096; q++)
bytes.Add((byte)q);
var src = bytes.ToArray();
var encoded = Format80.Encode(src);
var decoded = new byte[src.Length];
if (Format80.DecodeInto(encoded, decoded) != src.Length)
throw new InvalidOperationException("Bogus length");
@chrisforbes
chrisforbes / fontgen.cs
Created January 24, 2011 03:16
Bitmap Font Generator compatible with GapiDraw 4.x
using System.Drawing;
namespace fontgen
{
static class Program
{
static void Main(string[] args)
{
var bitmap = new Bitmap(1024, 60);
var x = 0;
@chrisforbes
chrisforbes / gist:764377
Created January 4, 2011 04:11
DownloadRaw -- it sucks less than WebClient.DownloadString
using System;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading;
namespace wctest
{
static class Program