A good API is not just easy to use but also hard to misuse.
- Version your API
- Path: /v1/users
- Subdomain: api.v1.example.com/users
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"); |
package main | |
import ( | |
"github.com/dgrijalva/jwt-go" | |
"fmt" | |
"time" | |
"errors" | |
) | |
var secret = []byte("my_secret_key") |
autocomplete="off"
onto <form>
element;<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;">
...
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' | |
} |
app.js
import React, { Component } from 'react';
import './app.scss';
const Bracket = ({b}) => <span className="bracket"> {b} </span>;
const ListWrapper = ({children}) => <section>{children}</section>;
const MapWrapper = ({children}) => <section>{children}</section>;
const NodeKey = ({k}) => (<label>{'"' + k + '"'}:</label>);
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 |
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() | |
} |
/* | |
* | |
* 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) |