Skip to content

Instantly share code, notes, and snippets.

@robo-corg
robo-corg / PageSearchBookmarklet.js
Created April 14, 2010 22:03
Bookmarklet for in page search
(function () {
var result=0;
var text = prompt("Find",'');
function find (node) {
if (node.nodeType == 1) {
var children = node.childNodes;
for (var i=0;i<children.length;i++) {
var child = children[i];
var res = find(child);
#!/usr/bin/env python
import sys
import urllib
input = open(sys.argv[1]).read()
print 'javascript:' + urllib.quote(input)
@robo-corg
robo-corg / Trap corridor
Created May 21, 2010 22:54
My trap corridor from my last Dwarf Fortress game
D = Draw bridge
C = Cage trap
W = Weapon trap
S = Stone fall trap
B = Normal retracting bridge
<- Entrance
|DDD| <- draw bridge that acts like a portcullis
|CCC|
def get_ifcs(links,rec=2):
return ifilter(lambda x: x!=None,chain(*[chain([link.ifc1,link.ifc2],get_ifcs(link.ordered_provider_links,rec-1)) for link in links]) if rec > 0 else [])
@robo-corg
robo-corg / badgerfish.py
Created October 15, 2010 17:36
Python badgerfish xml to json converter
import simplejson as json
from lxml import etree
def is_node_badger_array(node):
if len(node) <= 1:
return False
for (a,b) in zip(node,node[1:]):
if a.tag != b.tag:
return False
@robo-corg
robo-corg / Fixed google selenium rc example
Created November 3, 2010 20:17
Fixed python based selenium rc example that accounts for the new ajaxy nature of the google search page.
"""
Copyright 2006 ThoughtWorks, Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
@robo-corg
robo-corg / fixture_models.py
Created July 29, 2011 00:24
Detects what models were used in a django fixture
#!/usr/bin/env python
import json
import sys
# useful when used with backticks like: python manage.py dumpdata --indent=4 `fixture_models your_fixture.json`
data = None
with open(sys.argv[1]) as json_file:
data = json.load(json_file)
@robo-corg
robo-corg / ps1
Created May 23, 2012 23:31 — forked from bensonk/ps1.sh
Python, mercurial, and git friendly prompt script for bash.
#!/bin/bash
# Put this in ~/bin/ps1, and make it executable
# Then add the following line to your .bashrc or .bash_profile:
# PROMPT_COMMAND="source $HOME/bin/ps1"
HG_BRANCH=`hg branch 2>&1`
if [[ $? == 0 ]]
then
VCS_PROMPT="\[\033[00;33m\](\[\033[00;37m\]$HG_BRANCH\[\033[00;33m\]) \[\033[01;34m\]"
else
@robo-corg
robo-corg / traceback_collector.py
Created October 12, 2012 23:00
Traceback parser that opens the last file mentioned in the traceback.
import sys
import re
import subprocess
from functools import partial
class TracebackParser(object):
traceback_line_re = re.compile(r'\s+File\s+\"([^"]*)\"')
def __init__(self, on_traceback=None):
self.in_traceback = False
@robo-corg
robo-corg / embed_kernel_noloop.py
Created August 15, 2013 01:47
Returns a function that can used to manually pump IPython events to the embedded kernel instead of starting a blocking event-loop.
from IPython.kernel.zmq.kernelapp import IPKernelApp
from IPython.utils.frame import extract_module_locals
import sys
# Code lifted from IPython/kernel/zmq/embed.py
def embed_kernel_noloop(module=None, local_ns=None, **kwargs):
"""Embed and start an IPython kernel in a given scope
returning function that can be used to pump a single event
Parameters