Skip to content

Instantly share code, notes, and snippets.

View TanAlex's full-sized avatar

Tingli Tan TanAlex

View GitHub Profile
@TanAlex
TanAlex / datetime_functions.js
Last active November 5, 2017 18:43
javascript handle local and UTC time and string conversion
function convert_to_utc (today){
var localoffset = -(today.getTimezoneOffset()/60);
//var destoffset = -4;
//var offset = destoffset-localoffset;
var offset = localoffset;
var d = new Date( today.getTime() + offset * 3600 * 1000);
return d;
}
@TanAlex
TanAlex / crypto_functions.js
Created November 30, 2017 17:10
functions related to basic hash, password, random number
'use strict';
var crypto = require('crypto');
/**
 * generates random string of characters i.e salt
 * @function
 * @param {number} length - Length of the random string.
 */
var genRandomString = function(length){
return crypto.randomBytes(Math.ceil(length/2))
@TanAlex
TanAlex / eventemitter.js
Created August 27, 2018 15:02 — forked from mudge/eventemitter.js
A very simple EventEmitter in pure JavaScript (suitable for both node.js and browsers).
/* Polyfill indexOf. */
var indexOf;
if (typeof Array.prototype.indexOf === 'function') {
indexOf = function (haystack, needle) {
return haystack.indexOf(needle);
};
} else {
indexOf = function (haystack, needle) {
var i = 0, length = haystack.length, idx = -1, found = false;

install kubernetes 1.6 on centos 7.3

Install kubelet, kubeadm, docker, kubectl and kubernetes-cni

1. Install Yum Repo

cat <<EOF > /etc/yum.repos.d/kubernetes.repo
[kubernetes]
name=Kubernetes
baseurl=http://yum.kubernetes.io/repos/kubernetes-el7-x86_64
@TanAlex
TanAlex / python_exceptions.py
Created May 31, 2019 06:06
[python exception]Python exceptions gists #exception
# https://github.com/kennethreitz/requests/blob/master/requests/exceptions.py
class RequestException(IOError):
"""There was an ambiguous exception that occurred while handling your
request.
"""
def __init__(self, *args, **kwargs):
"""Initialize RequestException with `request` and `response` objects."""
response = kwargs.pop('response', None)
self.response = response
@TanAlex
TanAlex / request_structures.py
Created May 31, 2019 06:21
[LookupDict, CaseInsensitiveDict]Different kinds of dictionaries like CaseInsensitiveDicts #dictionary
"""
requests.structures
~~~~~~~~~~~~~~~~~~~
Data structures that power Requests.
"""
from .compat import OrderedDict, Mapping, MutableMapping
class CaseInsensitiveDict(MutableMapping):
@TanAlex
TanAlex / chunked_request.go
Last active June 2, 2019 16:32
[chunked_request go client]chunked_request #http
package main
import (
"fmt"
"io"
"io/ioutil"
"net/url"
"github.com/benburkert/http"
//"net/http"
@TanAlex
TanAlex / bus.js
Created June 7, 2019 00:18
[vue plugin sample]Create vm.$responsive to capture windows size #vue
//https://github.com/vuejs/vue-cli/blob/dev/packages/%40vue/cli-ui/src/util/bus.js
import Vue from 'vue'
const bus = new Vue()
export default {
install (Vue) {
Vue.prototype.$bus = (type, ...args) => {
bus.$emit(type, ...args)
}
@TanAlex
TanAlex / beforeEach.js
Created June 7, 2019 00:35
[vue router snippet]vue router related #vue #vue_router
/*
* to.matched is array for all the route it matches, use m.meta to get flags
* remember to use next() at the end !
* next({name: 'new-route'}) to redirect
*/
router.beforeEach(async (to, from, next) => {
if (to.matched.some(m => m.meta.needProject)) {
const result = await apolloClient.query({
query: PROJECT_CURRENT,
@TanAlex
TanAlex / console_log.js
Created June 7, 2019 00:58
[js console.log tricks]console.log #console #tricks
console.log('%cAn error occured', 'background: red; color: white; padding: 4px; border-radius: 4px;font-weight: bold;')
console.log("%cStr1" + "%cStr2", "Css-for-str1", "Css-for-str2")