Skip to content

Instantly share code, notes, and snippets.

View tildedave's full-sized avatar
🌮
Hungry

Dave King tildedave

🌮
Hungry
View GitHub Profile
@tildedave
tildedave / watch-out-for-class-variables.py
Created December 29, 2011 16:53
Don't initialize variables in the class, initialize them in the constructor
class Object(object):
l = []
def __init__(self):
pass
def add_one(self):
self.l.append(1)
@tildedave
tildedave / FN_CMD.DO_+TRANSPORT
Created December 28, 2011 01:04
do-+transport code, broken out to be readable
[syspemit(%#,
You take [setr(g,a transport from [ansi(hy,[name(loc(%!))])]
to [ansi(hy,[name(%qd)])]. The trip takes
[setq(h,u(fn_get_travel_time_between_systems,
u(zone(loc(%!))/fn_get_system),
u(zone(squish(%qd))/fn_get_system)))]
[iter(timestring(mul(%qh,60,60)),
if(and(f(strmatch(##,0*)),
f(strmatch(##,*m)),
@tildedave
tildedave / gist:1525601
Created December 28, 2011 00:56
intersteller transport function from one of my old MUSHes
PARENT: Intergalactic Transportation Node(#690TWn)
Type: THING Flags: WIZARD NO_COMMAND
An intergalactic transport node. See [ansi(hy,+help transports)] for information as to their use.
Owner: Pozzo(#270POWwerACMcJ) Zone: *NOTHING* Building Chips: 10
Parent: *NOTHING*
Powers:
Channels: SpaceMonitor
Warnings checked:
Created: Thu May 20 20:53:07 2004
Last Modification: Sun Mar 18 17:53:42 2007
CMD_SHOWGRID [#270R]: $^\+showgrid(/lr|/sm)?$:@switch [u(fn_grid_is_active)][and(hasattr(v(ship_obj),coords),hasattr(v(ship_obj),orientation))]=0*,{th syspemit(%#,The grid is not currently active.)},10,{th syspemit(%#,[ansi(hw,u(v(ship_obj)/get_name))] is not on the grid.)},{@pemit %#=[ulocal(fn_generate_[switch(%1,/lr,long,/sm,small,short)]_range_grid)]}
FN_GENERATE_SHORT_RANGE_GRID [#270]: [setq(0,ulocal(fn_generate_grid_info))][setq(1,ulocal(fn_get_extended_info,ulocal(fn_fill_and_rotate_larger_space_objects,ulocal(fn_generate_grid_legend,filter(fn_detects_object,ulocal(fn_adjust_coords_to_absolute_val,map(fn_adjust_relative_coords,%q0),short)))),rest(v(short_range_params))))][ulocal(fn_display_grid_and_legend,ulocal(fn_fill_short_range_grid,%q1),%q1)]
FN_GENERATE_LONG_RANGE_GRID [#270]: [setq(0,ulocal(fn_generate_grid_info))][setq(1,ulocal(fn_get_extended_info,ulocal(fn_fill_and_rotate_larger_space_objects,ulocal(fn_generate_grid_legend,filter(fn_detects_object,ulocal(fn_adjust_coords_to_absolute_val,ma
@tildedave
tildedave / who.mushcode
Created December 10, 2011 18:06
The +who function for one of my old MUSHes
FN_WHO [#1018]: [setq(1,words(lwho())%b[switch(words(lwho()),1,person,people)]%bconnected)][header(,%q1,,hw,hb)]%r%b%b[ljust(ansi(h,Player Name),20)][ljust(ansi(hw,Alias),10)][ljust([ansi(h,Status)],8)][ljust([ansi(hw,On For)],10)][ljust([ansi(h,Idle)],4)][iter(%0,%r[ifelse(orflags(##,WrJ),ansi(gh,\%)%b,%b%b)][ljust(ifelse(orflags(##,WrJ),ansi(yh,name(##)),name(##)),20)][ljust(alias(##),10)][ljust([xget(##,status)],8)][ljust([rjust(mod(div(conn(##),3600),100),2,0)]:[rjust(mod(div(conn(##),60),60),2,0)]:[rjust(mod(conn(##),60),2,0)],10)][ljust([first([timestring([idle(##)])])],4)])]%r[setq(0,[mudname()])][header(\% -- Staff,[mudname()],gh,yh,bh)]
@tildedave
tildedave / hello.C
Created October 11, 2011 16:12
objdump of "hello world" in C
#include <stdio.h>
int main(void) {
printf("hello, world!\n");
return 0;
}
@tildedave
tildedave / greenbar.py
Created August 17, 2011 10:41
nosetests from the browser for TDD heaven
#!/usr/bin/python26
import bottle
import sys
from StringIO import StringIO
from bottle import route, run
from optparse import OptionParser
from subprocess import Popen, PIPE
@tildedave
tildedave / continuous-deploy.py
Created June 17, 2011 12:43
Automated WAR Deployer (in Python)
#!/bin/python2.6
import os
import sys
import shutil
import subprocess
import time
from optparse import OptionParser
JAVA_HOME="/usr/lib/jvm/java-1.6.0-openjdk/"
@tildedave
tildedave / algebra.v
Created June 15, 2011 04:12
abstract algebra from pinter's "A Book of Abstract Algebra"
Section Declaration.
Variable G : Set.
Variable op : G -> G -> G.
Variable inv : G -> G.
Variable e : G.
Notation "a * b" := (op a b).
Hypothesis assoc : forall a b c : G, a * (b * c) = (a * b) * c.
@tildedave
tildedave / calculator.js
Created June 8, 2011 04:00
Conditional probability calculator
// Intended use:
//
// Initialize with variableNames and variableMaxes.
// variableNames looks like {"A" : 0, "B": 1, "C" : 2, etc}
// variableMaxes looks like {"A": 3, "B": 6, "C": 2, etc}.
// These variables take on discrete values between 1 and their maximum.
// Data is parsed from a format like
// A B C P(A,B,C)
// where the final is a float. for example,