Skip to content

Instantly share code, notes, and snippets.

View adamcheasley's full-sized avatar
🤓
Hacking

Adam Cheasley adamcheasley

🤓
Hacking
View GitHub Profile
@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
@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
# 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)