Skip to content

Instantly share code, notes, and snippets.

View ralphbean's full-sized avatar

Ralph Bean ralphbean

  • Red Hat, Inc
  • Rochester, NY
View GitHub Profile
@ralphbean
ralphbean / simple_file_completer.py
Created November 12, 2012 18:28
Half-working filename tab-completer. Play with it--it mostly works, but you have to help it along more than you're used to at the command line.
#!/usr/bin/env python
import readline
import os
import re
import sys
# This will tab-complete from the working directory, starting from /, and going
# through the sub-directories, but it doesn't behave quite the way you expect.
# For instance, it chooses for you if there are two partial matches.
@ralphbean
ralphbean / statusnet-oauth.py
Created November 14, 2012 06:21
how to get your secret tokens for identi.ca
#!/usr/bin/python
"""
This script should be used once to initialize your desktop/command line
application with a oauth access key and access secret.
Your first step is to login, via the web, to your identi.ca account
and authorize your application. Click Edit next to your username
to edit your profile settings. Then click Connections on the left
side bar. Then, in the right sidebar, click
@ralphbean
ralphbean / example-index.html
Created November 19, 2012 02:58
Statatat Docs
<html>
<body>
<p>This is my blog about jurisprudence.</p>
<script type='text/javascript' src='http://statatat.ws/widget/ralphbean/embed.js?width=400&height=55&duration=1600&n=10&topic=73360ab012f73b09d6da94787737c058'></script>
<footer>Have a nice day.</footer>
</body>
</html>
@ralphbean
ralphbean / scapy-pub.py
Created November 30, 2012 19:08
Try connecting to a netcat instance with scapy on port 9001
#!/usr/bin/env python
# The above line indicates that this is a python script.
# Author: Ralph Bean <[email protected]>
# This line imports python objects from the scapy module
from scapy.all import sendp, TCP, IP
# Can we get scapy to talk with netcat?
# http://stackoverflow.com/questions/12062781/how-to-make-netcat-display-payload-of-packet
# Run "nc -l 9001"
@ralphbean
ralphbean / oblivious_publisher.py
Created December 10, 2012 17:49
A publisher that isn't aware of the subscriber to which it connects.
#!/usr/bin/env python
import zmq
context = zmq.Context()
publisher = zmq.Socket(zmq.PUB)
# Say I normally have a passive subscriber listening on 9876.
# In the event that that process crashes, and there is nothing listening at
# 9876, I would like to raise an exception/be notified. Can I check for that?
@ralphbean
ralphbean / gstreamer-test.sh
Created March 6, 2013 19:03
Trying to stream gource to the browser. Not quite done.
#!/bin/bash
# Livestream gource to the browser (almost).
# Author: Ralph Bean <[email protected]>
# I'm so sorry. Select the X id of the gource window
xid=$(xwininfo -root -tree | grep Gource | awk '{print $1}' | head -1 | xwininfo -id 0x260000f -children | grep xwininfo | awk '{print $4}')
# Use that as a gstreamer capture source
SRC="ximagesrc xid=$xid use-damage=false"
@patch("sys.argv", new_callable=lambda: ["pythong", "--snap"])
def test_that_snap_makes_directory(self, mock_argv):
# TODO, you may want to change the pwd temporarily to /tmp/ or something.
pythong.create_project()
assert(os.path.isdir(THAT_DIR_YOU_WANT))
class directory(object):
""" pushd/popd context manager.
Use like:
>>> with directory("/tmp/"):
... pass # do some stuff
"""
def __init__(self, newPath):
class directory(object):
""" pushd/popd context manager.
Use like:
>>> with directory("/tmp/"):
... pass # do some stuff
"""
def __init__(self, newPath):
@ralphbean
ralphbean / check_supybot_plugin.py
Created April 16, 2013 01:33
NRPE/nagios check to see if supybot has a certain plugin loaded.
""" check_supybot_plugin -- ensure that a plugin is loaded by supybot.
Run like:
check_supybot_plugin --target fedmsg
check_supybot_plugin --target koji --debug
"""
import argparse