Skip to content

Instantly share code, notes, and snippets.

View all.pytb
$ nosetests test_stuff.py
E.E
======================================================================
ERROR: test_assert_true (test_stuff.TestFail)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/vagrant/test_stuff.py", line 17, in test_assert_true
raise Exception
Exception
View foo.js
function FooObj(){
this.location = "http://www.google.com"
this.setLocation= function (location){
this.location = location;
}
}
var foo = new FooObj();
foo.setLocation("http://www.google.com/");
View foo.pytb
Python 2.7.3 (default, Feb 27 2014, 19:58:35)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> class PatchArg(object):
... def __init__(self, target, attribute, new):
... self.target = target,
... self.attribute = attribute,
... self.new = new
...
>>> PatchArg("foo", "bar", "blat")
View autocorrelation.py
import matplotlib.pyplot as plt
import numpy as np
input = open("stage2-input.bin", "rb").read()
bin = map(int, list(''.join(map(lambda s: s[2:], map(bin, map(ord, list(input)))))))
results = np.correlate(bin, bin, mode='full')
results = results[results.size/2:]
plt.plot(results[0:255])
View gist:80b634a5513b7237519d
OfflineIMAP 6.5.4
Licensed under the GNU GPL v2+ (v2 or any later version)
Remote repository 'personal-remote': type 'IMAP'
Host: localhost Port: 1143 SSL: False
Establishing connection to localhost:1143
Server welcome string: * OK [CAPABILITY IMAP4REV1 AUTH=LOGIN IDLE MOVE] IMAP4rev1 DavMail 4.4.0-2198 server ready
Server capabilities: ('IMAP4REV1', 'AUTH=LOGIN', 'IDLE', 'MOVE')
folderfilter= lambda folder: folder == 'INBOX'
View ferengi-plan.txt
# The blog post that started it all: https://neocities.org/blog/the-fcc-is-now-rate-limited
#
# Current known FCC address ranges:
# https://news.ycombinator.com/item?id=7716915
#
# Confirm/locate FCC IP ranges with this: http://whois.arin.net/rest/net/NET-165-135-0-0-1/pft
#
# In your nginx.conf:
location / {
View foo.py
from functools import wraps
class MyDecorator(object):
"""
would normally be my_decorator because it's a function, and functions use underscore delimited lower-case.
Used CamelCase to demo that it's really a class.
"""
def __init__(multiplier):
self.multiplier = multiplier
View gist:941fcced20c53ba063bd
Delivered-To: tagrain@gmail.com
Received: by 10.182.2.162 with SMTP id 2csp295902obv;
Fri, 4 Jul 2014 09:16:25 -0700 (PDT)
X-Received: by 10.140.87.99 with SMTP id q90mr19172514qgd.43.1404490584775;
Fri, 04 Jul 2014 09:16:24 -0700 (PDT)
Return-Path: <apache@blockchain.info>
Received: from mail.blockchain.info ([69.197.35.141])
by mx.google.com with ESMTP id p66si34755143yhd.99.2014.07.04.09.16.24
for <tagrain@gmail.com>;
View datetime.py
>>> from django.conf import settings
>>> from django.template import Context, Template
>>> settings.DATETIME_FORMAT
'D j m Y H:i (e)'
>>> Template('{{deadline|date:"DATETIME_FORMAT"}}').render(Context({"deadline": datetime.datetime.now}))
u'July 24, 2014, 11:45 a.m.'
View defaultclass.py
from collections import defaultdict as DefaultDict
class DefaultClass(object):
def __init__(self, *args, **kwargs):
self.__dict__ = DefaultDict(*args, **kwargs)