Skip to content

Instantly share code, notes, and snippets.

View yuezk's full-sized avatar
💭
I may be slow to respond.

Kevin Yue yuezk

💭
I may be slow to respond.
View GitHub Profile
@yuezk
yuezk / build-openconnect.sh
Last active August 9, 2024 20:51
Build Openconnect from Source Code on Ubuntu 18.04
# Install dependencies
sudo apt install \
build-essential gettext autoconf automake libproxy-dev \
libxml2-dev libtool vpnc-scripts pkg-config zlib1g-dev \
libp11-kit-dev libp11-dev libssl-dev
# Build
cd openconnect
./autogen.sh
./configure
@yuezk
yuezk / numeric_literal_regexp.js
Last active August 7, 2019 05:22
[ECMAScript] Regexp to match the JavaScript numberic literal value (Supports number seprator)
// Reference: http://www.ecma-international.org/ecma-262/10.0/index.html#prod-NumericLiteral
(function () {
const regexp = /^[+-]?(?:0b[01]+|0o[0-7]+|0x[0-9a-f]+|(?:(?:(?:0|[1-9]\d*)\.\d*|\.\d+|(?:0|[1-9]\d*))(?:e[+-]?\d+)?))$/i;
// RegExp below also supports number spearator: https://github.com/tc39/proposal-numeric-separator
// const regexp = /^[+-]?(?:0b[01](_?[01])*|0o[0-7](_?[0-7])*|0x[0-9a-f](_?[0-9a-f])*|(?:(?:(?:0|[1-9](_?\d(_?\d)*)?)\.(\d(_?\d)*)?|\.\d(_?\d)*|(?:0|[1-9](_?\d(_?\d)*)?))(?:e[+-]?\d(_?\d)*)?))$/i;
const testCases = [
'0.', '0.E1', '0.e-1','0.e0', '0.1', '0.12', '0.12e2', '0.12e-2','0.12E0','0.0e1', '0.0e-1', '0.0E0',
'1.', '1.E1', '1.e-1','1.e0', '1.1', '1.12', '1.12e2', '1.12e-2','1.12E0','1.0e1', '1.0e-1', '1.0E0',
'1_0.', '1_0_0.', '1_0.0_1_2', '1_0_0', '100_000', '1e1_2', '1e+12_0', '.1_2_3', '.000_111', '10_1.1_2_3', '0.000_111', '0e0', '1_2e10',
@yuezk
yuezk / browserify-postcss.js
Created March 5, 2016 14:07
Transform CSS files use PostCSS
var through = require('through2');
var postcss = require('postcss');
function postcssTransform(filename, options) {
if (!/\.css$/.test(filename)) {
return through();
}
if (typeof options === 'undefined' || options === null) {
options = {};
@yuezk
yuezk / var.www.sh
Created December 6, 2015 02:44
/var/www 的权限配置
# https://help.ubuntu.com/12.04/serverguide/httpd.html#http-directory-permissions
sudo chgrp -R webmasters /var/www
sudo find /var/www -type d -exec chmod g=rwxs "{}" \;
sudo find /var/www -type f -exec chmod g=rws "{}" \;
@yuezk
yuezk / chinese-chars.js
Created November 26, 2015 10:12
中文正则表达式表示方法
var reg = /[\u4e00-\u9fa5]/;
@yuezk
yuezk / format-detection.html
Created November 10, 2015 09:16
HTML format-detection meta tag
<meta name="format-detection" content="telephone=no">
<meta name="format-detection" content="date=no">
<meta name="format-detection" content="address=no">
<meta name="format-detection" content="email=no">
@yuezk
yuezk / 1px.css
Created November 2, 2015 07:57
PostCSS one pixel border mixin
/**
* use the postcss-mixins plugin
*
* Usage:
* .item {
* position: relative;
* }
* .item:before {
* content: '';
* @mixin 1px top, #ddd;
@yuezk
yuezk / mobile-reg.js
Created October 16, 2015 13:22
中国内地手机号(联通,移动,电信)正则表达式
// 参考维基百科 - 中国内地移动终端通讯号码 http://t.cn/Ryr1Emc
var reg = /^(13[0-9]|15[0-35-9]|18[0-9]|17[06-8]|14[57])\d{8}$/
@yuezk
yuezk / cc-thqs-encrypt.js
Created October 14, 2015 02:23
按照 CC 文档中描述的 THQS 加密算法对提交的数据进行加密处理
// 依赖 JS 的 MD5 库 https://blueimp.github.io/JavaScript-MD5/js/md5.js
// 按照 CC 文档中描述的 THQS 加密算法对提交的数据进行加密处理
// 具体的加密算法在 http://t.cn/Ry3Hs7W 的附录部分
function encrypt(data) {
// 1. 将键值对按照 key 的升序排序
var qs = data.sort(function (a, b) {
return a.name > b.name;
}).map(function (item) {
return item.name + '=' + encodeURIComponent(item.value);
@yuezk
yuezk / random-color.js
Created August 24, 2015 05:36
random color
// reference: http://llllll.li/randomColor/
function randomColor() {
return '#' + Math.floor(Math.random()*16777215).toString(16);
}