This file contains hidden or 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 urllib.request import urlopen | |
| # Original class | |
| class UrlTemplate: | |
| def __init__(self, template): | |
| self.template = template | |
| def open(self, **kwargs): | |
| return urlopen(self.template.format_map(kwargs)) |
This file contains hidden or 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 print_msg(msg): | |
| def printer(): | |
| print(msg) | |
| printer() | |
| print_msg("hello") # hello | |
| def print_msg(msg): | |
| def printer(): |
This file contains hidden or 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
| # Suppose I have a list of points, I want to order this list by calculating distance for specific points. | |
| from functools import partial | |
| import math | |
| points = [(1, 2), (3, 4), (5, 6), (7, 8)] | |
| def distance(p1, p2): | |
| x1, x2 = p1 | |
| y1, y2 = p2 | |
| return math.hypot(x2 - x1, y2 - y1) |
This file contains hidden or 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
| x = 10 | |
| a = lambda y: x + y | |
| x = 20 | |
| b = lambda y: x + y | |
| a(10) # 30 | |
| b(10) # 30 | |
| x = 15 | |
| a(10) # 25 |
This file contains hidden or 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 spam(a, b=42): | |
| print(a, b) | |
| spam(1) # a=1, b=42 | |
| spam(1, 2) # a=1, b=2 | |
| def spam(a, b=None): | |
| if b is None: | |
| b = [] |
This file contains hidden or 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 add(x: int, y: int) -> int: | |
| return x + y |
This file contains hidden or 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 | |
| import sys | |
| import json | |
| from threading import Thread | |
| from collections import OrderedDict | |
| from tweepy.streaming import StreamListener | |
| from tweepy.api import API | |
| from tweepy import OAuthHandler | |
| from tweepy import Stream |
This file contains hidden or 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 matplotlib.pyplot as plt | |
| import cv2 | |
| fig = plt.figure("fig_1") | |
| ax = fig.add_subplot(1, 1, 1) | |
| image = cv2.imread("xxx.jpg") | |
| ax.imshow(image) | |
| plt.show() |
This file contains hidden or 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 numpy as np | |
| import matplotlib.pyplot as plt | |
| #%matplotlib inline | |
| X = np.linspace(0, 10, 256) | |
| plt.plot(X) |
This file contains hidden or 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
| OSRM build on Linux Ubuntu 14.04LTS | |
| 1. | |
| sudo apt-get install build-essential git cmake pkg-config \ | |
| libbz2-dev libstxxl-dev libstxxl-doc libstxxl1 libxml2-dev \ | |
| libzip-dev libboost-all-dev lua5.1 liblua5.1-0-dev libluabind-dev libtbb-dev | |
| 2. | |
| git clone https://github.com/Project-OSRM/osrm-backend.git | |
| cd osrm-backend |