Skip to content

Instantly share code, notes, and snippets.

@robballou
robballou / instance_name.py
Created October 17, 2011 16:55
Get the EC2 instance name
"""
Get the EC2 instance name (tag "Name") for the instance
Usage:
python instance_name.py [instance id]
On an EC2 instance, you can run:
python instance_name.py `ec2metadata --instance-id`
@robballou
robballou / gist:1319600
Created October 27, 2011 13:55
Mac Shell Customization trials
# Place in your ~/.[bash_]profile file
#
# display "username:path $ " with path in green
#
# currently works well with multiple lines, but does sometimes get a bit wonky when
# paging through history with the arrow keys:
export PS1="\u:\[\e[32;1;32m\]\W\[\e[m\] \$ "
@robballou
robballou / gist:1358548
Created November 11, 2011 17:01
Get the instance DNS names for an AWS security group using boto
from boto.ec2.connection import EC2Connection
ec2 = EC2Connection()
reservations = ec2.get_all_instances(None, {'group-name': 'Your Group Name'})
dns_names = [instance[0].dns_name for instance in [reservation.instances for reservation in reservations]]
@robballou
robballou / svnup.py
Created November 23, 2011 14:30
'svn up' all the directories
"""
Update all directories in the svn directory
"""
import sys
import os
import subprocess
def svnup(directory):
items = os.listdir(directory)
for item in items:
@robballou
robballou / gist:1706299
Created January 30, 2012 19:55
Jenkins error
WARNING: Caught exception evaluating: it.isTagged(). Reason: java.lang.NullPointerException
java.lang.NullPointerException
at hudson.scm.SubversionTagAction.isTagged(SubversionTagAction.java:157)
at sun.reflect.GeneratedMethodAccessor73.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:616)
at org.apache.commons.jexl.util.introspection.UberspectImpl$VelMethodImpl.invoke(UberspectImpl.java:258)
at org.apache.commons.jexl.parser.ASTMethod.execute(ASTMethod.java:104)
at org.apache.commons.jexl.parser.ASTReference.execute(ASTReference.java:83)
at org.apache.commons.jexl.parser.ASTReference.value(ASTReference.java:57)
<?php
/*
I felt it was best to treat this a bit more completely by pulling in an open source library.
So, cheating a bit and using simplehtmldom since it's best if we account for
both href & target attributes (if a link has a target, we don't want to repeat it)
http://simplehtmldom.sourceforge.net/
A solution without using this library could use preg_match_all to parse out the href's but
<?php
$names = 'Jeff';
// if User() is a class, this will be an error since classes are not callable. If it
// is a class then it would be "new User();"
$user = User();
// $names is not iterable, so this will error out
foreach($names as $name)
{
<?php
/*
Based on rules from http://en.wikipedia.org/wiki/Roman_numerals
*/
function romanToInt($roman){
$int = 0;
$characters = str_split($roman);
$previous = null;
$values = array('I' => 1, 'V' => 5, 'X' => 10, 'L' => 50, 'C' => 100, 'D' => 500, 'M' => 1000);
foreach($characters as $character){
@robballou
robballou / gist:2589032
Created May 3, 2012 20:28
custom_content_pages example hook_menu() implementation
<?php
/**
* Implement hook_menu()
*/
function custom_content_pages_menu() {
$items['custom/%/about'] = array(
'page callback' => 'custom_content_pages_about',
'access arguments' => array('access content'),
);
@robballou
robballou / gist:2589066
Created May 3, 2012 20:36
custom_content_pages example page callback #1
<?php
function custom_content_pages_about() {
// load our content: since our path starts with the alias for this
// node, we can lookup the node source that way
$node_path = drupal_lookup_path('source', arg(0) .'/'. arg(1));
// now we can the actual node
$node = menu_get_object('node', 1, $node_path);
// set the title