Skip to content

Instantly share code, notes, and snippets.

Qiwei Huang qhuang872

  • San Jose
Block or report user

Report or block qhuang872

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@qhuang872
qhuang872 / reset.less
Created Mar 7, 2017 — forked from joshuapowell/reset.less
LESS: Global LESS CSS reset that gives elements default formatting.
View reset.less
/**
* Global Reset of all HTML Elements
*
* Resetting all of our HTML Elements ensures a smoother
* visual transition between browsers. If you don't believe me,
* try temporarily commenting out this block of code, then go
* and look at Mozilla versus Safari, both good browsers with
* a good implementation of CSS. The thing is, all browser CSS
* defaults are different and at the end of the day if visual
* consistency is what we're shooting for, then we need to
View fix.txt
Original error happens on line 11, that exit_ok was default to be False which caused the file_exist erorr, I made the change to set it to be True.
Also added a docstring for the download_file function.
View fix.txt
Original error happens on line 11, that exit_ok was default to be False which caused the file_exist erorr, I made the change to set it to be True.
Also added a docstring for the download_file function.
View sample.py
import os
import urllib.request
from urllib.parse import urlparse
def download_file(url, cachedir=None, ignorecache=False, filename=None) -> str:
"""download_file would create a directory if not exist, then download the file to directory"""
if not cachedir:
cachedir = os.path.join(os.getcwd(), "build")
@qhuang872
qhuang872 / answer.txt
Created Dec 31, 2016
Qiwei's answer to optimization take-home-test
View answer.txt
1, average runtime of the program is 52 seconds.
2, I separate the program into 4 different small functions, each serving only one purposes: read_content, get_link, download_video and download_image. So that I can measure memory usage of each part, using memory_profiler. According to the output of memory_profiler, read_content takes up the most memory: about 48 MiB. Other functions and their memory usage: get_link uses 40 MiB, download_video uses 42 MiB, and download_image uses 45 MiB.
3, in this program, variable contents which is a json object occupies most memory.
4, 1) the first way to optimize this script is to skip the "get_link" process, which means instead of storing all mp4_links and png_links into lists, since the "get_link" process is just a for loop, by eliminating this process, we are reducing runtime as well. We can just iterate through every json object, and just download the link from there. However, this solution only reduces runtime by 1~2 seconds in average, in my opinion, this is not
You can’t perform that action at this time.