Skip to content

Instantly share code, notes, and snippets.

@KevinWang15
KevinWang15 / class_decorator.ts
Created April 19, 2017 05:08 — forked from remojansen/class_decorator.ts
TypeScript Decorators Examples
function logClass(target: any) {
// save a reference to the original constructor
var original = target;
// a utility function to generate instances of a class
function construct(constructor, args) {
var c : any = function () {
return constructor.apply(this, args);
}
@KevinWang15
KevinWang15 / tr.sh
Created November 8, 2017 04:47
tr 2.84 install script
#!/usr/bin/env bash
# 以root权限运行,只支持Ubuntu 14和16
echo 请设置web用户名和密码,如果输错了,按Ctrl+C结束本脚本并重来
echo 输入web用户名:
read webuser
echo 输入web密码:
read webpass
@KevinWang15
KevinWang15 / fix.sh
Created November 10, 2017 09:01
Fix .bin PATH for npm global modules
export npm_path=$(npm config get prefix)
export PATH=$PATH:$npm_path/bin
@KevinWang15
KevinWang15 / JSCalendar.js
Last active March 4, 2018 08:21
JS Calendar - super simple & customizable, written in the form of angularjs, with calendar layout algorithm / "show today".
// adapted from https://stackoverflow.com/a/13786155/6247478
var cal_days_in_month = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
var month_names = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
var day_names = ['SUN', 'MON', 'TUE', 'WED', 'THU', 'FRI', 'SAT'];
angular.module('demo')
.directive('calendar', function () {
return {
restrict: 'E',
@KevinWang15
KevinWang15 / after-build-cache-bust.js
Created March 4, 2018 16:37
General purpose cache buster ( after build ), append checksum to <script src="..."> and <link ref="...">, cache bust js & css in any build system
#!/usr/bin/env node
const INDEX_FILE_NAME = './www/index.html';
const fs = require('fs');
const path = require('path');
const crypto = require('crypto');
function checksum(str, algorithm, encoding) {
return crypto
.createHash(algorithm || 'md5')
.update(str, 'utf8')
@KevinWang15
KevinWang15 / config.js
Last active April 1, 2018 01:58
Upload JS/CSS to qiniu cdn for production in index.html, cache bust according to checksum
module.exports = {
qiniu_ak: '',
qiniu_sk: '',
qiniu_bucket: '',
qiniu_domain:'http://cdn.example.com'
};
<?php
/**
* 如果$_REQUEST中出现可能导致sql注入的字符,就返回400。
* 需要在程序一开始的时候就运行。
*
* 注意:本方法只对默认的html表单类型(application/x-www-form-urlencoded)有效
* 如果有文件上传类型的(enctype="multipart/form-data"),则不能执行本方法
*/
function guardAgainstBadCharactersInRequest()
@KevinWang15
KevinWang15 / mysql.sh
Created April 23, 2018 16:42
backup mysql
#!/bin/bash
# crontab:
# 30 */8 * * * /root/backup/mysql.sh
databases=(db1 db2 db3)
basepath='/root/backup/mysql/'
@KevinWang15
KevinWang15 / .zshrc
Created January 26, 2020 05:32
aliases
alias setp="export http_proxy=127.0.0.1:1087 && export https_proxy=127.0.0.1:1087"
alias unsetp="export http_proxy= && export https_proxy="
@KevinWang15
KevinWang15 / glog.go
Created December 30, 2020 07:26
glog / klog with cobra
package main
import (
"flag"
"fmt"
"github.com/golang/glog"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
)