Skip to content

Instantly share code, notes, and snippets.

View twexler's full-sized avatar
💁‍♂️
Breakin' stuff.

Ted Wexler twexler

💁‍♂️
Breakin' stuff.
View GitHub Profile
@twexler
twexler / gist:981377
Created May 19, 2011 18:13
Favorite piece of code
def quote_argument(argument):
failure = ('\\', '"', '$', '`', ';')
for fail in failure:
if(argument.find(fail) != -1):
os._exit(255)
return argument
#!/usr/bin/python
from __future__ import with_statement
import os,stat, pickle
class PyCache:
file = "/tmp/pycache.tmp"
def __init__(self): pass
def retrieve(self):
try:
st = os.stat(self.file)
curtime = time.time()
@twexler
twexler / gist:1821335
Created February 13, 2012 23:09
All the things!
def allthethings(a, b=None):
if b == None: b = "things"
print "%s all the %s!" % (a,b)
-(id)initWithNameAndURLs:(NSString*)name xmlURL:(NSURL*)xURL ackURL:(NSURL*)aURL {
if ((self = [super init]) != NULL){
displayName = [name retain];
xmlURL = [xURL retain];
ackURL = [aURL retain];
return self;
}
return nil;
}
@twexler
twexler / gist:4157060
Created November 27, 2012 21:14
Generate a random number
>>> import random
>>> random.randint(1,100)
77
>>>
[18:47:57] twexler:~ $ python
Python 2.7.6 (default, May 17 2014, 00:21:47)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.29.2)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import timeit
>>> timeit.timeit('import re;s="perceptes is gay";r=".*gay$";rr = re.compile(r);rr.match(s)')
2.5647430419921875
>>> timeit.timeit('import re;s="perceptes is gay";r=".*gay$";re.match(r, s)')
2.603404998779297
>>>
@twexler
twexler / gist:a63462d2a414d83f7bc9
Last active August 29, 2015 14:03
get all names from running instances that have a tag
import boto
ec2 = boto.connect_ec2()
ec2_hosts = [ec2.get_all_tags(filters={'resource-id': i.id, 'key': 'Name'})[0].value for i in list(itertools.chain.from_iterable([res.instances for res in ec2.get_all_instances(filters={"tag-key": "server_env", "instance-state-code": 16})]))]ec2_hosts = [ec2.get_all_tags(filters={'resource-id': i.id, 'key': 'Name'})[0].value for i in list(itertools.chain.from_iterable([res.instances for res in ec2.get_all_instances(filters={"tag-key": "server_env", "instance-state-code": 16})]))]ec2_hosts = [ec2.get_all_tags(filters={'resource-id': i.id, 'key': 'Name'})[0].value for i in list(itertools.chain.from_iterable([res.instances for res in ec2.get_all_instances(filters={"tag-key": "server_env", "instance-state-code": 16})]))]
#!/usr/bin/env python
import boto
import sys
#standard nagios exit codes
EXIT_OK = 0
EXIT_WARN = 1
EXIT_CRIT = 2
EXIT_UNKN = 3
FROM litaio/ruby
MAINTAINER "Ted Wexler <ted@stuckinacan.com>"
RUN apt-get update
RUN apt-get install -y redis-server libssl-dev
RUN gem install lita
ADD conf/ /srv/lita-docker/
WORKDIR /srv/lita-docker
RUN bundle install
CMD service redis-server start && bundle exec lita start
@twexler
twexler / subnet_address_alloc.py
Created December 22, 2014 23:09
ec2 subnet address allocation script
import boto.ec2
import boto.vpc
def subnet_stats(subnet_id):
addresses = []
ints = ec2.get_all_network_interfaces(filters={'subnet-id': subnet_id})
for i in ints:
addresses.append(i.private_ip_address)
for addr in i.private_ip_addresses:
if addr.private_ip_address != i.private_ip_address: