Skip to content

Instantly share code, notes, and snippets.

View benhosmer's full-sized avatar

Ben Hosmer benhosmer

View GitHub Profile
@benhosmer
benhosmer / hello.py
Created October 19, 2012 12:23
Using bottle with Google App Engine
'''
place the bottle.py in the same directory as your hello.py
'''
from bottle import route, run
@route('/')
def index(name=['hello', 'World', 'from <a href="http://appfog.com">Appfog!</a>']):
return '<br>'.join(name)
@benhosmer
benhosmer / unban.sh
Created October 15, 2012 18:03
Unban an ip address that has been banned with fail2ban
# Put a real ip address no 12.34.56.78
sudo fail2ban-client get ssh actionunban 12.34.56.78
@benhosmer
benhosmer / makedivs-php-arrays.php
Created October 12, 2012 12:14
PHP Arrays with named key values.
<?php
function makedivarrays() {
$output = array();
$topdiv = '<div id="topdiv"><div class="myclass">Topdivtext</div></div>';
$bottomdiv = '<div id="bottomdiv"><div class="myclass">bottomdivtext</div></div>';
$output = array(
'topdiv' => $topdiv,
'bottomdiv' => $bottomdiv,
);
@benhosmer
benhosmer / ssh_config
Created October 9, 2012 09:16
Specify different SSH keys for a specific host
Host GitServer
Hostname=git.example.org
IdentityFile=~/.ssh/my_cool_key_rsa
@benhosmer
benhosmer / drupal-console-log.php
Created October 8, 2012 16:41
Drupal log javascript functions to the console.
<?php
drupal_add_js('jQuery(document).ready(function () { console.log("Hello!"); });', 'inline');
?>
@benhosmer
benhosmer / docopt_adder.py
Created October 8, 2012 11:30
A simple use of the docopt library in python.
"""Usage:
adder.py <value1> <value2>
"""
from docopt import docopt
arguments = docopt(__doc__, version='0.1.1rc')
def adder():
number1 = int(arguments['<value1>'])
@benhosmer
benhosmer / .vimrc
Last active October 11, 2015 00:48
My vimrc file
set number
set ruler
set background=dark
set tabstop=2
set shiftwidth=2
" set paste
set colorcolumn=80
syntax on
filetype plugin on
@benhosmer
benhosmer / salt-in-SLS.yaml
Created September 19, 2012 13:56
An example of using a salt module in an SLS file.
# This uses the grains module
# http://docs.saltstack.org/en/latest/ref/modules/all/salt.modules.grains.html#module-salt.modules.grains
# http://salt.readthedocs.org/en/latest/ref/states/all/salt.states.module.html#module-salt.states.module
salt:
module.run:
- name: grains.ls
@benhosmer
benhosmer / easygui-dialogs.py
Created September 12, 2012 15:07
Notes for using easygui for quick prototyping input boxes.
import easygui
import PIL
# A simple message box
easygui.msgbox("Ben is cool", "Warning")
# A box with choices
@benhosmer
benhosmer / unique-list-items.py
Created September 11, 2012 09:27
Get the unique items from a python list using set()
mylist = ['apples', 'bananas', 'oranges', 'strawberries', 'apples']
print "Not Unique List: ", mylist
print "Unique List Using set: ", list(set(mylist)