This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Usage: chmown [options] <chmod-args> <chown-user>[:<chown-group>] | |
chmown () { | |
options='' | |
while [ -n "$(echo $1 | grep '-')" ]; do | |
options="$options $1" | |
shift | |
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Given the following HTML (a form generated by a django formset), I want to be able to | |
clone the form elements inside the div#book-form-container, omitting any values | |
<form action="/books/add/" method="post"> | |
<div id="book-form-wrapper"> <input type="hidden" name="form-TOTAL_FORMS" value="1" id="id_form-TOTAL_FORMS" /> <input type="hidden" name="form-INITIAL_FORMS" value="0" id="id_form-INITIAL_FORMS" /> | |
<div class="book-form-container"> | |
<input type="hidden" name="form-0-id" id="id_form-0-id" /> | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Image | |
def get_color_list(path_to_image): | |
""" | |
Returns a list of tuples for RGB colors: (R, G, B) | |
This is gonna be slow and memory-intensive. Use at your own risk. | |
Requires PIL | |
""" | |
def _get_color(t): return t[1] | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#X-------------------- minute (0 - 59) | |
#--X------------------ hour (0 - 23) | |
#-----X--------------- day of month (1 -31) | |
#-------X------------- month (1-12) | |
#----------X---------- day of week (0-7) (sunday = 0 or 7) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from BeautifulSoup import BeautifulSoup | |
def _remove_attrs(soup): | |
for tag in soup.findAll(True): | |
tag.attrs = None | |
return soup | |
def example(): | |
doc = '<html><head><title>test</title></head><body id="foo" onload="whatever"><p class="whatever">junk</p><div style="background: yellow;" id="foo" class="blah">blah</div></body></html>' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
In [14]: Decimal(2.0 * 3.0) | |
--------------------------------------------------------------------------- | |
TypeError Traceback (most recent call last) | |
/Users/oldbrad/Downloads/carmenproject/<ipython console> in <module>() | |
/System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/decimal.py in __new__(cls, value, context) | |
650 if isinstance(value, float): | |
651 raise TypeError("Cannot convert float to Decimal. " + | |
--> 652 "First convert the float to a string") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> from bleach import Bleach | |
>>> from janitor import html_tags # my stuff | |
>>> | |
>>> html_tags.basic_document_tags | |
['a', 'abbr', 'acronym', 'blockquote', 'cite', 'code', 'dd', 'del', 'dfn', 'dl', 'dt', 'em', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'hr', 'img', 'ins', 'kbd', 'li', 'ol', 'p', 'pre', 'q', 'samp', 'strong', 'ul', 'body', 'DOCTYPE', 'head', 'html', 'link', 'meta', 'style', 'title'] | |
>>> | |
>>> s = '<!DOCTYPE html><html><head><title>t</title></head><body><p><em>Some</em> stuff</p></body></html>' | |
>>> | |
>>> bl = Bleach() | |
>>> bl.clean(s, tags=html_tags.basic_document_tags) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCYTYPE html> | |
<html> | |
<head><title>countdown</title> | |
<style type="text/css"> | |
body { padding: 2em; margin: 0px auto; background-color: white; color: #222; font-family: "Helvetica", "Arial", sans-serif;} | |
h1 {border-bottom: 1px solid #aaa; text-align: center; } | |
p#countdown { font-size: 150px; text-align: center; margin: 0; padding: 0;} | |
table { width: 50%; margin: 0 auto; } | |
thead > tr {background-color: #aaa; } | |
td, th { text-align: center; padding: 1em; border: 1px solid #ccc; } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyModel(models.Model): | |
status = models.IntegerField() | |
stuff = models.ForeignKey() | |
def save(self, force_insert=False, force_update=False): | |
#if something has happened with stuff: | |
# update status | |
super(MyModel, self).save(force_insert, force_update) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Step 1: Create a style for the output of "hg log" | |
# See: http://hgbook.red-bean.com/read/customizing-the-output-of-mercurial.html | |
# I put this in: ~/.hg/templates/fileonly | |
changeset = '{files}' | |
file = '{file}\n' | |
# Step 2: Use the above style and sort/count your output | |
hg log --style ~/.hg/templates/fileonly --date="2011-01-01 to 2011-04-01" | sort | uniq -c | sort -r |
OlderNewer