Skip to content

Instantly share code, notes, and snippets.

View awentzonline's full-sized avatar

Adam Wentz awentzonline

View GitHub Profile
def nn(name):
if len(name) < 3:
return name
return '%s%d%s' % (
name[0], len(name) - 2, name[-1]
)
class SpaceS(PolymorphicS):
def process_filter_geo_polygon(self, key, val, action):
return {
"geo_polygon": {
key: {
"points":[dict(lat=y, lon=x) for x, y in val]
}
}
}
from geventirc import message
class Pass(message.Command):
def __init__(self, password, prefix=None):
params = [password]
super(Pass, self).__init__(params, prefix=prefix)
botbits.handlers.SalutationMatcher:
nick: aholebot
salutations:
- "get lost {}"
- "you are unloved, {}"
- "{} has no mother"
- "nice chat message, {}"
- "i hate you {}"
def p(n):
if n == 0:
return '1'
return str(2 ** n) + p(n - 1)
from fabric.api import *
from fabric.operations import run
env.user = 'remoteuser'
env.webroot = '/usr/local/blah/htdocs'
env['disable_known_hosts'] = True
def production_provision():
@awentzonline
awentzonline / gist:10415560
Created April 10, 2014 19:38
ROBOT READS YOU A WEB FRAGMENT
import subprocess
import sys
import lxml.html
import requests
if __name__ == '__main__':
url, selector = sys.argv[-2:]
response = requests.get(url)
@awentzonline
awentzonline / JSON.XML
Created May 6, 2014 18:43
Awesome new data interchange format prototype
<json anAttr="<json anotherAttr=\"<json value=\"Foobar\"/>\"/>"/>
@awentzonline
awentzonline / gist:a7d9a2a6adc0f49257bf
Created May 15, 2014 20:21
robotalk.py: for spoken communication after the singularity
import subprocess
import sys
if __name__ == '__main__':
"""
Example: robotalk.py "Please do not violate me, robot."
"""
text = sys.argv[-1]
s = ' '.join([' '.join(bin(ord(x))[2:]) for x in text])
def from_native(self, data, files):
identity = self.get_identity(data)
if identity:
obj = self.opts.model.objects.get(id=identity)
dirty = False
for field_name, field_serializer in self.fields.items():
val = field_serializer.from_native(data[field_name])
if getattr(obj, field_name) != val:
setattr(obj, field_name, val)
dirty = True