Skip to content

Instantly share code, notes, and snippets.

@anhtran
anhtran / Tutorials.md
Created April 9, 2020 14:39
How to install Swift latest version on Debian 9/10
  1. Prerequisites: sudo apt-get install clang libcurl3 libpython2.7 libpython2.7-dev
  2. Download latest stable version from official website: https://swift.org/download/#releases For example: wget https://swift.org/builds/swift-5.2.1-release/ubuntu1804/swift-5.2.1-RELEASE/swift-5.2.1-RELEASE-ubuntu18.04.tar.gz
  3. Untar and move the folder to some places on disk: sudo mv swift-5.2.1-RELEASE-ubuntu18.04 /opt/swift
  4. Add to environment of shell (bash or zsh).
  5. Check version by using: swift --version

IMPORTANT: If you get stuck with error like this: error while loading shared libraries: libtinfo.so.5, you need install an additional package to make it works: sudo apt install libncurses5

@anhtran
anhtran / [ReactJS] Detect Scrolls To Bottom
Created February 24, 2020 10:57 — forked from enqtran/[ReactJS] Detect Scrolls To Bottom
[ReactJS] Detect Scrolls To Bottom
constructor(props) {
super(props);
this.state = {
height: window.innerHeight,
message: 'not at bottom'
};
this.handleScroll = this.handleScroll.bind(this);
}
handleScroll() {
const windowHeight = "innerHeight" in window ? window.innerHeight : document.documentElement.offsetHeight;
@anhtran
anhtran / vrack.md
Last active April 11, 2023 06:59
How to configure VRack in OVH?

FIX: MigrationsAreLockedError: Migration lock was never released or currently a migration is running.

mysql

use db_name;  
UPDATE migrations_lock set locked=0 where lock_key='km01';
@anhtran
anhtran / bs-message.js
Created July 23, 2019 08:22
Implement Bootstrap 4 Toast without injecting HTML
/* Author: Anh Tran <anhtran.net> */
/* Date: 2019-07-23 14:36 */
function showMessage (content, style, title, subTitle, delay=2000) {
const id_ = Date.now()
const body = $('body')
let wrapper = $('#id_message_wrapper')
if (!content) {
return
}
@anhtran
anhtran / ctrl.sh
Last active July 26, 2019 09:03
Sample of settings for running django service inside python-supervisor (standalone)
#!/bin/sh
supervisorctl -c /path/to/service/supervisord.ini $@
@anhtran
anhtran / convert_to_webp.py
Created June 13, 2019 05:09
Building, convert images to WebP in a single command
import glob
import os
import click
from webptools import webplib as webp
@click.group()
def cli():
pass
@anhtran
anhtran / utils.py
Last active June 1, 2019 10:00
An util for Django to download image from url (support WebP)
import os
import re
import secrets
from io import BytesIO
from pprint import pprint
from urllib.parse import urlsplit
import arrow
import requests
import user_agents
@anhtran
anhtran / gulpfile.js
Created June 1, 2019 02:39
Reload Django development server using Browsersync and Gulp 4
const browserSync = require('browser-sync').create();
const spawn = require('child_process').spawn;
function reload(done) {
browserSync.reload();
done();
}
gulp.task('buildCss', gulp.series(
// your functions here
@anhtran
anhtran / update_geoip_city.sh
Last active May 13, 2019 07:44
Script to update GeoLite2-City database for detect location by IP address
#!/usr/bin/env bash
#prg="wget --quiet"
prg="wget"
# currently it will create folder `geoip` in parent of this script path
# you could modify to absolute path to fix as your wish
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
geolite_path="$(dirname "$DIR")/geoip"
mkdir -p ${geolite_path}