Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
#
import json
import os
from random import choice, gauss, sample, randint
from datetime import datetime
import re
{
"metadata": {
"name": "",
"signature": "sha256:093e4d7561eebe0a00236a799d36efc6bdc0dd00e7517505b7ab14026324aef7"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
{
"cells": [
class SignedObjectMixin(object):
@property
def signed(self):
if hasattr(self, '__sig__'):
return sign(self)
raise NotImplemented('no __sig__ found')
class InitAllMixin(object):
def __init__(self, *args, **kwargs):
for base in (c for c in self.__class__.__bases__ if c is not InitAllMixin):
base_class.__init__(self, *args, **kwargs)
class BaseClassOne(object):
spam_message = "class_spam"
def __init__(self):
self.spam_message = "instance_spam"
@capttwinky
capttwinky / safe_iterator.py
Created August 28, 2014 20:22
None safe iterators
import collections
def strict_iterator(iterable):
if not isinstance(iterable, collections.Iterable):
raise StopIteration
else:
for i in iterable:
yield i
def safe_iterator(iterable):
@capttwinky
capttwinky / colornames.html
Last active August 29, 2015 14:03
colornames
<html>
<table>
<tr><th>environ</th><th>color</th></tr>
<tr><td>local</td><td bgcolor=Pink>Pink</td></tr>
<tr><td>beta</td><td bgcolor=MediumPurple>MediumPurple</td></tr>
<tr><td>dev</td><td bgcolor=LimeGreen>LimeGreen</td></tr>
<tr><td>prod</td><td bgcolor=Crimson>Crimson</td></tr>
<tr><td>review</td><td bgcolor=HotPink>HotPink</td></tr>
<tr><td>stage</td><td bgcolor=Orange>Orange</td></tr>
<tr><td>stress</td><td bgcolor=LightSeaGreen>LightSeaGreen</td></tr>
#!/usr/bin/env python
import qrcode
with open(__file__) as ofile:
mcnts = ofile.read()[:-1]
qrcode.make(mcnts).save('quine_qr.png')
print(mcnts)
## calling this url will return a QR code which encodes the str_in parameter:
url = 'chart.apis.google.com/chart?cht=qr&chs=300x300&chl={str_in}&chld=H|0'.format(str_in='')
## find a str_in such that the generated QR code, when scanned, returns the url which generated it
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
from contextlib import contextmanager
from functools import wraps
class dummy_statsd_connection(object):
def __init__(self, *args, **kwargs):
self.data = []
self.log_data(args, kwargs)
def log_data(self, *args, **kwargs):
self.data.append({'args':args, 'kwargs':kwargs})