Skip to content

Instantly share code, notes, and snippets.

View chairco's full-sized avatar
🏠
Working from home

Jason chairco

🏠
Working from home
View GitHub Profile
@chairco
chairco / HTTrack.md
Created December 21, 2016 08:20 — forked from tmslnz/HTTrack.md
Nice command line for HTTrack

Commands

httrack example.com -O ./example.com -N100 −%i0 -I0 --max-rate 0 --disable-security-limits --near -v
httrack example.com -O ./example.com-3 -N100 -I0 -N "%p/%n%[month].%t" --max-rate 0 --disable-security-limits --near  -v

Options

@chairco
chairco / Python3.6-new.md
Last active December 27, 2016 08:02
What’s New In Python 3.6 原文: https://docs.python.org/3/whatsnew/3.6.html

新的語意 features:

  • PEP 498, formatted string literals.
  • PEP 515, underscores in numeric literals.
  • PEP 526, syntax for variable annotations.
  • PEP 525, asynchronous generators.
  • PEP 530: asynchronous comprehensions.

新的程式庫模組:

@chairco
chairco / list-in-dict-in-list.md
Last active January 6, 2017 02:24
Python dict in list 操作經驗

會碰到這樣資料結構可能是 Parser 的 Data 是從 JSON 格式而來,像是

[
  {
    'dict1':[
        {
          'dict2_0':'list2_0'
        },
 {
@chairco
chairco / react-error.md
Created January 6, 2017 15:48
react-error
%cUnhandled rejection Error: Not Found
    at Request.eval (webpack:///./~/superagent/lib/client.js?:508:19)
    at Request.Emitter.emit (webpack:///./~/component-emitter/index.js?:134:20)
    at XMLHttpRequest.xhr.onreadystatechange (webpack:///./~/superagent/lib/client.js?:952:10)
    at XMLHttpRequest.callback.(anonymous function) (/Users/chairco/OneDrive/SourceCode/g0v/web/react.vtaiwan.tw/node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:230:32)
    at invokeEventListeners (/Users/chairco/OneDrive/SourceCode/g0v/web/react.vtaiwan.tw/node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:195:25)
    at invokeInlineListeners (/Users/chairco/OneDrive/SourceCode/g0v/web/react.vtaiwan.tw/node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:163:7)
    at EventTargetImpl._dispatch (/Users/chairco/OneDrive/SourceCode/g0v/web/react.vtaiwan.tw/node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:122:7)
    at EventTargetImpl.dispatchEvent (/Users/chairco/OneDrive/Source
@chairco
chairco / python-os-path.md
Last active January 10, 2017 02:19
python os 路徑判斷兩三事

在 python os module 提供兩種判斷資料夾存在與否方法:

  1. os.path.isdir()
  2. os.path.exists()

這兩種差異在哪哪?簡單來舉個例子就知道了。假設我們有一個檔案 /Users/chairco/OneDrive/SourceCode/django/radar/radar/logs/ghostdriver.log 我們想知道這個檔案的資料夾存在與否。所以要先抽出檔案:

>>> path = '/Users/chairco/OneDrive/SourceCode/django/radar/radar/logs/ghostdriver.log'
>>> os.path.dirname(path)
@chairco
chairco / python-class-override.md
Created January 11, 2017 07:18
python class override

子類別 (subclass) 可依本身特性設定自己的屬性 (attribute) 與方法 (method) ,也會從父類別 (superclass) 繼承 (inherit) 屬性與方法。 一般來說,沒有設定成私有的屬性及方法都會被繼承,子類別可由父類別公開的方法存取父類別私有的屬性。

子類別也可依需要改寫 (override) 父類別的方法,這是說子類別需要用到與父類別具有相同名稱的方法,但是子類別需要的功能有所修改、擴充或增加, 因此當子類別裡頭定義與父類別相同名稱的方法時,就會改寫父類別的方法。經過改寫,子類別的方法完全屬於子類別所有,例如以下程式

class Demo:
    __x = 0
 
@chairco
chairco / beautiful_idiomatic_python.md
Created December 5, 2016 02:04 — forked from JeffPaine/beautiful_idiomatic_python.md
Transforming Code into Beautiful, Idiomatic Python: notes from Raymond Hettinger's talk at pycon US 2013. The code examples and direct quotes are all from Raymond's talk. I've reproduced them here for my own edification and the hopes that others will find them as handy as I have!

Transforming Code into Beautiful, Idiomatic Python

Notes from Raymond Hettinger's talk at pycon US 2013 video, slides.

The code examples and direct quotes are all from Raymond's talk. I've reproduced them here for my own edification and the hopes that others will find them as handy as I have!

Looping over a range of numbers

for i in [0, 1, 2, 3, 4, 5]:
@chairco
chairco / Python-MRO.md
Last active January 16, 2017 12:07
Python Tutorial: Understanding Python MRO - Class search path 中文翻譯 原文網址: https://makina-corpus.com/blog/metier/2014/python-tutorial-understanding-python-mro-class-search-path

Python Tutorial: Understanding Python MRO - Class search path

The Python Method Resolution Order defines the class search path used by Python to search for the right method to use in classes having multi-inheritance. It as envolved since Python 2.2 to 2.3. The algorithm change is also refered as old classes and new classes MRO algorithm. The new one is not so easy to bring out. This tutorial tries to explain by example each of them.

Python 方法解析順序(Method Resolution Order) 定義類別搜尋路徑提供 Python 在多重繼承類別查詢正確的使用方法。他在 Python 2.2 到 2.3 的版本做了一些進化。這個演算法同時被稱呼為經典的與新的經典 MRO 演算法。新的方法不是很容易說明。這個 Tutorial 嘗試透過範例去解釋兩者的不同之處。

History of new and old algorithms usages

import requests
import pandas
import json
url = 'http://ecshweb.pchome.com.tw/search/v3.3/all/results?q=%E5%88%AE%E9%AC%8D%E5%88%80&page=2&sort=rnk/dc'
r = requests.get(url)
jd = json.loads(r.text)
df = pandas.DataFrame(jd['prods'])
print df.head()