Skip to content

Instantly share code, notes, and snippets.

View liuxd's full-sized avatar
🗿
Hi, there.

Allen Liu liuxd

🗿
Hi, there.
  • Tax Traders
  • Auckland, New Zealand
View GitHub Profile
@liuxd
liuxd / demo.php
Last active June 20, 2024 23:13
[PHP token generator]
<?php
$token = bin2hex(random_bytes(16));
@liuxd
liuxd / demo.js
Created July 19, 2021 01:04
[Detect Back Button Event]
if (performance.getEntriesByType("navigation")[0].type === 'back_forward') {
// do something.
}
@liuxd
liuxd / a.js
Created May 20, 2021 04:03
[Reverse the elements in a target element] #jQuery
$.fn.reverseChildren = function() {
return this.each(function(){
var $this = $(this);
$this.children().each(function(){ $this.prepend(this) });
});
};
$('#target').reverseChildren();
@liuxd
liuxd / demo.html
Created February 25, 2020 08:30
[Bind all <a> to ask whether to go or not with a confirm popup] #JavaScript
<!DOCTYPE html>
<html>
<body>
<a href="https://www.google.com/">Google</a>
<a href="https://www.youtube.com/">Youtube</a>
<script>
function clickRedirectHandler(e) {
@liuxd
liuxd / demo.py
Created February 12, 2020 02:56
[Ignore BOM while reading a file with Python 3]
f = open('file', mode='r', encoding='utf-8-sig')
f.read()
# set encoding='utf-8-sig' is the key point.
@liuxd
liuxd / main.sql
Last active December 4, 2019 22:23
[Get a column list of a table in SQLite] #sqlite
PRAGMA table_info(tablename);
@liuxd
liuxd / convert_mdb_to_sqlite.py
Last active October 26, 2023 08:46
[Convert .mdb to .sqlite in python on Mac] #MS Access
# It requires mdbtools.
from subprocess import Popen, PIPE
import subprocess
import sqlite3
def run_cmd(cmd):
p = Popen(cmd, stdout=PIPE, stderr=PIPE)
output, error = p.communicate()
output = str(output, 'utf-8')
@liuxd
liuxd / code.js
Created October 25, 2019 02:54
[convert number to dollar]
function show_dollar(num) {
return '$' + num.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, '$1,')
}
@liuxd
liuxd / main.md
Last active October 16, 2019 21:40
[Set Full Screen in Chrome / Safari on Mac (without bookmark or url)] #Mac

Safari :全屏之后,“显示”菜单中去掉“始终在全屏中显示工具栏”的对勾。

Chrome :全屏之后,“视图”菜单中选择“采用全屏模式时隐藏工具栏”。

@liuxd
liuxd / a.md
Created July 23, 2019 04:10
[Find Slack API Token]

click the menu of Install App on the left side navigations.