Skip to content

Instantly share code, notes, and snippets.

View adamcheasley's full-sized avatar
🤓
Hacking

Adam Cheasley adamcheasley

🤓
Hacking
View GitHub Profile
import docx
from docx.shared import Inches
doc = docx.Document()
table = doc.add_table(rows=2, cols=2)
table.style = 'TableGrid'
table.autofit = True
table.cell(0, 0).text = 'Time Zone'
import requests
def sum_of_proper_divisors(n):
divisor_sum = 1
for x in range(2, int((n / 2) + 1)):
if n % x == 0:
divisor_sum += x
return divisor_sum
@adamcheasley
adamcheasley / pre-commit
Created June 23, 2017 10:34 — forked from chronossc/pre-commit
Basic pre-commit hook for avoid commit code with pdb/ipdb
#!/bin/bash
# based on http://www.snip2code.com/Snippet/165926/Check-for-ipdb-breakpoints-git-hook
pdb_check=$(git grep -E -n '[ ;]i?pdb')
if [ ${#pdb_check} -gt 0 ]
then
echo "COMMIT REJECTED: commit contains code with break points. Please remove before commiting."
echo $pdb_check
exit 1
fi

Keybase proof

I hereby claim:

  • I am adamcheasley on github.
  • I am adamfc (https://keybase.io/adamfc) on keybase.
  • I have a public key ASBrc7vcoUTX2Jg-7FtVdk20XyXud6cfB6gbqXKUfDLatwo

To claim this, I am signing this object:

@adamcheasley
adamcheasley / helloevolve.py
Last active February 10, 2017 16:29
helloevolve.py - a simple genetic algorithm in Python
"""
helloevolve.py implements a genetic algorithm that starts with a base
population of randomly generated strings, iterates over a certain number of
generations while implementing 'natural selection', and prints out the most fit
string.
The parameters of the simulation can be changed by modifying one of the many
global variables. To change the "most fit" string, modify OPTIMAL. POP_SIZE
controls the size of each generation, and GENERATIONS is the amount of
generations that the simulation will loop through before returning the fittest
@adamcheasley
adamcheasley / git-tag.sh
Created August 9, 2016 11:41
simple script to get the current version of your code
#! /bin/bash
DESCRIBE=`git describe --tags`
MAJOR=`echo $DESCRIBE | awk '{split($0,a,"."); print a[1]}'`
MINOR=`echo $DESCRIBE | awk '{split($0,a,"."); print a[2]}'`
BUG=`echo $DESCRIBE | awk '{split($0,a,"."); print a[3]}'`
echo $MAJOR
echo $MINOR
echo $BUG
# quick and dirty skin script to audit a site's content
# stucture is {portal_type: {state: count}}
brains = context.portal_catalog.searchResults()
types = {}
for brain in brains:
ctype = brain['portal_type']
state = brain['review_state']
state_counts = types.setdefault(ctype, {})
count = state_counts.setdefault(state, 0)
def uniquify_ordered(seq, idfun=None):
# Removes duplicates from a list and preserves the order of items
# Taken from http://www.peterbe.com/plog/uniqifiers-benchmark
if idfun is None:
def idfun(x):
return x
seen = {}
result = []
for item in seq:
marker = idfun(item)
@adamcheasley
adamcheasley / gist:7602227
Created November 22, 2013 15:59
relation field in dexterity
from z3c.relationfield.schema import RelationChoice, RelationList
class IRDFFramework(form.Schema):
"""RDF descriptors"""
rdf_framework = RelationList(
title=_(u"RDF Framework"),
default=[],
value_type=RelationChoice(
source=ObjPathSourceBinder(
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"
xmlns:tal="http://xml.zope.org/namespaces/tal"
xmlns:metal="http://xml.zope.org/namespaces/metal"
xmlns:i18n="http://xml.zope.org/namespaces/i18n"
lang="en"
metal:use-macro="context/main_template/macros/master"
i18n:domain="plone">
<body>
<metal:main fill-slot="content-core">