Skip to content

Instantly share code, notes, and snippets.

View benhosmer's full-sized avatar

Ben Hosmer benhosmer

View GitHub Profile
@benhosmer
benhosmer / time-files-modified.py
Created January 25, 2013 14:12
Find the oldest and newest file in a directory and sort them.
#!/usr/bin/env python
import os
path = 'data'
os.chdir(path)
files = sorted(os.listdir(os.getcwd()), key=os.path.getmtime)
oldest = files[0]
newest = files[-1]
@benhosmer
benhosmer / rps.py
Created April 28, 2012 19:40
Rock, Paper, Scissors - In Python!
# if not re.match("^[a-z]*$", input_str):
import random
import os
import re
os.system('cls' if os.name=='nt' else 'clear')
while (1 < 2):
print "\n"
print "Rock, Paper, Scissors - Shoot!"
@benhosmer
benhosmer / udp-port-scanning.txt
Created April 20, 2012 15:31
UDP Port Troubleshooting using netcat
Using the nc command you can scan a port or a range of ports to verify whether a UDP port is open and able to receive traffic.
This first command will scan all of the UDP ports from 1 to 65535 and add the results to a text file:
$ nc -vnzu server.ip.address.here 1-65535 > udp-scan-results.txt
This merely tells you that the UDP ports are open and receive traffic.
Perhaps a more revealing test would be to actually transfer a file using UDP.
@benhosmer
benhosmer / date-to-epoch.py
Created March 17, 2014 11:12
Python script to convert a date to epoch time.
hiredate= '1981-06-03'
pattern = '%Y-%m-%d'
epoch = int(time.mktime(time.strptime(hiredate, pattern)))
print epoch
360388800
@benhosmer
benhosmer / gist:5118626
Last active November 28, 2018 04:42
My Drupal 6/7 nginx site configuration file.
# Drupal 6 NGINX Configuration File
# Enable www.mysite.com or mysite.com to be served
server {
server_name www.mysite.com;
rewrite ^/(.*) $scheme://mysite.com/$1 permanent;
}
server {
server_name mysite.com;
access_log /var/log/nginx/mysite.com-access.log;
@benhosmer
benhosmer / app.py
Created October 22, 2012 11:00
bottle.py notes
from bottle import route, run, static_file, request, abort, redirect, view, template
import re
# Serve a static html with templates
# Create an index.tpl and save it in /views
'''
#Sample index.tpl
<html>
<head>
<link rel="stylesheet" type="text/css" href="/static/styles.css" />
@benhosmer
benhosmer / AWS-CloudFormation-Drupal-From-A-Makefile.template
Created April 24, 2012 16:41
An AWS CloudFormation Template to install Drush, Drush_Make, and Drupal from a Makefile
{
"Description" : "RadiantBlue Drupal 7 CloudFormation template from a make file V.0.0.1",
"Parameters" : {
"KeyName" : {
"Description" : "Name of an existing EC2 KeyPair to enable SSH access to the instances",
"Type" : "String",
@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 / yaml-read-parse.py
Created September 11, 2012 09:24
Parsing yaml into a python dictionary.
f = open('user.yaml')
dataMap = yaml.load(f)
f.close()
print ""
print "=-----------="
print "dataMap is a ", type(dataMap), dataMap
print "=-----------="
print "main items are", type(dataMap['main']), dataMap['main']
@benhosmer
benhosmer / pyelapheupcgen.py
Created February 12, 2015 00:16
Python using elaphe to generate UPC A Barcodes
#/usr/bin/env python
# Install elaphe first
# pip install elaphe
from elaphe.upc import UpcA
upc_a = UpcA()
# Just a simple dictionary of numbers. If I remember right, I had to use UPC A because they had the number of characters I needed