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
url = 'https://www.gravatar.com/avatar/ad45f075aa4d69cbd552b671a32bf3ed?s=32&d=identicon&r=PG&f=1' | |
def save_image_as_base64(browser, url): | |
""" | |
""" | |
base = browser.execute_async_script(""" | |
var done = arguments[0]; | |
function toDataURL(url, callback) { | |
var xhr = new XMLHttpRequest(); |
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 PyPDF2 import PdfFileMerger | |
from svglib.svglib import svg2rlg | |
from reportlab.graphics import renderPDF | |
def svgs_to_pdf(file_paths=[r'C:\1.svg',r'C:\2.svg',r'C:\3.svg'], output_folder='tmp', pdf_name='test.pdf'): | |
""" | |
Convert svg files into pdfs, save pdfs in output_folder, merge them in one pdf file. | |
@param file_paths: full paths to svg files | |
@param output_folder: path to folder for saving temporary pdfs | |
@param pdf_name: name for resulting pdf file. |
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 numpy as np | |
from scipy.spatial import distance | |
def add_points_to_distance_matrix(points, original_array, distance_matrix, metric='euclidean'): | |
""" | |
There is an NxM array of points, a square matrix NxN with distances between points. | |
This function adds new points to the distance matrix. | |
We need to create a diagonal block holding distances between the new points | |
and two identical blocks holding distances to original array. | |
E.g. |
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 dfs_traverse(root): | |
stack = [] | |
stack.append(root) | |
while (stack): | |
node = stack.pop() | |
for child in node.children: | |
stack.append(child) | |
process_node(node) |
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 deque | |
def bfs_traverse(root): | |
queue = deque([]) | |
queue.append(root) | |
while (queue): | |
node = queue.popleft() | |
for child in node.children: | |
queue.append(child) |
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
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Bokeh Plot</title> <link rel="stylesheet" href="https://cdn.pydata.org/bokeh/release/bokeh-0.12.1.min.css" type="text/css" /> <script type="text/javascript" src="https://cdn.pydata.org/bokeh/release/bokeh-0.12.1.min.js"></script> <script type="text/javascript"> Bokeh.set_log_level("info"); </script> <style> html { width: 100%; height: 100%; } body { width: 90%; height: 100%; margin: auto; } </style> </head> <body> <div class="bk-root"> <div class="plotdiv" id="8f4aa28a-874e-433f-958f-e92f767d005d"></div> </div> <script type="text/javascript"> Bokeh.$(function() { var docs_json = {"be98bf1a-5a89-48ca-b8ef-b563f0b4001a":{"roots":{"references":[{"attributes":{"fill_color":{"value":"blue"},"inner_radius":{"units":"data","value":0.1},"line_color":{"value":"blue"},"outer_radius":{"units":"data","value":0.1},"x":{"value":2},"y":{"field":"y"}},"id":"af43fdc4-5308-4d5e-94d5-ee6751f9f733","type":"Annulus"},{"attributes":{"plot":null,"text":null},"id |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
#e.g. if you have a list comprehension that can return only 1 element or an empty list | |
>>> reduce(lambda x,y:y, [], None) | |
None | |
>>> reduce(lambda x,y:y, [5], None) | |
5 | |
>>> return [5] if [5] else None | |
5 |
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
Mon May 09 05:55:14 2016 old | |
28055818 function calls (28031179 primitive calls) in 108.555 seconds | |
Ordered by: internal time | |
ncalls tottime percall cumtime percall filename:lineno(function) | |
3666302 33.412 0.000 55.143 0.000 utils.py:307(find) | |
6232384 12.518 0.000 16.739 0.000 utils.py:266(_getrange) | |
165520 8.038 0.000 64.496 0.000 layout.py:601(isany) |
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
DSD_Y41-650-D-PermitsCompleted.pdf 34 pages | |
Sun May 08 22:53:13 2016 restats_w | |
53819963 function calls (53796078 primitive calls) in 187.163 seconds | |
Ordered by: internal time | |
ncalls tottime percall cumtime percall filename:lineno(function) |
NewerOlder