Skip to content

Instantly share code, notes, and snippets.

View pcdinh's full-sized avatar

Pham Cong Dinh pcdinh

View GitHub Profile
@pcdinh
pcdinh / about.txt
Created July 5, 2018 07:13 — forked from jessejlt/about.txt
nginx, flask, and file downloads
Okay so here's the setup:
[-] The primary server API is exposed via Flask (Python) and all static files, including all html, css, js is served by nginx.
[-] Python is exposing an API at url http://domain.com/api/download/<file_id>, where file_id is a database id for the file that we're interested in downloading.
1. User wants to download a file, so we spawn a new window with the url '/api/download/<file_id>'
2. Nginx intercepts the request, sees that it starts with /api/, and then forwards the request to Flask, which is being served on port 5000.
3. Flask routes the request to its download method, retrieves the pertinent data from the file_id, and constructs additional header settings to make nginx happy and to force the browser to see the file stream as a download request instead of the browser just trying to open the file in a new window. Flask then returns the modified header stream to nginx
4. Nginx is finally ready to do some work. While parsing the headers for the incoming request, it encounters "X
@pcdinh
pcdinh / test-laptop-dell
Last active June 18, 2018 11:09
Laptop Dell XPS 9360
1. Nguồn gốc (Service Tag)
cmd
wmic bios get serialnumber
http://www.dell.com/support/home/vn/en/vnbsdt1/products
2. Kiểm tra màn hình
Xước
Test điểm chết: Dead Pixel Buddy
@pcdinh
pcdinh / openresty-luarocks.sh
Created July 28, 2017 11:19 — forked from yagop/openresty-luarocks.sh
OpenResty + LuaRocks
wget http://openresty.org/download/ngx_openresty-1.7.10.1.tar.gz \
-O ngx_openresty-1.7.10.1.tar.gz
tar xzvf ngx_openresty-1.7.10.1.tar.gz
cd ngx_openresty-1.7.10.1
./configure
make
sudo make install
wget https://codeload.github.com/keplerproject/luarocks/tar.gz/v2.0.13 \
@pcdinh
pcdinh / nginx.conf
Created July 13, 2017 07:59 — forked from deltheil/nginx.conf
Hide sensitive GET parameters within nginx access logs thanks to the Lua module
http {
log_format filt '$remote_addr - $remote_user [$time_local] "$_request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
server {
location /login {
# `set` is provided by the Rewrite module
set $filter "password|secret";
@pcdinh
pcdinh / 100_base.conf
Created June 28, 2017 09:31 — forked from danackerson/100_base.conf
using nginx + lua + redis for redirects and rewrites
# using such a setup requires `apt-get install lua-nginx-redis` under Ubuntu Trusty
# more info @ http://wiki.nginx.org/HttpLuaModule#access_by_lua
http {
lua_package_path "/etc/nginx/include.d/?.lua;;";
lua_socket_pool_size 100;
lua_socket_connect_timeout 10ms;
lua_socket_read_timeout 10ms;
server {
@pcdinh
pcdinh / semiprivate.md
Created June 27, 2017 10:25 — forked from tarcieri/semiprivate.md
Ed25519-based semi-private keys

Semiprivate Keys

Semi-private keys are an expansion of the traditional idea of asymmetric keys, which have a public/private keypair, to N keys which can each represent a different capability level. In the degenerate case, a semi-private key system has 3 different types of keys. These are, to use the Tahoe terminology:

  • writecap: can publish new ciphertexts
  • readcap: can read/authenticate ciphertexts
@pcdinh
pcdinh / directio_mmap.py
Created December 10, 2016 00:02 — forked from Spindel/directio_mmap.py
Direct IO in Python
#!/bin/env python3
import os
import mmap
import logging
import hashlib
import contextlib
log = logging.getLogger(__name__)
@contextlib.contextmanager
def directio_mmap(filename, readsize, offset):
# Mở engine sửa đổi URL gốc
RewriteEngine on
# Tác động lên phần URL phía sau domain (REQUEST_URI)
RewriteBase /
# So sánh phần URL sau domain để xem có chứa ".css", ".gif" ... không. Nếu kết thúc bằng mấy cái đó thì bỏ qua
# Gửi URL như vậy thẳng vào engine của web server để xử lý và ngừng việc sửa ở đây.
RewriteCond %{REQUEST_URI} !.(css|gif|ico|jpg|js|png|swf|txt|pdf|docx|mp3|mp4|doc|zip|rar)$
# Kiểm tra xem URL gửi đến có trực tiếp yêu cầu 1 file đã tồn tại hay không? Nếu file thực sự tồn tại thì gửi nguyên URL đó
# đến web server và ngừng việc sửa ở đây.
RewriteCond %{REQUEST_FILENAME} !-f
@pcdinh
pcdinh / carett.log
Created April 30, 2016 04:31
Logging Tree
<--""
Level DEBUG
Handler Stream <open file '<stderr>', mode 'w' at 0x7f282d2491e0>
Formatter fmt='%(asctime)s %(levelname)s %(message)s' datefmt=None
Handler <raven.handlers.logging.SentryHandler object at 0x7f2827c4d050>
Level WARNING
|
o "carett"
| Level INFO
| Propagate OFF
@pcdinh
pcdinh / user_info.json
Created April 19, 2016 02:57
User info
{
"body": {
"uid": 454,
"career": {
"recruit_status": null,
"career_interested": null,
"college_concentrations": null,
"industry_interested": null
},
"semester": {