Skip to content

Instantly share code, notes, and snippets.

View mindon's full-sized avatar
🙃
hx/ui, coding with ts/js, zig, golang and sometimes qt...

Mindon Feng mindon

🙃
hx/ui, coding with ts/js, zig, golang and sometimes qt...
View GitHub Profile
@mindon
mindon / appup.js
Created July 29, 2015 07:02
launch a mobile app from mobile web or inside wechat, or goes to app website to download
;// to launch mobile app
var insideWeChat = typeof window.WeixinJSBridge == "object";
var isMobileDevice = 'ontouchstart' in window || /Android|webOS|iPhone|iPad|iPod|BlackBerry|BB10|IEMobile|Opera Mini/i.test(navigator.userAgent);
;(function(document, window){ //
var ua = navigator.userAgent;
var tid, callfn, duration = 1300;
function bind(el, en, fn, useCapture){
el.addEventListener ? el.addEventListener(en, fn, useCapture||false): (el.attachEvent ? el.attachEvent('on'+en, fn) : el['on'+en]=fn);
}
function unbind(el, en, fn, useCapture){
@mindon
mindon / xxtea.min.js
Created January 27, 2016 12:13
Minimized XXTea JavaScript
!function(r,k){"use strict";var N=1023,N0=56320,N6=65536,z={f:Math.floor,s:"string",r:"Character outside valid Unicode range: 0x",e:"Bad UTF-8 encoding 0x"},q=function(c,i,j){if(!i&&!j)throw new Error(c||"Unfinished UTF-8 octet sequence");return j?c.subarray(i,j):(i==1?(0===c||null===c||0===c.length):(i==2?c.toString(16):(i>2&&i<6?new [Uint8Array,Uint16Array,Uint32Array][i-3](c):String.fromCharCode.apply(String,c))))};function e(r,e){var n=r.length,t=n<<2;if(e){var a=r[n-1];if(t-=4,t-3>a||a>t)return null;t=a}for(var o=q(t,3),i=0;t>i;++i)o[i]=r[i>>>2]>>>((3&i)<<3);return o}function n(r,e){var n=r.length,t=n>>>2;0!==(3&n)&&++t;var a;e?(a=q(t+1,5),a[t]=n):a=q(t,5);for(var o=0;n>o;++o)a[o>>2]|=r[o]<<((3&o)<<3);return a}function t(r,e,n,t,a,o){return(n>>>5^e<<2)+(e>>>3^n<<4)^(r^e)+(o[3&t^a]^n)}function a(r){if(r.length<16){var e=q(16,3);e.set(r),r=e}return r}function o(r,e){var n,a,o,i,c,f,u=r.length,s=u-1;for(a=r[s],o=0,f=0|z.f(6+52/u);f>0;--f){for(o+=y,i=o>>>2&3,c=0;s>c;++c)n=r[c+1],a=r[c]+=t(o,n,a,c,i,e);n=r[0]
/* download ppt pdf from dtcc 2017
* Author: Mindon <mindon@gmail.com> http://mindon.github.io
*/
package main
import (
"bufio"
"fmt"
"io/ioutil"
"net/http"
@mindon
mindon / gohtml-cli.go
Created June 26, 2017 01:33
gohtml-cli command tool to format html files using yosssi's gohtml
// gohtml-cli command tool to format html files using yosssi's gohtml
// [NOTICE] some issues are in yosssi's gohtml - which has not updated for years <https://github.com/yosssi/gohtml/issues>
// DO MAKE BACKUPs before you trying this
// it's recommended using js-beautify instead: <https://github.com/beautify-web/js-beautify>
// Jun. 25, 2017 - Mindon <mindon@gmail.com>
package main
import (
"fmt"
@mindon
mindon / the-monty-hall-problem.js
Created July 13, 2017 02:12
The Monty Hall Problem 蒙提霍尔问题验证
// The Monty Hall problem
// 蒙提霍尔问题
var posibilities = [
['C', 'A', 'B'],
['C', 'B', 'A'],
['B', 'C', 'A'],
['B', 'A', 'C'],
['A', 'B', 'C'],
['A', 'C', 'B'],
];// Apple, Banana, Car
@mindon
mindon / track.js
Last active July 25, 2017 05:06
Audio/Video Track Feature
// track feature
// author: Mindon <mindon@gmail.com>
// updated: July 13, 2017. Shenzhen, Guangdong, China P.R.
// track.bind(audio-element, cues)
// track.bind(audio-element, cues, track-bubble-container-element)
// cues-array = track.get(cues-data or cues-dataUrl, cb) // cb = (cues)=>{}
// supports VTT and lyric format
var track = (function(){
// ------ track namespace begin
@mindon
mindon / bisect.js
Last active August 29, 2017 07:39
javascript bisect
// javascript bisect
// const z=[0, 20, 50, 80, 110, 141, 173, 204, 235, 266, 297, 327]; console.log(bisect(25, z));
function bisect(v,d){let i=n=0,j=d.length;if(j==1){return 0}n=Math.floor(j/2);if(d[n]>v){j=n}else{i=n}return i+bisect(v,d.slice(i,j))}
@mindon
mindon / ai2svg.go
Created March 9, 2018 06:36
Convert simple ai Illustrator file to svg format
// CONVERT simple .ai (adobe illustrator) file to svg format
// http://www.fileformat.info/format/ai/egff.htm
//
package main
import (
"fmt"
"io/ioutil"
"math"
@mindon
mindon / heart.scad
Created April 17, 2018 09:15
Heart Shape in OpenSCAD format
// simple heart shape for OpenSCAD
// author: Mindon <mindon@gmail.com>
// from https://mindon.github.io/
heart(width = 160, height = 160);
module heart(width, height = 0) { // 0 = auto height
w = width; h = height;
r = 2 * w/7; // top circle radius
i = r/4.0; // top circle intersect-part width
@mindon
mindon / request_testing_helper.go
Last active May 17, 2018 10:39
A helper func for http request testing
// http request testing helper
// author: Mindon Feng <mindon@gmail.com>
// site: https://mindon.github.io
package mindon
import (
"bytes"
"errors"
"io/ioutil"
"net/http"