Skip to content

Instantly share code, notes, and snippets.

View vgel's full-sized avatar

Theia Vogel vgel

View GitHub Profile
@vgel
vgel / tinystackr3.py
Created July 8, 2012 23:59
Tiny stack-based language in python.
stack = []
compileStacks = []
words = {}
builtins = {}
lambdaType = type(lambda x: x) #cannot compare against the function type directly for some reason
def prn(o):
print(o)
def clr(l):
@vgel
vgel / fileserver.py
Created July 9, 2012 14:16
A very basic HTTP file server in 13 lines of python. Assumes all requests are GETs, and it vulnerable to directory traversal (Run it in ~ and localhost:8080/../../ will ls root), so don't use it online. Will correctly list files in directories.
import sys, os, socket
s = socket.socket()
s.bind((sys.argv[1], int(sys.argv[2])))
s.listen(5)
try:
while True:
conn, addr = s.accept()
path = os.path.join(os.getcwd(), "./"+conn.recv(4096).split("\n")[0].split(" ")[1])
conn.send((open(path).read() if os.path.isfile(path) else reduce(lambda x,s:x+"\n"+s+("/" if os.path.isdir(s) else ""),sorted(os.listdir(path)),"Directory "+path+" ls")) if os.path.exists(path) else '404: '+path)
conn.close()
@vgel
vgel / gist:3098126
Created July 12, 2012 13:32
A autocomplete-like word suggester. Run with `python <file> "/usr/share/dict/words"` Enter words at command line and hit enter for suggestions
import sys
t={}
def w(o):
c=t
for l in o:
c[l]=c[l]if l in c else{}
c=c[l]
c[None]=None
g=lambda t,b,i:reduce(lambda i,l:i+[b]if l is None else g(t[l],b+l,i),t,i)
map(w,open(sys.argv[1]).read().split("\n"))
@vgel
vgel / a.py
Created July 20, 2012 19:55
simple platformer. run python a.py mapfile
import pygame as pg,sys
pg.init()
w=pg.display.set_mode((100,)*2)
o=list(open(sys.argv[1]).read().replace("\n",""))
px=py=50
j=0
k=pg.key.get_pressed
t=lambda x,y:o[x/5+y/5*20]
z=lambda i:min(95,max(0,i))
while True:
@vgel
vgel / golfed-msgboard.py
Created July 23, 2012 12:47
A simple message-board-type site in golfed python. Expanded version below if you can't read golfed code or want comments.
import BaseHTTPServer as b,sys,os,json,urlparse
p=(json.loads(open(sys.argv[1]).read()) if os.path.exists(sys.argv[1]) else {})
n="<br/>"
h="""<form action=%s method="post">Post: <textarea name="a"></textarea><input type="submit" value="Post!"/></form>"""
y=lambda s:urlparse.parse_qs(s)['a'][0]
class F(b.BaseHTTPRequestHandler):
def do_GET(s):
s.send_response(200)
s.send_header("Content-type","text/html")
s.end_headers()
from math import *
import random, time, pygame
x=0
y=1
z=2
def t3d_2d(a,c,t,e):
dx = cos(t[y]) * (sin(t[z]) * (a[y] - c[y]) + cos(t[z]) * (a[x] - c[x])) - sin(t[y]) * (a[z] - c[z])
dy = sin(t[z]) * (cos(t[y]) * (a[z] - c[z]) + sin(t[y]) * (sin(t[z]) * (a[y] - c[y]) + cos(t[z]) * (a[x] - c[x]))) + cos(t[x]) * (cos(t[z]) * (a[y] - c[y]) - sin(t[z]) * (a[x] - c[x]))
dz = cos(t[x]) * (cos(t[y]) * (a[z] - c[z]) + sin(t[y]) * (sin(t[z]) * (a[y] - c[y]) + cos(t[z]) * (a[x] - c[x]))) - sin(t[x]) * (cos(t[z]) * (a[y] - c[y]) - sin(t[z]) * (a[x] - c[x]))
import re, logging, time, cProfile
class Word(object):
def __init__(self, function, name, types, inputs):
if name == '':
raise ValueError("Invalid name.")
self.name = name
self.function = function
self.types = types
@vgel
vgel / RenderPortal
Created June 16, 2013 03:28
FUCK FUCK FUCK
WorldServer worldServer = DimensionManager.getWorld(dim);
if (worldServer == null) {
DimensionManager.initDimension(dim);
worldServer = DimensionManager.getWorld(dim);
}
if (dim != dimRendering) {
dimRendering = dim;
privRG.setWorldAndLoadRenderers(Minecraft.getMinecraft().theWorld);
}
System.out.println("render " + MinecraftForgeClient.getRenderPass());
@vgel
vgel / kinect-scroll.py
Created July 1, 2013 23:01
Some kinect scrolling junk
#! /usr/bin/python
from openni import *
import kinect_motor
import uinput
import math
grabbed = False
def setup_uinput():
@vgel
vgel / installingamarok.mkd
Last active February 13, 2022 02:29
How to compile and install Amarok

How to Build (and Install) Amarok from Source

First, install the build dependencies for amarok. Mostly, these are just headers and support libraries to hook into KDE. On debian-based systems, you can simply run # apt-get install build-essential git-core; apt-get build-dep amarok as root.

Then, using git, clone the amarok repository from KDE's anongit:

git clone git://anongit.kde.org/amarok.git; cd amarok

Before doing anything else, you should check the README and INSTALL files to see if anything has changed in these steps. They will note any important build updates.