Skip to content

Instantly share code, notes, and snippets.

@joshmarshall
joshmarshall / tornado_cassandra.py
Last active August 3, 2018 07:34
Tornado wrapper for Cassandra driver futures
from cassandra.cluster import Cluster, OperationTimedOut
from cassandra.decoder import SyntaxException
from tornado.concurrent import Future
from tornado.testing import AsyncTestCase, gen_test
class TornadoCassandra(object):
def __init__(self, session, ioloop):
@joshmarshall
joshmarshall / mongo_fast.sh
Created February 22, 2014 02:54
Run Mongo "In Memory" for Faster Tests
#!/bin/sh
# if you run this for anything other than local tests you are making poor
# choices. also, make sure you use safe=True / wc=1 in your tests, or you'll
# get consistency issues
mongod --nojournal --noprealloc --smallfiles --dbpath /Volumes/RAM\ Disk/
@joshmarshall
joshmarshall / puppet-install.sh
Created March 26, 2012 17:00 — forked from oesmith/puppet-install.sh
Install Puppet 2.6.2 from squeeze-backports on Ubuntu 10.04 LTS
cat > /etc/apt/preferences.d/backports <<EOF
Package: puppet puppet-common puppetmaster facter
Pin: release a=lenny-backports
Pin-Priority: 900
EOF
cat > /etc/apt/sources.list.d/backports.list <<EOF
deb http://backports.debian.org/squeeze-backports squeeze-backports main contrib non-free
EOF
@joshmarshall
joshmarshall / screenshare.sh
Created March 26, 2012 02:47
Streaming an Ubuntu Screen / Audio
#!/bin/sh
PORT="5544"
FRAMERATE="20"
VIDEO_SIZE="1280x720"
VIDEO_BITRATE="2000k"
AUDIO_BITRATE="512k"
AUDIO_FORMAT="mp2"
ffmpeg -f alsa -ac 2 -i pulse -acodec "$AUDIO_FORMAT" -ab "$AUDIO_BITRATE" \
@joshmarshall
joshmarshall / mogo_with_statement_example.py
Created October 14, 2011 13:37
Multiple Databases / Connections using Mogo With Statement
import mogo
DBNAME1 = "__testing__"
DBNAME2 = "__testing2__"
# Basic model
class Person(mogo.Model):
name = mogo.Field(unicode)
# Automatically opens and closes DB connection (or should)
@joshmarshall
joshmarshall / euler18.py
Created September 8, 2011 03:44 — forked from ramhiser/gist:1202533
Maximum Binary Tree Sum - Project Euler #18
from numpy import array
raw_data = """75
95 64
17 47 82
18 35 87 10
20 04 82 47 65
19 01 23 75 03 34
88 02 77 73 07 63 67
99 65 04 28 06 16 70 92
@joshmarshall
joshmarshall / ichooseyou.py
Created July 29, 2011 02:13
Twitter Winner Chooser
""" This proves that there was no money under the table. """
import random
import sys
from collections import Counter
def main():
""" Pick one of the sys args """
assert len(sys.argv) > 1
names = sys.argv[1:]
@joshmarshall
joshmarshall / gist:1033401
Created June 18, 2011 18:59
A session using mouseporter.py
user@localbox:~$ sudo apt-get install x2x
# On the remote machine...
user@remotebox:~$ sudo apt-get install x2x openssh-server
# Download the code from https://gist.github.com/1033384
# and save it to ~/bin on the local machine
user@localbox:~$ python bin/mouseporter.py 192.168.1.10
Session started... (type Ctrl-C to quit)
# ... and scroll to your right! :)
@joshmarshall
joshmarshall / mouseporter.py
Created June 18, 2011 18:37
A script for starting an x2x+SSH session
#!/usr/bin/env python
"""
AUTHOR: Josh Marshall
ACKNOWLEDGMENTS: Corey(?) http://www.ctrlv.ca/2010/04/163/
REQUIREMENTS: Python 2.6+, x2x, openssh-server
This is just a simple script to start an x2x session over SSH
on a remote machine. It takes a few parameters (like what side of
the screen do you want to use to "cross over" to the other machine,
what SSH port / identify file to use, etc.
@joshmarshall
joshmarshall / tornado_xmlrpc_early_test.py
Created May 1, 2011 18:57
Tornado XML-RPC Early Test Script
import tornado.httpserver
import tornado.ioloop
import tornado.web
def private(func):
# Decorator to make a method, well, private.
class PrivateMethod(object):
def __init__(self):
self.private = True
__call__ = func