Skip to content

Instantly share code, notes, and snippets.

@anhtran
anhtran / create_datetime_from_timeago.py
Created March 20, 2019 06:47
create datetime from time ago string (Vietnamese)
import arrow
def create_datetime_from_timeago(text, timezone='Asia/Saigon'):
"""
Create datetime object from timeago string.
Author: anhtran <anhtran.net>
:param str text:
:param str timezone:
Example:
5 phút trước
@anhtran
anhtran / userChrome.css
Last active November 26, 2021 12:32
Custom Firefox Quantum Dev Tools (Network tab)
/* https://www.userchrome.org/what-is-userchrome-css.html */
/* Preview: https://imgur.com/kZmJ75T */
.requests-list-file.requests-list-column {
background-color: #48654b1a !important;
color: #ddd !important;
min-width: 300px !important;
direction: rtl !important;
}
.requests-list-file.requests-list-column[title*='/web-api'] {
@anhtran
anhtran / google-webfont-async.php
Created November 18, 2018 07:57 — forked from paulund/google-webfont-async.php
Javascript tag to load google web font async
<script type="text/javascript">
WebFontConfig = {
google: { families: [ 'Roboto' ] }
};
(function() {
var wf = document.createElement('script');
wf.src = ('https:' == document.location.protocol ? 'https' : 'http') +
'://ajax.googleapis.com/ajax/libs/webfont/1.6.26/webfont.js';
wf.type = 'text/javascript';
wf.async = 'true';
@anhtran
anhtran / youtrack-nginx.conf
Last active June 21, 2018 09:59
Using YouTrack with nginx as proxy, so you can install Certbot easily (Let's Encrypt)
# Run command: `java -Xmx1g -XX:MaxMetaspaceSize=250m -Djava.awt.headless=true -jar youtrack-xxxx.x.xxx.jar my.domain.com:9988`
upstream youtrack_upstream {
server my.domain.com:9988;
}
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
@anhtran
anhtran / vietnam_provinces.py
Last active May 4, 2024 10:10
Python List provinces of Vietnam in 2024. Danh sách tỉnh thành của Vietnam cung cấp dưới dạng dict.
# created by @anhtt <anhtran.net>, 2018/05/23
# 63 cities and provices of Vietnam, updated in 2024.
PROVINCES = {
'HCMC': 'Hồ Chí Minh',
'HANOI': 'Hà Nội',
'HAIPHONG': 'Hải Phòng',
'DANANG': 'Đà Nẵng',
'CANTHO': 'Cần Thơ',
'HAGIANG': 'Hà Giang',
@anhtran
anhtran / unicode_utils.py
Created April 18, 2018 05:41
Hàm số Chuyển đổi chuỗi Unicode Tổ Hợp sang Unicode Dựng Sẵn trong Python 3
def compound_unicode(unicode_str):
"""
Chuyển đổi chuỗi Unicode Tổ Hợp sang Unicode Dựng Sẵn
Edited from: `https://gist.github.com/redphx/9320735`
"""
unicode_str = unicode_str.replace("\u0065\u0309", "\u1EBB") # ẻ
unicode_str = unicode_str.replace("\u0065\u0301", "\u00E9") # é
unicode_str = unicode_str.replace("\u0065\u0300", "\u00E8") # è
unicode_str = unicode_str.replace("\u0065\u0323", "\u1EB9") # ẹ
unicode_str = unicode_str.replace("\u0065\u0303", "\u1EBD") # ẽ
@anhtran
anhtran / save_gif.py
Created March 6, 2018 03:46
Example python code for saving animated GIF into file using Pillow
# (c) 2018 Anh Tran <anhtran.net>
import requests
from PIL import ImageSequence
def fetch_chap_img(img_url):
""" Get image from internet then saving it on disk """
r = requests.head(img_url)
if r.status_code == 200:
r = requests.get(img_url)
# sets the proxy cache path location, max size 2g
proxy_cache_path /data/nginx/cache levels=1:2 keys_zone=STATIC:100m inactive=24h max_size=2g;
# transfers the `Host` header to the backend
proxy_set_header Host $host;
# uses the defined STATIC cache zone
proxy_cache STATIC;
# cache 200 10 minutes, 404 1 minute, others status codes not cached
@anhtran
anhtran / example_image_utils.py
Created November 29, 2017 03:54 — forked from josephkern/example_image_utils.py
Layer on top of Python Imaging Library (PIL) to write text in images easily
#!/usr/bin/env python
# coding: utf-8
# You need PIL <http://www.pythonware.com/products/pil/> to run this script
# Download unifont.ttf from <http://unifoundry.com/unifont.html> (or use
# any TTF you have)
# Copyright 2011 Álvaro Justen [alvarojusten at gmail dot com]
# License: GPL <http://www.gnu.org/copyleft/gpl.html>
from image_utils import ImageText
@anhtran
anhtran / upgrade_ghost.sh
Created April 25, 2017 06:10
Script for Upgrading ghost blog
#!/bin/bash
cd /home/username/webapps/my_ghost_blog
curl -LOk https://ghost.org/zip/ghost-latest.zip
unzip ghost-latest.zip -d ghost-latest
cd ./ghost
rm -rf core index.js package.json npm-debug.log *.md
cp -R ../ghost-latest/core .
cp -R ../ghost-latest/index.js .