Skip to content

Instantly share code, notes, and snippets.

[wraithan@wraithbeast ~]
$ python3
Python 3.2.2 (default, Sep 5 2011, 04:52:19)
[GCC 4.6.1 20110819 (prerelease)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> None < 3
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unorderable types: NoneType() < int()
>>>
Python 3.2.2 (default, Sep 5 2011, 04:52:19)
[GCC 4.6.1 20110819 (prerelease)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> if True:
... foo = 5
...
>>>> print(foo)
5
def visible(self, loc):
' determine which squares are visible to the given player '
if self.vision == None:
if not hasattr(self, 'vision_offsets_2'):
# precalculate squares around an ant to set as visible
self.vision_offsets_2 = []
mx = int(sqrt(self.viewradius2))
for d_row in range(-mx,mx+1):
for d_col in range(-mx,mx+1):
def visible(self, loc):
' determine which squares are visible to the given player '
if self.vision == None:
if not hasattr(self, 'vision_offsets_2'):
# precalculate squares around an ant to set as visible
self.vision_offsets_2 = []
mx = int(sqrt(self.viewradius2))
for d_row in range(-mx,mx+1):
for d_col in range(-mx,mx+1):
@wraithan
wraithan / test.py
Created December 11, 2011 11:41
deepcopy vs list comprension
from copy import deepcopy
from timeit import Timer
list_o_lists = [[1,2,3,4],[1,2,3,4],[1,2,3,4],[1,2,3,4]]
def deepcopy_f():
meh = deepcopy(list_o_lists)
def slice_f():
>>>> a = [[1]] * 10
>>>> a
[[1], [1], [1], [1], [1], [1], [1], [1], [1], [1]]
>>>> a[0][0] = 20
>>>> a
[[20], [20], [20], [20], [20], [20], [20], [20], [20], [20]]
>>>>
from datetime import datetime
from timeit import Timer
def verbose_f():
now = datetime.now()
new_dt = datetime(now.year, now.month, now.day, now.hour, now.minute, now.second, now.microsecond, now.tzinfo)
def terse_f():
now = datetime.now()
new_dt = datetime.combine(now.date(), now.time())
(9:28:07 PM) meredith mclain: heya!
(9:28:11 PM) me: ohai bot
(9:28:19 PM) meredith mclain: Im not a freaking bot
(9:28:36 PM) me: orly
(9:28:44 PM) meredith mclain: hey whats up? 23/F here. youu?
(9:28:44 PM) me: So what are you selling?
(9:28:52 PM) meredith mclain: hmm. have we chattted before?
(9:28:54 PM) me: bot
(9:29:02 PM) meredith mclain: Im not a freaking bot
(9:29:10 PM) me: bot
@wraithan
wraithan / base.html
Created January 23, 2012 00:17
Generic Template with Extra Context
<!doctype html>
<html>
<head>
<title>{{page_name}}</title>
</head>
<body>
<h1>{{page_name}}</h1>
{% block content %}
{% endblock content %}
</body>
var fs = require('fs');
var redis_lib = require('redis');
var pub = redis_lib.createClient();
module.exports = {
send_privmsg: function(to, message) {
return pub.publish('out', JSON.stringify({
version: 1,
type: 'privmsg',