Skip to content

Instantly share code, notes, and snippets.

View siwells's full-sized avatar

Simon Wells siwells

View GitHub Profile
@siwells
siwells / wikify.sh
Created February 27, 2010 15:17
wikify a list of papers for embedding into a wiki
#!/bin/bash
usage()
{
echo "usage: `basename $0` inputfile"
}
IN=$1
ENDING=".pdf"
OPEN="[["
#include <stdio.h>
int main()
{
printf("Hello World\n");
return 0;
}
ifconfig eth0 | grep 'inet ' | awk '{print $2}' | sed 's/addr://'
@siwells
siwells / gist:1114395
Created July 29, 2011 18:19
Use a regex to remove the font tags & their attributes from a page to undo highlighting applied using those self-same font tags
/*
* Clear the highlighting to allow the user to toggle
* between the original page & the highlighted page.
*/
function clearHighlighting()
{
alert("clearing hightlighting...");
if (!document.body || typeof(document.body.innerHTML) == "undefined") {
if (warnOnFailure) {
@siwells
siwells / is-net-up.sh
Created August 1, 2011 11:09
A Bash script to check whether the network for a given VM is up and running. It will look for the VirtualBox reserved NAT IP (10.0.2.15). If found the VM is up & running, otherwise inform the user then sleep for 10 seconds before trying again.
#!/bin/bash
function checknet {
UP=$(VBoxManage guestproperty enumerate omero-vm | grep "10.0.2.15")
}
checknet
echo "UP :: " $UP
@siwells
siwells / whatos.sh
Created August 4, 2011 16:27
Determine the kernel that the host is running & output an appropriate message
#!/bin/bash
OS=`uname -s`
if [ "$OS" == "Darwin" ]; then
echo "Mac OS X with Darwin Kernel"
elif [ "$OS" == "Linux" ]; then
echo "GNU/Linux OS with Linux Kernel"
else
echo "Not Mac or Linux"
@siwells
siwells / cli_test.py
Created August 16, 2011 08:58
Example of using optparse to work with command line arguments to build a *nix style CLI tool
import optparse
def main():
p = optparse.OptionParser()
p.add_option('--person', '-p', default="world")
options, arguments = p.parse_args()
print 'Hello %s' % options.person
if __name__ == '__main__':
main()
@siwells
siwells / cmd_test.py
Created August 16, 2011 09:03
A simple example of using cmd to build a simple REPL within a python CLI tool.
import cmd
class CmdProcessor(cmd.Cmd):
"""A Simple Command Processor."""
def do_greeting(self, line):
print "Hello World!"
def do_EOF(self, line):
return True
@siwells
siwells / bracket_matching.py
Created August 17, 2011 10:30
Playing with a bracket matching function for use in a new code generation tool.
def Evaluate(str):
stack = []
pushChars, popChars = "<({[", ">)}]"
for c in str :
if c in pushChars :
stack.append(c)
elif c in popChars :
if not len(stack) :
return False
else :
@siwells
siwells / notifytest.py
Created September 25, 2011 00:05
Playing with pynotify on Ubuntu to display notifications
import pynotify
def notificate():
n = pynotify.Notification("Hello World", "Simon says HELLO", "notification-message-im")
n.set_urgency(pynotify.URGENCY_NORMAL)
n.set_timeout(200)
if not n.show():
print "Failed to display notification"
sys.exit(1)