Skip to content

Instantly share code, notes, and snippets.

#compdef fab
_targets() {
_describe -t commands "fabric targets" target_list
}
output_levels=(
'status: Status messages, i.e. noting when Fabric is done running, if the user used a keyboard interrupt, or when servers are disconnected from. These messages are almost always relevant and rarely verbose.'
'aborts: Abort messages. Like status messages, these should really only be turned off when using Fabric as a library, and possibly not even then. Note that even if this output group is turned off, aborts will still occur – there just won’t be any output about why Fabric aborted!'
'warnings: Warning messages. These are often turned off when one expects a given operation to fail, such as when using grep to test existence of text in a file. If paired with setting env.warn_only to True, this can result in fully silent warnings when remote programs fail. As with aborts, this setting does not control actual warning behavior, only whether warning messages are printed or hidden.'
@squarepegsys
squarepegsys / identity.py
Created September 18, 2013 18:59
This is a Django filter that returns just the base name of the object type. If you have 'book' of type 'book.models.Book', it would return 'Book'.
from django import template
register = template.Library()
@register.filter(name="identify")
def identify(value):
"""
Arguments:
- `value`: some object, probably a model
@squarepegsys
squarepegsys / countdown.py
Created October 9, 2013 18:00
Trying to get "X days, Y hours, and Z minutes" string with a timedelta. Also, try to use singular when the value is 1
def get_label(label,val):
if val!=1:
return label+"s"
return label
diff = somedate -datetime.now()
hours, remainder = divmod(diff.seconds, 3600)
import groovy.text.SimpleTemplateEngine
def text = '${firstName} ${lastName} is a member of the ${lodge}'
def binding = [firstName: "Fred", lastName: "Flintstone", lodge:"Water Buffaloes"]
def engine = new SimpleTemplateEngine()
template = engine.createTemplate(text).make(binding)
import groovy.text.SimpleTemplateEngine
/* this causes
* groovy.lang.MissingPropertyException: No such property: firstName for class: bad_template
*/
def text = "${firstName} ${lastName} is a member of the ${lodge}"
def binding = [firstName: "Fred", lastName: "Flintstone", lodge:"Water Buffaloes"]
def engine = new SimpleTemplateEngine()
import groovy.text.SimpleTemplateEngine
class Member{
String firstName
String lastName
String lodge
}
def text = '${firstName} ${lastName} is a member of the ${lodge}'
def member = new Member(firstName: "Fred", lastName: "Flintstone", lodge:"Water Buffaloes")
@squarepegsys
squarepegsys / this--is-wrong.groovy
Created August 6, 2014 19:57
Groovy blank fields
/* Check if all fields are blank */
StringBuilder rInfoRows = new StringBuilder()
rInfoRows.append(params.get("field1")?.toString()?.trim())
rInfoRows.append(params.get("field2")?.toString()?.trim())
rInfoRows.append(params.get("field3")?.toString()?.trim())
Boolean isRInfoPresent = Boolean.FALSE
if(!"".equals(rInfoRows.toString())){
isRInfoPresent = Boolean.TRUE
}
@squarepegsys
squarepegsys / psudo.py
Created August 7, 2014 13:51
Pseudo XML Python
tag1 = et.find("the_tag['sID']='GUID'")
tag2 = tag1.find("the_tag['eID']='GUID'")
content = tag2.previousSibling.text()
from lxml import etree
def bib2html(xmlString):
root = etree.fromstring(xmlString)
out = etree.Element("out")
for beg_verse in root.findall(".//verse[@sID]"):
@squarepegsys
squarepegsys / template_resuse.groovy
Created October 28, 2014 17:39
Reusing a template
import groovy.text.SimpleTemplateEngine
class Member{
String firstName
String lastName
String lodge
}
def text = '${firstName} ${lastName} is a member of the ${lodge}'