Skip to content

Instantly share code, notes, and snippets.

View taavi's full-sized avatar

(Taavi) Elora Burns taavi

View GitHub Profile
@taavi
taavi / smallcaps.py
Created September 6, 2022 17:55
Smallcaps converter, for #yelling
#!/usr/bin/env python3
import sys
to_smallcaps = {
"a": "ᴀ",
"b": "ʙ",
"c": "ᴄ",
"d": "ᴅ",
"e": "ᴇ",
"f": "ꜰ",
from collections import deque
def fizzbuzz(n):
return "f f bf fb f i i ui iu i z z zz zz z z z zz zz z b u z z "[n % 15 :: 15].strip() or n
if __name__ == "__main__":
deque((print(fizzbuzz(n)) for n in range(100)), maxlen=0)
@taavi
taavi / listener.py
Created October 9, 2015 14:33
Statsd listener for debugging stats locally
# From https://wiki.python.org/moin/UdpCommunication modified for Statsd + debugging usage
import datetime
import socket
UDP_IP = "127.0.0.1"
UDP_PORT = 8125
sock = socket.socket(
socket.AF_INET, # Internet
socket.SOCK_DGRAM) # UDP
@taavi
taavi / gist:ee89b94f8602e25296d3
Created January 20, 2015 15:13
Scoping of "return" in Scala
scala> // "return" binds to the nearest method, not function literals.
scala> def myfun() {
| val foo = List(1, 2, 3);
| val bar = foo map { x =>
| println(x)
| if (x == 2) return
| }
| println("Dead code")
| }
@taavi
taavi / gist:9255557
Created February 27, 2014 18:10
Strategies, staticmethods, modules, OH MY
# http://en.wikipedia.org/wiki/Strategy_pattern
# class_strategy.py:
# class IntegerStrategy(object):
# @staticmethod
# def add(a, b):
# ...
# class FloatStrategy(object):
# @staticmethod
# def add(a, b):
@taavi
taavi / runwhen.py
Created October 17, 2013 20:30
Watches your source tree for changes and runs a command when it does. Looks at filename, file size, and file mtime to determine what constitutes a "change". Saving a file with no other changes will cause it to re-run the command (I consider this a feature).
#!/usr/bin/env python
import os
import sys
from time import sleep
usable_files = (
'.py',
'.php',
'.yaml',
@taavi
taavi / cartesian_subquery.py
Created June 5, 2013 14:45
Cartesian-select performance in SQLAlchemy 0.7.9 with 2-layers of loads.
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import relationship, sessionmaker
import sqlalchemy as sa
# >>> sa.__version__
# '0.7.9'
engine = sa.create_engine('sqlite:///cartesian_subquery.db', echo=True)
Base = declarative_base()
@taavi
taavi / gist:5189792
Last active December 15, 2015 02:49
Adds instrumentation to pypy-stm's transaction.py to count and report on the number of transactions actually run.
diff -r a73a349ee7ec lib_pypy/pypy_test/test_transaction.py
--- a/lib_pypy/pypy_test/test_transaction.py Wed Mar 06 23:46:03 2013 +0100
+++ b/lib_pypy/pypy_test/test_transaction.py Mon Mar 18 15:55:30 2013 -0400
@@ -76,6 +76,27 @@
assert num_foos == 1, lsts
+def test_number_of_transactions_reported():
+ before = transaction.number_of_transactions_in_last_run()
+ transaction.run()
from cStringIO import StringIO
log_file = StringIO(
'posix_timestamp,elapsed,sys,user,queries,query_time,rows,'
'accountid,userid,contactid,level,silo,method\n'
'1343103150,0.062353,0,4,6,0.01690,3,'
'12345,1,-1,3,invoice_InvoiceResource,search\n'
)
import pandas as pd
from datetime import datetime
@taavi
taavi / gist:4953922
Created February 14, 2013 16:21
stm-thread-2 failure @3b4ede83d81c
$ hg parent
changeset: 61237:3b4ede83d81c
branch: stm-thread-2
tag: tip
user: Armin Rigo <arigo@tunes.org>
date: Thu Feb 14 14:49:25 2013 +0000
summary: Unclear why it occurs here and not on "default", but we need to prevent multiple #includes of this file
[translation:ERROR] Error: