Skip to content

Instantly share code, notes, and snippets.

@gvx
gvx / roundrect.lua
Created February 18, 2014 15:13
Rounded rectangles
function love.graphics.roundrect(mode, x, y, width, height, xround, yround)
local points = {}
local precision = (xround + yround) * .1
local tI, hP = table.insert, .5*math.pi
if xround > width*.5 then xround = width*.5 end
if yround > height*.5 then yround = height*.5 end
local X1, Y1, X2, Y2 = x + xround, y + yround, x + width - xround, y + height - yround
local sin, cos = math.sin, math.cos
for i = 0, precision do
local a = (i/precision-1)*hP
class LinkedList:
next = None
val = None
def __init__(self, val):
self.val = val
def add(self, val):
if self.next is None:
self.next = LinkedList(val)
@gvx
gvx / Easy output
Created July 16, 2014 22:06
Daily Programmer #171 Easy/Intermediate
xxxxxxxx
x x
x xxxx x
x x x x
x x x x
x xxxx x
x x
xxxxxxxx
---
@gvx
gvx / classes.lua
Created July 26, 2014 19:34
A simple, alternative class system for Lua
return function(name)
local class = require(name)
local classmt = getmetatable(class)
if getmetatable(class) == nil then
local props = {unpack(class)}
for i = #class, 1, -1 do
class[i] = nil
end
local classmt = {}
local instancemt = {__index = class}
@gvx
gvx / keybase.md
Created September 27, 2014 15:01

Keybase proof

I hereby claim:

  • I am gvx on github.
  • I am robinwell (https://keybase.io/robinwell) on keybase.
  • I have a public key whose fingerprint is 43E3 C73A 188A 844E 39F1 EEBA E429 16EB 3793 DA2D

To claim this, I am signing this object:

@gvx
gvx / output
Last active August 29, 2015 14:11
named tuple performance
$ py3.3 time_them.py
default implementation:
2.1573487099958584
my implementation:
0.7448599760100478
$ py3.3 time_them_2.py
default implementation:
0.6372028530022362
my implementation:
0.20809232600731775
@gvx
gvx / switch.py
Created November 8, 2008 08:17
A switch function for Python
#By Robin Wellner (gvx)
#I hereby waive copyright and related or neighboring rights to this work
#See the Creative Commons Zero Waiver at <http://creativecommons.org/publicdomain/zero/1.0/>
def switch(expression, cases, default=None):
try:
ret = cases[expression]
except KeyError:
ret = default
if callable(ret): ret = ret()
@gvx
gvx / mutable.py
Created November 12, 2008 15:27
Immutable objects made mutable
#By Robin Wellner (gvx)
#I hereby waive copyright and related or neighboring rights to this work
#See the Creative Commons Zero Waiver at <http://creativecommons.org/publicdomain/zero/1.0/>
class mutable(object):
def __init__(self, obj):
self._obj = obj
def __repr__(self):
return 'mutable('+repr(self._obj)+')'
def __call__(self, obj=None):
@gvx
gvx / ROT13.py
Created November 16, 2008 08:04
A ROT13 function for Pyton.
#By Robin Wellner (gvx)
#I hereby waive copyright and related or neighboring rights to this work
#See the Creative Commons Zero Waiver at <http://creativecommons.org/publicdomain/zero/1.0/>
def rotn(intext, n):
outtext = []
for char in intext:
if 65 <= ord(char) < (65+26):
char = chr(((ord(char) - 65) +n) % 26 + 65)
elif 97 <= ord(char) < (97+26):
@gvx
gvx / RNDABC.TIbasic
Created November 16, 2008 08:44
A simple number guessing game.
PROGRAM:RNDABC
:Input D:randInt
(1,D)→A:randInt(
1,D)→B:randInt(1
,D)→C:Disp "AB",
AB,"AC",AC,"BC",
BC:Pause :Disp "
{A,B,C}",{A,B,C