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 fabric script automates the creation of a virtual environment and a Django | |
project. The result will be virtual environtment with the name of the project. | |
The folder namer where the project code will be placed is specified in | |
SOURCE_DIRECTORY_NAME, a static root folder will be created and settings.py | |
will be updated. | |
""" | |
try: | |
from fabric.api import env, run, local | |
from fabric.context_managers import lcd, prefix |
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
max = 999 | |
min = 100 | |
check = lambda x: True if str(x) == str(x)[::-1] else False | |
def tmp(max, min): | |
for x in xrange(max*max, min*min, -1): | |
if check(x): | |
for i in xrange(max, min, -1): | |
if x%i==0 and min < x/i < max : |
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 timeit | |
NUM = 10**10000 | |
def f1(): | |
x = [chr(i**i) for i in xrange(NUM) if i%2==1] | |
return x |
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 unittest | |
from datetime import datetime, timedelta | |
from tweetime import timelinetime | |
class TimeLineTimeTest(unittest.TestCase): | |
def test_timelinetime(self): | |
now = datetime.now() |
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
# views.py | |
from .models import News | |
from django.shortcuts import get_object_or_404 | |
def single_news(request, slug): | |
news = get_object_or_404(News.objects.public(), slug=slug) | |
return render_to_response('news/single_news.html', {'news': news}) |
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
# Problem 1 | |
def f(*args, **kwargs): | |
return sum(list(args) + kwargs.values()) | |
# Sample run | |
# f() | |
# f(1, 2, 3) | |
# f(a=1, c=3, b=2) | |
# f(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
import timeit | |
string = "Hello, World!" | |
def reverse(string): | |
result = "" | |
for i in xrange(len(string), 0, -1): | |
result = result+string[i-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
class ShortListSerializerMixin(object): | |
def get_fields(self): | |
use_list_fields = self.context['view'].action == u'list' \ | |
and getattr(self.Meta, 'list_fields') | |
if use_list_fields: | |
detail_fields = self.opts.fields | |
self.opts.fields = self.Meta.list_fields | |
fields = super(ShortListSerializerMixin, self).get_fields() |
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
# facebook-sdk==0.4.0 | |
def facebook_share(): | |
import facebook | |
graph = facebook.GraphAPI('you_key_here') | |
profile = graph.get_object("me") | |
# friends = graph.get_connections("me", "friends") |
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 bisect | |
import timeit | |
import random | |
def test_bisect(num): | |
data_list = list() | |
for i in range(1,num): | |
var=random.randint(1,num*100) | |
loc=bisect.bisect(data_list,var) |
OlderNewer