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
#example of bad code | |
for indice in xrange(0, len(l)): | |
print "l[%d] = %r" % (indice, l[indice]) | |
# ==> | |
#the best way to perform such operation (get indices and corresponding values) is by using enumerate | |
for indice, value in enumerate(l): | |
print "l[%d] = %r" % (indice, value) | |
#since enumerate returns a list of tuples : |
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
*/15 * * * * /home/user/sphinx/bin/indexer --config /home/user/webapps/project-name/sphinx.conf --rotate profiles_delta | |
0 0 * * * /home/user/sphinx/bin/indexer --config /home/user/webapps/project-name/sphinx.conf --merge profiles profiles_delta --merge-dst-range deleted 0 0 --rotate |
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
#appen an element to a list | |
li = [1, 2, 3, 4, 5] | |
li.append(6) | |
print li # [1, 2, 3, 4, 5, 6] |
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_primes(x): | |
non_primes = set() | |
primes = set() | |
for i in range(2, x+1): | |
if x%i == 0 and i not in non_primes: | |
primes.add(i) | |
j = i | |
while j*i <= x: | |
non_primes.add(i*j) | |
j += 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
def primes_less(x): | |
non_prime = set() | |
i = 2 | |
while i*i <= x: | |
if i not in non_prime: | |
j = i | |
while j*i <= x: | |
non_prime.add(j*i) | |
j += 1 | |
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
def get_primes_multiplicities(x): | |
""" | |
Returns factors for x! | |
""" | |
p_multi = {}#factors multiplicities | |
for p in primes_less(x): | |
temp = x | |
mult = 0 | |
while temp!= 0: | |
temp /= p |
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 nbr_factors_sqr(x): | |
nbr = 1 | |
for f in get_primes_multiplicities(x).values(): | |
nbr *= (2*f + 1) | |
return nbr |
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 fabric.api import local | |
from fabric.api import lcd | |
def prepare_deployment(branch_name): | |
local('python manage.py test myapp') | |
local('git add -p && git commit') | |
local('git checkout master && git merge ' + branchname) | |
def deploy(): |
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 Musician(models.Model): | |
first_name = models.CharField(max_length=50) | |
last_name = models.CharField(max_length=50) | |
instrument = models.CharField(max_length=100) | |
class Meta: | |
app_label = 'myapp' |
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 Album(models.Model): | |
artist = models.ForeignKey('Musician') | |
name = models.CharField(max_length=100) | |
release_date = models.DateField() | |
num_stars = models.IntegerField() | |
class Meta: | |
app_label = 'myapp' |
OlderNewer