Skip to content

Instantly share code, notes, and snippets.

View scottferg's full-sized avatar

Scott Ferguson scottferg

  • Numerator/InfoScout
  • Chicago, IL
View GitHub Profile
@scottferg
scottferg / gist:3854544
Created October 8, 2012 19:51
Go GL crash OSX
panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xb code=0x1 addr=0x0 pc=0x7fff949b0af4]
goroutine 1 [running]:
goroutine 2 [syscall]:
created by runtime.main
/private/var/folders/00/0sdwh000h01000cxqpysvccm0035qk/T/bindist497693387/go/src/pkg/runtime/proc.c:221
goroutine 3 [syscall]:
@scottferg
scottferg / mmc1.go
Created September 26, 2012 01:48
NES PPU and MMC1 mapper
package main
import (
"fmt"
)
const (
BankUpper = iota
BankLower
)
func (p *Ppu) renderTileRow() {
// 32 total loops for 32 tiles, 1 pixel of each
for x := 0; x < 32; x++ {
// for i := a; i < a+0x20; i++ {
attrAddr := 0x23C0 | (p.VramAddress & 0xC00) | int(p.AttributeLocation[p.VramAddress&0x3FF])
shift := p.AttributeShift[p.VramAddress&0x3FF]
attr := ((p.Vram[attrAddr] >> shift) & 0x03) << 2
ntAddress := p.selectNametable((p.VramAddress & 0xC00) >> 10)
t := p.bgPatternTableAddress(p.Vram[(p.VramAddress&0x3FF)+ntAddress])
@scottferg
scottferg / apns.go
Created August 29, 2012 16:10
iOS Push notification service in Go
package main
import (
"bytes"
"crypto/tls"
"encoding/binary"
"encoding/hex"
"encoding/json"
"fmt"
package main
type Cpu struct {
X Word
Y Word
A Word
P Word
CycleCount int
StackPointer Word
Verbose bool
@scottferg
scottferg / gist:3189926
Created July 27, 2012 19:16
MenuInflater example
@Override
public boolean onCreateOptionsMenu(Menu aMenu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.my_main_menu, aMenu);
return true;
}
import os
import sys
sys.path.append(os.path.dirname(__file__))
sys.path.append('/usr/local/django')
os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
@scottferg
scottferg / adb_install.sh
Created September 15, 2010 14:32
Small shell script to easily deploy an Android debug build to all connected devices using adb
#!/bin/bash
for x in `adb devices | awk '/device$/ {print $1}'`; do
echo `adb -s $x install -r bin/*-debug.apk`
sleep 0;
done
@scottferg
scottferg / salr.js
Created August 31, 2010 01:46 — forked from Rohaq/salr.js
// Copyright (c) 2009, Scott Ferguson
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
@scottferg
scottferg / django_required_parameter.py
Created July 7, 2010 20:24
This decorator will validate the request parameters sent to your view. Wrap the view with @required_parameter('someparam') to validate that 'someparam' was provided.
class required_parameter(object):
def __init__(self, paramName):
self.paramName = paramName
def __call__(self, function):
def error(param):
return HttpResponse('Required parameter %s not provided' % param)
def wrapped_f(*args):
if (self.paramName in args[0].REQUEST.keys() and args[0].REQUEST.get(self.paramName)):