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
def get_dict(keys): | |
if keys: | |
return dict([k, ''] for k in keys) | |
return {} |
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 pymongo import Connection | |
class MongoCon(object): | |
__db = None | |
@classmethod | |
def get_connection(cls): | |
if cls.__db is None: | |
cls.__db = Connection() | |
return cls.__db |
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
engine = ConnectionPool.get_engine() | |
Base = declarative_base() | |
Session = scoped_session(sessionmaker(bind=engine)) |
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 | |
''.join(BeautifulSoup(page).findAll(text=True)) |
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
scala.io.Source.fromFile("file.txt").getLines.reduceLeft(_+_) |
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 django.utils.functional import curry | |
from django.views.defaults import server_error, page_not_found | |
handler500 = curry(server_error, template_name='admin/500.html') | |
handler404 = curry(page_not_found, template_name='admin/404.html') | |
url(r'^accounts/login/$', 'django.contrib.auth.views.login', {'template_name': 'admin/login.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
import os | |
PROJECT_ROOT = os.path.dirname(os.path.realpath(__file__)) | |
TEMPLATE_DIRS = ( | |
os.path.join(PROJECT_ROOT, 'templates'), | |
) |
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
d = {1:1, 2:2} | |
a = d.pop(1, None) # Pop item from d | |
b = d.get(2, None) # Get item from d, no change in the dict object |
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 itertools import chain | |
result_list = list(chain(page_list, article_list, post_list)) |
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
s = 'abcde' | |
print s[::-1] | |
print ''.join(reversed(s)) |
OlderNewer