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
To install node.js and coffee-script inside a virtualenv and keep it self-contained: | |
1. Activate the virtualenv:: | |
$ workon test | |
2. Move inside the virtualenv directory:: | |
(test)$ cdvirtualenv |
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
#-*-coding: utf-8-*- | |
K = 3 | |
STRINGS = ['abacainstitutebac', 'mycabacrchinstituteve', 'acabacinstinstituterue'] | |
def sort(i, outputs=[]): | |
string = "" | |
k = i | |
while len(string) < len(STRINGS[0])-i: |
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 collections import namedtuple | |
# make a basic Point class | |
Point = namedtuple('Point', ["lat", "lon"]) | |
points = [Point(1,2), | |
Point(3,4), | |
Point(5,6)] | |
# implement the function gmaps_img(points) that returns the google maps image | |
# for a map with the points passed in. A example valid response looks like |
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 time | |
# complex_computation() simulates a slow function. time.sleep(n) causes the | |
# program to pause for n seconds. In real life, this might be a call to a | |
# database, or a request to another web service. | |
def complex_computation(a, b): | |
time.sleep(.5) | |
return a + b | |
# QUIZ - Improve the cached_computation() function below so that it caches |
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
#handy link | |
#http://stackoverflow.com/questions/423379/using-global-variables-in-a-function-other-than-the-one-that-created-them | |
#maybe a link to itertools | |
SERVERS = ['SERVER1', 'SERVER2', 'SERVER3', 'SERVER4'] | |
# QUIZ - implement the function get_server, which returns one element from the | |
# list SERVERS in a round-robin fashion on each call. Note that you should | |
# comment out all your 'print get_server()' statements before submitting | |
# your code or the grading script may fail. For more info see: |
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 collections import namedtuple | |
friends_json = [{ | |
'uid': 16734834, | |
'first_name': 'Alena', | |
'last_name': 'Grin', | |
'deactivated': 'banned', | |
'photo': 'http://vk.com/images/deactivated_c.gif', | |
'online': 0, | |
'user_id': 16734834, | |
'lists': [26] |
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
IP_URL = "http://api.hostip.info/?ip=" | |
' | |
def location(self, user): | |
""" | |
:param user: user id(uid) | |
:return: address from ndb, coordinates from IP | |
""" | |
address = '%s, %s' % (user.country, user.city) | |
coords = self.get_coords(self.request.remote_addr) # receive location from id | |
if coords == None: |
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
To do so on terminal: | |
gksu gedit /etc/polkit-1/localauthority/50-local.d/com.ubuntu.enable-hibernate.pkla | |
Replace gedit with your favorite editor’s command. This command will open a blank file. Copy and paste these lines: | |
[Enable Hibernate] | |
Identity=unix-user:* | |
Action=org.freedesktop.upower.hibernate | |
ResultActive=yes |
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 printTable( data, header=None ): | |
lens = [0]*len(data[0]) | |
for row in data: | |
for numCol, column in enumerate(row): | |
cLen = len(str(column)) | |
if lens[numCol] < cLen: | |
lens[numCol] = cLen | |
res = "" | |
spacer = lambda lenList: '+' + '+'.join( '-'*(x+2) for x in lenList ) + '+' | |
drawRow = lambda lenList, valueList: '|' + "".join( |
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
l=[3,11,2,4,2,1,3,4,62,6,67,8,2,3,2246] | |
tmp = l[0] | |
for i in l: | |
for j in l: | |
if i<j and i<tmp: | |
tmp = i | |
print tmp |
OlderNewer