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
jQuery('div#message').addClass( | |
'borderfade' | |
).animate({ | |
'borderWidth': '+10px' | |
}, 1000).fadeOut(); | |
// Can be 'packaged' as: | |
jQuery.fn.dumbBorderFade = function() { |
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 os, random | |
random.choice(os.listdir("C:\\")) #change dir name to whatever |
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
dict(a=1, b=2, c=3) | |
returns {'a': 1, 'b': 2, 'c': 3} |
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
# Both seem to work for something like: | |
mydict = {'a' : 1, 'b' : 2} | |
for key,val in mydict.items(): | |
print key,val | |
# ==> a 1 b 2 | |
for key,val in mydict.iteritems(): |
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
#!/usr/local/bin/python | |
import sys | |
import time | |
havevalue = 0 | |
while havevalue < 1: | |
try: | |
table = input("What table to you want? ") |
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
globvar = 0 | |
def set_globvar_to_one(): | |
global globvar # Needed to modify global copy of globvar | |
globvar = 1 | |
def print_globvar(): | |
print globvar # No need for global declaration to read value of globvar | |
set_globvar_to_one() |
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
#! /usr/bin/env python | |
# Released to the public domain, by Tim Peters, 03 October 2000. | |
"""reindent [-d][-r][-v] [ path ... ] | |
-d (--dryrun) Dry run. Analyze, but don't make any changes to, files. | |
-r (--recurse) Recurse. Search for all .py files in subdirectories too. | |
-n (--nobackup) No backup. Does not make a ".bak" file before reindenting. | |
-v (--verbose) Verbose. Print informative msgs; else no output. |
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
// add a function as an element of a dictionary | |
>>> {1: lambda: len('ciao')} | |
>>> {1: <function <lambda> at 0x101d530>} | |
// get element with specified key | |
>>> {1: lambda: len('ciao')}[1] | |
>>> <function <lambda> at 0x101d5f0> | |
>>> a = {1: lambda: len('ciao')}[1] | |
>>> a | |
>>> <function <lambda> at 0x101d670> |