Skip to content

Instantly share code, notes, and snippets.

View wangpin34's full-sized avatar
🎯
Focusing

Penn wangpin34

🎯
Focusing
View GitHub Profile
@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 / 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 / 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

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 / 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'
}
@wangpin34
wangpin34 / react-json-view-thinking.md
Last active December 13, 2018 06:23
react json viewer

app.js

import React, { Component } from 'react';
import './app.scss';

const Bracket = ({b}) => <span className="bracket">&nbsp;{b}&nbsp;</span>;
const ListWrapper = ({children}) => <section>{children}</section>;
const MapWrapper = ({children}) => <section>{children}</section>;

const NodeKey = ({k}) => (<label>{'"' + k + '"'}:</label>);
@wangpin34
wangpin34 / index.js
Created May 10, 2019 06:23
only allow input numbers
function handleKeydown(e) {
if (e.shiftKey) {
if (e.which !== 9) {
e.preventDefault()
}
}
if (e.which > 57) {
e.preventDefault()
}
if (e.which === 32) {
.env.dev
.env.qa
.env.stg
.env.prod
@wangpin34
wangpin34 / env.js
Last active November 16, 2020 02:17
load env variables of different stacks
const dotenv = require('dotenv')
const path = require('path')
const fs = require('fs')
function load() {
if (process.env.stack) {
return dotenv.config({ path: path.join(__dirname, `.env.${process.env.stack}`) })
}
return dotenv.config()
}
@wangpin34
wangpin34 / main.go
Last active August 20, 2019 02:57
golang list: general helper functions
/*
*
* Demo: https://repl.it/@wangpin34/array-utils
*/
/*
* Filter elements which pass the test function
*/
func filter(in interface{}, testFunc func(interface{}) bool) *[]interface{} {
b, _ := json.Marshal(in)