Skip to content

Instantly share code, notes, and snippets.

View johnpaulhayes's full-sized avatar
💭
Always be coding

John Paul Hayes johnpaulhayes

💭
Always be coding
View GitHub Profile
@johnpaulhayes
johnpaulhayes / wordsinwords.py
Created February 1, 2014 14:46
find a list of words in a word for each entry in a dictionary
word_list = []
with open ('word_list.txt', 'r') as words:
for word in words:
word_list.append(word.strip())
def contains(subword, word):
res = []
for s in subword:
@johnpaulhayes
johnpaulhayes / ubuntu_update_heartbleed.txt
Created April 10, 2014 09:18
Update Ubuntu OpenSSL in response to Heartbleed bug.
sudo apt-get update
sudo apt-get install -y libssl1.0.0 openssl
# Confirm Build Date is at least Aril 7th 2014
openssl version -a
# Restart all services listed by this command:
sudo lsof -n | grep ssl | grep DEL
@johnpaulhayes
johnpaulhayes / upload_file_to_s3.py
Created June 25, 2014 14:52
Upload a file to S3 bucket
"""
Requirements:
AWS Account
Valid Access key and secret
A valid bucket setup
"""
from boto.s3.connection import S3Connection
from boto.s3.key import Key
import sys
@johnpaulhayes
johnpaulhayes / ExchangeRates.py
Created February 19, 2015 17:57
Retrieve exchange rates from Central Bank of Ireland and load them into a dictionary
# -*- coding: utf-8 -*-
import urllib
import xlrd
class ExchangeRates():
"""
Class to fetch exchange rate information from the Central Bank of Ireland
Example:
@johnpaulhayes
johnpaulhayes / sum_value_in_dict.py
Last active August 29, 2015 14:19
Sum a value field in a dictionary
dicts_with_values = [{"value": 30}, {"value": 20}, {"value": 1}]
""" Horrible! """
result = reduce(lambda x, y: x + y, [i["value"] for i in dicts_with_values])
""" Nice, Pythonic """
result = sum([i["value"] for i in dicts_with_values])
@johnpaulhayes
johnpaulhayes / reverse_mailmerge.asp
Created May 8, 2015 11:39
Macro for splitting a mail-merge document into single files.
Sub Splitter()
Dim Mask As String
Dim Letters As Long
Dim Counter As Long
Dim DocName As String
Dim oDoc As Document
Dim oNewDoc As Document
Set oDoc = ActiveDocument
oDoc.Save
@johnpaulhayes
johnpaulhayes / thousandsSeparater.js
Created June 29, 2015 13:08
Javasript thousands seperator
function thousdansSeparater(nStr) {
nStr += '';
x = nStr.split('.');
x1 = x[0];
x2 = x.length > 1 ? '.' + x[1] : '';
var rgx = /(\d+)(\d{3})/;
while (rgx.test(x1)) {
x1 = x1.replace(rgx, '$1' + ',' + '$2');
}
@johnpaulhayes
johnpaulhayes / gist:6422556
Created September 3, 2013 11:17
Perform an action for each directory found in a given location
#! /bin/bash
# Description: For each directory in ~/Development, descend into it, pull the latest from git and come back out of it.
find ~/Development/. -type d -print0 -maxdepth 1 | while IFS= read -r -d '' dir
do
cd $dir
git pull
cd ../
done
@johnpaulhayes
johnpaulhayes / gist:6580864
Created September 16, 2013 13:44
Switch branches of a number of git repositories in a specific path
from git import Repo
from git import InvalidGitRepositoryError
import sys
import os
import getopt
settings = {
'repos_path': '/path/to/your/git/repos',
'cmd_options': 'b:r:',
'this_file_name': 'the_name_of_this_script.py'
@johnpaulhayes
johnpaulhayes / gist:6881375
Created October 8, 2013 08:22
pre-commit hook that checks for various python based 'crud' such as pdb, ipdb, print statements, console output. Taken from http://css.dzone.com/articles/why-your-need-git-pre-commit
#!/usr/bin/env python
import os
import re
import subprocess
import sys
modified = re.compile('^(?:M|A)(\s+)(?P<name>.*)')
CHECKS = [