Skip to content

Instantly share code, notes, and snippets.

@chadgh
chadgh / Curling.class.php
Created August 24, 2010 17:46
A solution to simplify the use of curl in php
<?php
/**
* @name Curling.class.php
*
* Purpose: encapsulates and simplifies curl functionality
*
* @author Chad G. Hansen
*/
class Curling
{
@chadgh
chadgh / runner.js
Created February 15, 2011 00:41
Bot for Botswana
var Runner = function() {};
Runner.prototype = new Bot("Runner");
Runner.prototype.setup = function() {
this.clicks = 0; // keep track of how many clicks
this.opponent = -1;
this.speed = 2;
this.safety = 7;
};
Runner.prototype.getAngle = function(point) {
dx = 0;
@chadgh
chadgh / timer.js
Created April 19, 2011 15:39
A timer utility class for javascript.
function Timer(el, callbackFunction) {
// init the timer
// el - element for time to be updated
// callbackFunction - string of function name to
// be called when the countdown is finished.
this.init = function(el, callbackFunction) {
this.seconds = 0;
this.minutes = 0;
this.counterCaller = null;
this.timer = el;
@chadgh
chadgh / gist:1027833
Created June 15, 2011 19:05
defines a function to move up X number of directories in bash
updir(){
if [ $# -gt 0 ];then
path=""
for (( i=1; i<=$1; i++ )); do
path=$path"../"
done
cd $path
else
cd ../
fi
@chadgh
chadgh / commandline.py
Created June 20, 2012 17:50
simple python module that provides a few useful setups for other command line python scripts. Requires plumbum
#!/usr/bin/python
import sys
import argparse
from plumbum import local, FG, BG
local = local
FG = FG
BG = BG
def getArgParser(program=__file__, desc=''):
@chadgh
chadgh / chadbot.js
Last active October 13, 2015 18:18
Bot for botswana
var Chad = function() {};
Chad.prototype = new Bot();
Chad.prototype.setup = function() {
this.timer = 0;
this.movements = ['strafe-right', 'strafe-left', 'forward', 'backward'];
this.formation = this.id % 4;
};
@chadgh
chadgh / squid.py
Last active December 22, 2015 00:49
The squid module provides a nice easy way to use threading effectively for I/O bound tasks that you want the results back to do something with.
import threading
def tentacle(f, daemon=False):
"""Decorator adopted from http://stackoverflow.com/a/14331755/18992 (thanks bj0)"""
import Queue
def wrapped_f(q, *args, **kwargs):
"""Call decorated function and puts the result in a queue."""
ret = f(*args, **kwargs)
@chadgh
chadgh / debugging_decorators.py
Last active February 15, 2022 04:32
python decorators for; debugging, threading
def timeit(function):
'''Decorator used for debugging. Prints the call and how long it took.'''
def timed(*args, **kwargs):
ts = time.time()
result = function(*args, **kwargs)
te = time.time()
print("{0} ({1}, {2}) {3:.2} sec"
.format(function.__name__, args, kwargs, te - ts))
​def make_power(power):
def pow(number):
return number ** power
return pow
cube = make_power(3)
print(cube(3)) # should print '27'
@chadgh
chadgh / README.md
Last active August 29, 2015 14:16
Trello to Django

What?!?!

Sometimes it is easier to design and talk about models in a more abstract easy to change way. After that design phase is finished, it is nice to have something to take your designs and give you boilerplate code. This does that for Django when models are specified in a specific style in Trello. An example board https://trello.com/b/iPHi7eQz/my-django-models.

Assumptions

  • py-trello==0.1.6 is installed
    • py-trello has a bug that is easily fixed, edit the env/lib/python2.X/site-packages/trello/__init__.py line 577. Change it from self.due = json_obj.get('due', '')[:10] to if json_obj.get('due', ''): self.due = json_obj.get('due', '')[:10]
  • Environment variables are set; TRELLO_KEY, TRELLO_SECRET, TRELLO_TOKEN

Trello Syntax

  • Each list that starts with "Model:" will be turned into a Django model. All other syntax is based on the cards in those lists.