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 / nodejs-ubuntu-bind-port-80.md
Created March 21, 2018 02:52 — forked from guifromrio/nodejs-ubuntu-bind-port-80.md
Allow Node.js to bind to privileged ports without root access on Ubuntu

How to: Allow Node to bind to port 80 without sudo

TL;DR

Only do this if you understand the consequences: all node programs will be able to bind on ports < 1024

sudo setcap 'cap_net_bind_service=+ep' /usr/local/bin/node

Important: your node location may vary. Use which node to find it, or use it directly in the command:

@chairco
chairco / jupyter-architect.md
Last active May 16, 2020 16:47
jupyter cluster 架構

Target

目前有組一台主機來做科學計算,因此打算建構一個 remote 環境運行 Jupyterhub 跑科學計算。 原則上使用 jupyterhub 只是假設未來有多人使用需求可以區隔環境。

架構大概是這樣:

#

@chairco
chairco / search.py
Last active March 1, 2018 14:46
live coding
#-*- coding: utf-8 -*-
"""
Find the best discount groups's combination
Author: Jason
Example:
$ python search.py
"""
@chairco
chairco / 2018_PyConTW_Talk.md
Last active May 1, 2019 12:28
Real-time web, Asynchronous I/O and Django channels 介紹,為 PyConTW 2018 演講概略內容。

Real-time web

維基是這樣定義 Real-time web 的:

The real-time web is a set of technologies and practices which enable users to receive information 
as soon as it is published by its authors, rather than requiring that they or their software check 
a source periodically for updates.

大意是指當作者在網頁上更新訊息時,其他使用者不需要做任何裝置上的刷新操作可以立即的在裝置上得到新資訊。

Python Socket 编程详细介绍

Python 提供了两个基本的 socket 模块:

  • Socket 它提供了标准的BSD Socket API。
  • SocketServer 它提供了服务器重心,可以简化网络服务器的开发。

下面讲解下 Socket模块功能。

Socket 类型

@chairco
chairco / backend-architectures.md
Created February 8, 2018 15:07 — forked from ngocphamm/backend-architectures.md
Backend Architectures
@chairco
chairco / timestamp.md
Last active January 17, 2018 07:03
python timestamp transfer

轉錄,因為之前用 python 處理時間戳,看到不錯文章。

python 時間戳處理

Unix 時間戳根據精度的不同,有10位(秒級),13位(毫秒級),16位(微妙級)和19位(納秒級)。在python中,我們可以將一個整數的時間戳轉換為字符串格式,如'2016-02-25 20:21:04',也可以將其轉換為python中的datetime格式。反之,也可以將整數的時間戳轉換為字符串格式和datetime格式。用圖展示如下:

             +------------+             
             | timestamp  |             
       +---->|            |<-----+      
       |     +------------+      |      
  • option+shift+k -> 
@chairco
chairco / data_analysis.md
Last active January 16, 2018 05:26
data-analysis 筆記
  1. Data mining 從資料中找出一些關係(和目前 ML 很像)不限用統計方法

  2. 統計方法 以機率為出發點,著重找參數(例如: 平均數和變異數)目的是在做推論。所以主要程序會是建模(假設)>輸入資料>建模。所謂建模就是先告訴他一些特徵值。通常喜歡用常態分配來推估。

  3. 機器學習 不以機率為出發點,雖然借用一些統計方法但實際上在做的事情受限於電腦無法精確算出數值,所以會以近似值逼近,例如微分就是用數值微分等等。以統計學觀點來看就是未做一些假設,純粹以資料驅動。

@chairco
chairco / classmethodvsstaticmethod.md
Last active January 11, 2018 07:29
classmethod v.s staticmethod in python

@classmethod 和 @staticmethod 有什麼差異?

最近遇到人家問我的問題。老實講最後一次使用應該是在 g0v 專案,而且只使用 classmethod,會使用是因為有些方法不需要做物件初始化,只需要傳遞本身參數。 被問到也有點訝異,驚嚇是竟然會忘記這個挺不錯的裝飾器。好吧,做點功課別忘了。

兩者差異應該我來看就只有一個,classmethod 傳遞是自己的參數 cls 而非物件的 self... 用講的太籠統,直接上實例吧:

class A:
 def foo(self, x):