Aligning UI input

http://troygilbert.com/2006/10/the-movement-and-attack-mechanics-of-the-legen...

very interesting stuff:


While Link can move a single pixel at a time, in any direction, the
longer he continously moves in any direction the more he gravitates
toward aligning himself with the underlying grid of the screen. The
tile grid for LoZ is 16 tiles wide by 14 tiles high (including 3 tiles
for the status display at the top of the screen). Each tile is 16×16
pixels. Link operates on a half-tile grid, though (32×28 tiles, 8×8
pixels each). As Link moves, if he’s not currently aligned with the
half-tile grid, he is adjusted, one pixel at a time, toward the
closest correction. As a result, if Link is 4 pixels off alignment
he’ll line back up with the grid after moving 4 pixels.
Posted
 

tornado is win

Seriously awesome benchmarks at http://nichol.as/asynchronous-servers-in-python

tl;dr, author likes Gevent the most (which uses a Stackless style,
mini-thread approach), and it outperforms everything but tornado.

Posted
 

stress testing the japherchunk

* Checking minimum space in /tmp... [ OK ]  * Configuring network interfaces... [ OK ]  * Starting system log daemon... [ OK ]  * Starting kernel log daemon... [ OK ]  * Starting OpenBSD Secure Shell server sshd [ OK ]  * Running local boot scripts (/etc/rc.local) [ OK ]  Ubuntu 8.04 japherchunk hvc0  japherchunk login: Out of memory: kill process 1415 (klogd) score 178 or a child Killed process 1415 (klogd) Out of memory: kill process 1392 (syslogd) score 153 or a child Killed process 1392 (syslogd) Out of memory: kill process 19233 (getty) score 25 or a child Killed process 19233 (getty) Out of memory: kill process 1354 (getty) score 8 or a child Killed process 1354 (getty) Out of memory: kill process 1459 (getty) score 8 or a child Killed process 1459 (getty) Kernel panic - not syncing: Out of memory and no killable processes...

the browser based terminal did it's best! I'm not quite sure why
nothing can figure out to kill the process that is using all the
memory. At least the reboot button works. :)

Posted
 

SQLITEBOT LIVES

courtesy of @charleshooper, the genius behind subversity.net

#!/usr/bin/env pythonimport tornado.httpserverimport tornado.ioloopimport tornado.webimport tornado.authfrom sqlite3 import connectimport settingsdef list_databases():    """List all databases"""    from os import listdir    return listdir(settings.data_path)def list_tables(database):    """List all tables"""    from os import path    # TODO: Sanitize 'database' var for directory traversal    conn = connect(path.join(settings.data_path,database))    cursor = conn.cursor()    cursor.execute("""SELECT name FROM sqlite_master WHERE type='table'        ORDER BY name""")    tables = [table for table in cursor]    cursor.close()    conn.close()    return tablesdef dump_data(database,table):    """Dump all records in a table"""    from os import path    conn = connect(path.join(settings.data_path,database))    cursor = conn.cursor()    # TODO: santize 'table' for SQL injection    cursor.execute("SELECT * FROM `%s`" % table)    data = [row for row in cursor]    cursor.close()    conn.close()    return dataclass MainHandler(tornado.web.RequestHandler):    """Main Handler... list all databases"""    def get(self):        self.write(repr(list_databases()))class ListTableHandler(tornado.web.RequestHandler):    """List tables in specified database"""    def get(self,database):        self.write(repr(list_tables(database)))class DataHandler(tornado.web.RequestHandler):    """Dump all records from a table"""    def get(self,database,table):        self.write(repr(dump_data(database,table)))application = tornado.web.Application([    (r"/", MainHandler),    (r"/([\w]+)/", ListTableHandler),    (r"/([\w]+)/([\w]+)/", DataHandler),],    cookie_secret=settings.cookie_secret,)if __name__ == "__main__":    http_server = tornado.httpserver.HTTPServer(application)    http_server.listen(settings.port)    tornado.ioloop.IOLoop.instance().start()

Also see his codepad posting

Posted
 

sound fx generator

this is so dang cool, an oldschool soundfx generator in flash:

http://www.superflashbros.net/as3sfxr/?gaming

Posted
 

gremlins in me code?!

weird weird bug with turbogears. My main controller has two methods, index() and vote() . Recently we added a sort of homebrew session thing that works by passing POST parameters around instead of cookies ( this is all going through facebook, so there are hoops). the gist of it being, first we get a userid from facebook, we salt and hash it and use those values to make sure people are POSTing at us from fb, and also to know if they are a new user or not.

