Skip to content

Instantly share code, notes, and snippets.

<p>
{{ form.name.errors }}
<label for=id_name>Name:</label>
{{ form.name }}
</p>
<p>
{{ form.is_captain.errors }}
<label for=id_is_captain>Is Captain?:</label>
{% if user %}
<input type=checkbox name=is_captain id=id_is_captain {% if object.is_captain %}checked{% endif %}>
class PirateForm(ModelForm):
class Meta:
model = Pirate
fields = ("name", "is_captain")
def __init__(self, *args, **kwargs):
user = kwargs.pop("user", None)
super().__init__(*args, **kwargs)
if not user:
@jbbarth
jbbarth / changelog_writer.py
Last active January 12, 2017 05:48
Usage: ./changelog_writer.py <new_tag> [from_tag]
#!/usr/bin/env python
import os
import re
import subprocess
import sys
CHANGELOG_FILE = "HISTORY.rst"
#!/usr/bin/env python
import os
import re
import subprocess
import sys
CHANGELOG_FILE = "HISTORY.rst"
#!/usr/bin/env ruby
puts "#{"PID".ljust(7)} PROCESS"
lines = %x(ps auxfwww|grep " simplefl[o]w ").lines.map do |line|
stats, command = line.split("|", 2)
tokens = stats.split
{ pid: tokens[1], command: command }
end
@jbbarth
jbbarth / sigabrt.py
Last active January 4, 2017 05:01
time.sleep() immediately returns when a signal is received
import time
import signal
def abrt_handler(signum, frame):
print "Hey I catched a signal {}".format(signum)
signal.signal(signal.SIGABRT, abrt_handler)
while True:
time.sleep(5)
#!/usr/bin/env ruby
def children(ps, pid)
ps.select do |p|
p.split[2] == pid
end
end
def pid_from_line(line)
line.split[1]
#!/bin/bash
if [ "$1" == "clone" ]; then
repo=$(echo $3|sed 's#.*/##')
key="$HOME/.ssh/id_rsa_$repo"
if [ -e "$key" ]; then
export GIT_SSH="ssh -i $key -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no"
fi
fi
git $*
@jbbarth
jbbarth / example1.py
Created March 16, 2016 05:50
Blog post test
def notify(msg):
print "NOTIFY: {}".format(msg)
def process():
#...
notify = False
if notify:
# take action
print "processing!"
#...
@jbbarth
jbbarth / patch.diff
Last active November 26, 2015 15:42
simpleflow classes support
diff --git a/examples/basic.py b/examples/basic.py
index 1b5e538..f431c59 100644
--- a/examples/basic.py
+++ b/examples/basic.py
@@ -17,10 +17,18 @@ def double(x):
return x * 2
+# simpleflow activities can be classes ; in that case the class is instantiated
+# with the params passed via submit, then the `execute()` method is called and