Skip to content

Instantly share code, notes, and snippets.

View TanAlex's full-sized avatar

Tingli Tan TanAlex

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

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 / 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;
@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 / 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;
}