Yes, this is sort of vulnerable to man in the middle attacks; that's not the point, and the dang app doesn't properly work yet.


so, I slap two decorators on my methods, fire up the server, and hit http://localhost:8080/ . it calls the vote() method instead of the index() method..

if I comment out the vote() method, it calls the index() method.

if i comment out my salter/chkhash decorators, it calls the right methods

if i comment out the @chkhash decorator on the vote() method, it calls the right methods.

if i decorate the vote() method with @nada, it works:

def nada(meth):     def donothing(self, **kw):         return meth(self,**kw)     return donothing


wtf?

miscellaneous oddities I notice at this point:

i throw a pdb.set_trace() in the first line of chkhash(), it gets called twice every time i hit http://localhost:8080/

my abort(500, msg) displays a traceback sort of page, unlike the abort(500,msg) from other code in this module.


so I change @chkhash to be named @choookhash, no dice ( maybe chkash is a tg keyword?)

I change def nada(meth): -> def nada(meth, **kw): , it still works (something with the def taking **kw?!)

i comment out nada, change def choookhash to def nada, it fails.

big wtf.

here is the chkhash function at this point; see if you can spot my n00b error.

def chkhash( meth, **kw):    #import pdb;pdb.set_trace()     if not 'wm_user' in kw or not 'wm_hash' in kw:         msg = 'Missing required user and hash params'         log.error( '%s params: %s' % (msg, request.params))         abort(500, msg)     if kw['wm_hash'] != mkhash( kw['wm_user']):         return '0'     def valid_meth(self, **kw):         return meth(self, kw['wm_user'], wm_hash=wm_hash, **kw)     return valid_meth

headers and path info .. i note that we're doing some sessions or something in the cookies? probably a default setting somewhere in turbogears.

(Pdb) request.path
'/'
(Pdb) request.path_info
'/'
(Pdb) request.headers
{'Content-Length': '0', 'Accept-Language': 'en-us,en;q=0.5',
'Accept-Encoding': 'gzip,deflate', 'Keep-Alive': '300', 'Connection':
'keep-alive', 'Accept':
'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'User-Agent': 'Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.3)
Gecko/20091020 Ubuntu/9.10 (karmic) Firefox/3.0.3', 'Accept-Charset':
'ISO-8859-1,utf-8;q=0.7,*;q=0.7', 'Host': 'localhost:8080', 'Cookie':
'user=ImphcGhlcndvY2t5Ig==|1260243809|3b8330977fe406c894502c87c5a6a7381c96193f;
_xsrf=98f0de607c634cae8f26dbeb0f353cda;
hansel=49c22a928dedfc864feeae4bd36ae1acbc6d7481bb5c483b16e698d1abfcb7b838e2e6a4',
'Content-Type': ''}


so.. i start adding lines of chkhash one at a time to see what's throwing it off, and it's the fucking abort(500,msg) !! because this works:

if not 'wm_user' in kw or not 'wm_hash' in kw:         msg = 'Missing required user and hash params'         log.error( '%s params: %s' % (msg, request.params))         #abort(500, msg)        kw['wm_user'] = 'me'         kw['wm_hash'] = mkhash( kw['wm_user'])


what the fuuuuuck, turbogears?! why does that line make you call the wrong method on my controller ?!

ah.. oh . wait. decorators are always supposed to return functions, aren't they? I bet abort is returning.. something else. fuck, duh, that would break when we are trying to use it properly, might as well fix that up.

def chkhash( meth, **kw):     def fail(self, **kw):         return '0'     if not 'wm_user' in kw or not 'wm_hash' in kw:         msg = 'Missing required user and hash params'         log.error( '%s params: %s' % (msg, request.params))         return fail     if kw['wm_hash'] != mkhash( kw['wm_user']):         return fail     def valid_meth(self, **kw):        return meth(self, kw['wm_user'], wm_hash=wm_hash, **kw)    return valid_meth

oh.  and now turbogears calls the right controller method..  ohkaaay.

Moral of the story: sometimes bugs make shit fail in weird ways.

 

Posted
 

Oh users, you crack me up

Uninstall report:

542749 you gave me a awful headache.I'm 73 years old, legally blind,I
wear two hearing aids, that don't wotk. You teased me about giving
$50k to cure my credit card bills. My life is ruined because you
killed my dreams.I hope you don't hurt anymore people like you hurt
me.

whaa?

 

Posted
 

Mobius Bagel Chains ?!

http://www.georgehart.com/bagel/bagel.html just blew my mind.. can't
wait to get my hands on some bagels.
Posted