Skip to content

Instantly share code, notes, and snippets.

View wangpin34's full-sized avatar
🎯
Focusing

Penn wangpin34

🎯
Focusing
View GitHub Profile
@wangpin34
wangpin34 / random.js
Created August 28, 2018 09:00
random numbers
function int (min, max, limit) {
if (typeof max !== 'number' || typeof min !== 'number') {
throw 'max or min is not a integer';
}
if (typeof limit !== 'number' || limit <= 0) {
throw 'limit is not a integer or less than zero'
}
if (min >= max) {
throw 'min must not greater than max'
}

Disable HTML Form Input Autocomplete and Autofill

  1. Add autocomplete="off" onto <form> element;
  2. Add hidden <input> with autocomplete="false" as a first children element of the form.
<form autocomplete="off" method="post" action="">
    <input autocomplete="false" name="hidden" type="text" style="display:none;">
    ...
@wangpin34
wangpin34 / rest_quick_reference.md
Last active August 10, 2018 07:49 — forked from odan/rest_quick_reference.md
REST, RESTful API Quick Reference

REST, RESTful API Quick Reference

A good API is not just easy to use but also hard to misuse.

Resources

  • Version your API
    • Path: /v1/users
    • Subdomain: api.v1.example.com/users
@wangpin34
wangpin34 / jwt_demo.go
Last active December 22, 2017 08:58
Jwt simple demo using github.com/dgrijalva/jwt-go
package main
import (
"github.com/dgrijalva/jwt-go"
"fmt"
"time"
"errors"
)
var secret = []byte("my_secret_key")
@wangpin34
wangpin34 / ajax.js
Last active November 9, 2017 08:52
small ajax function
var ajax = http = function (method, path, data, onsuccess, onfailed, oncomplete) {
var xhttp;
method = method.toUpperCase();
if (window.XMLHttpRequest) {
xhttp = new XMLHttpRequest();
} else {
// code for old IE browsers
xhttp = new ActiveXObject("Microsoft.XMLHTTP");
@wangpin34
wangpin34 / Query.java
Created May 5, 2017 10:21
Java baidu image
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.net.InetSocketAddress;
import java.net.Proxy;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLEncoder;
import java.util.HashMap;
@wangpin34
wangpin34 / urlUtil.js
Last active April 7, 2017 09:48
Url parameter serialized and parsed
/**
* @param jsonObj {Object} Sample: { name: 'wangpin', job: 'engineer' }
* @return params {String} Sample: name=wangpin&job=engineer
*/
function stringifyParams(jsonObj) {
if(typeof jsonObj !== 'object' || !(jsonObj instanceof Object)){
throw new Error('Not a valid json object');
}
var result = [];
@wangpin34
wangpin34 / Q.js
Last active March 31, 2017 02:46
manage event listener
/**
* Lib Q
* For easliy manage event listener
* v0.0.2
*/
(function(w){
function Q(){
var elements = [];
@wangpin34
wangpin34 / winLocale.js
Created March 17, 2017 02:18
retrieve locale and language info of windows os
const spawn = require('child_process').spawn;
const locales = spawn('systeminfo.exe', []);
const localeReg = /([a-z]+-[a-z]+);/ig;
let result = "";
locales.stdout.on('data', (data) => {
if(data && data.length > 0){
result += data;
@wangpin34
wangpin34 / browser-features.js
Last active March 2, 2017 05:44
Turn off these browser features which is not proper for your application like text selection, drag then open the file etc.
/*
* Disable text selection when double click or drag cursor
* @dom html element
*/
function disableTextSelection(dom){
if(dom.addEventListener){
dom.addEventListener('mousedown', function(event){
event.stopPropagation();
event.preventDefault();
})