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
defaults write com.apple.versioner.python Version 2.6 # or 2.5, 2.4 .. |
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
if (testarray.length <1) alert("array is empty"); | |
//or | |
if(A && A.length==0) | |
//or if you have other objects that A may be: | |
if(A && A.constructor==Array && A.length==0) |
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 datetime import datetime, timedelta | |
now = datetime.now() | |
sometime_in_the_future = datetime(2020, 1, 1, now.hour, now.minute, now.second) | |
MAX_AGE = timedelta(hours=2, minutes=0) | |
if (now - sometime_in_the_future) > MAX_AGE: | |
return True | |
else: | |
return False |
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
DROP TABLE IF EXISTS `django_session_cleaned`; | |
CREATE TABLE `django_session_cleaned` ( | |
`session_key` varchar(40) NOT NULL, | |
`session_data` longtext NOT NULL, | |
`expire_date` datetime NOT NULL, | |
PRIMARY KEY (`session_key`) | |
) ENGINE=InnoDB DEFAULT CHARSET=utf8; | |
INSERT INTO `django_session_cleaned` SELECT * FROM `django_session` WHERE `expire_date` > CURRENT_TIMESTAMP; |
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
""" MoinMoin - Python Source Parser """ | |
import cgi, sys, cStringIO | |
import keyword, token, tokenize | |
# Python Source Parser (does highlighting into HTML) | |
_KEYWORD = token.NT_OFFSET + 1 | |
_TEXT = token.NT_OFFSET + 2 | |
_colors = { | |
token.NUMBER: '#0080C0', | |
token.OP: '#0000C0', | |
token.STRING: '#004080', |
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
# This searches recursively for all directories (-type d) in the hierarchy starting at "." (current directory), and finds those whose name is '.svn'; the list of the found directories is then fed to rm -rf for removal. | |
find . -name '.svn' -type d | xargs rm -rf | |
# If you want to try it out, try | |
find . -name '.svn' -type d | xargs echo | |
# This should provide you with a list of all the directories which would be recursively deleted. |
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
# Try to use the C implementation first, falling back to python | |
try: | |
from xml.etree import cElementTree as ElementTree | |
except ImportError, e: | |
from xml.etree import ElementTree | |
########## | |
def find(*args, **kwargs): | |
"""Find a book in the collection specified""" |
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 time import mktime | |
from datetime import datetime | |
dt = datetime.fromtimestamp(mktime(item['updated_parsed'])) |
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
## {{{ http://code.activestate.com/recipes/52231/ (r1) | |
class Counter: | |
def __init__(self): | |
self.dict = {} | |
def add(self,item): | |
count = self.dict.setdefault(item,0) | |
self.dict[item] = count + 1 | |
def counts(self,desc=None): | |
'''Returns list of keys, sorted by values. | |
Feed a 1 if you want a descending sort.''' |
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
Python 2.6.1 (r261:67515, Feb 11 2010, 00:51:29) | |
[GCC 4.2.1 (Apple Inc. build 5646)] on darwin | |
Type "help", "copyright", "credits" or "license" for more information. | |
>>> word_list = ['Jellicle', 'Cats', 'are', 'black', 'and', 'white,', 'Jellicle', 'Cats', 'are', 'rather', 'small;', 'Jellicle', 'Cats', 'are', 'merry', 'and', 'bright,', 'And', 'pleasant', 'to', 'hear', 'when', 'they', 'caterwaul.', 'Jellicle', 'Cats', 'have', 'cheerful', 'faces,', 'Jellicle', 'Cats', 'have', 'bright', 'black', 'eyes;', 'They', 'like', 'to', 'practise', 'their', 'airs', 'and', 'graces', 'And', 'wait', 'for', 'the', 'Jellicle', 'Moon', 'to', 'rise.', ''] | |
>>> word_counter = {} | |
>>> for word in word_list: | |
... if word in word_counter: | |
... word_counter[word] += 1 | |
... else: | |
... word_counter[word] = 1 |