Skip to content

Instantly share code, notes, and snippets.

View greycode's full-sized avatar
💭
I may be slow to respond.

Calvin Yu greycode

💭
I may be slow to respond.
View GitHub Profile
@greycode
greycode / BatchMgtCtrl.java
Created August 23, 2014 06:12
quartz 手动处理job
package pkgName;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@greycode
greycode / SpringContextUtil.JAVA
Created August 23, 2014 06:07
手动获取bean
package pckName
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
//
// 使用 SpringContextUtil.getBean(SchedulerFactoryBean.class);
// <bean class="pckName.SpringContextUtil" scope="singleton"></bean>
@greycode
greycode / encodeHtml.JS
Created August 12, 2014 02:10
javascript 对 HTML 做转义处理
//$package("js.lang"); // 没有包管理时,也可简单写成 js = {lang:{}};
js = {lang:{}};
js.lang.String = function(){
this.REGX_HTML_ENCODE = /"|&|'|<|>|[\x00-\x20]|[\x7F-\xFF]|[\u0100-\u2700]/g;
this.REGX_HTML_DECODE = /&\w+;|&#(\d+);/g;
this.REGX_TRIM = /(^\s*)|(\s*$)/g;
@greycode
greycode / autoheight.JS
Created July 14, 2014 02:28
根据窗口大小自动改变元素高度
/**
* 将具有 autoheight 属性的 div 元素设置为自动高度
* 用法:给需要的 div 元素添加 autoheight 属性,如:<div autoheight> ... </div>
* 可以修改选择符,如写为 ".autoheight" 或是其它的以匹配需要的元素。
*/
$(function () {
var _jahDivs = $("#textMsg");
if (_jahDivs.length > 0) {
_jahDivs.css("overflow", "auto");
$(window).resize(function () {
@greycode
greycode / wordCount.js
Last active August 29, 2015 14:02
微博字数统计
var getLength = (function() {
var trim = function(h) {
try {
return h.replace(/^\s+|\s+$/g, "")
} catch (j) {
return h
}
}
var byteLength = function(b) {
if (typeof b == "undefined") {
@greycode
greycode / dateFormat.js
Created June 19, 2014 06:36
javascript date to string
// 对Date的扩展,将 Date 转化为指定格式的String
// 月(M)、日(d)、小时(h)、分(m)、秒(s)、季度(q) 可以用 1-2 个占位符,
// 年(y)可以用 1-4 个占位符,毫秒(S)只能用 1 个占位符(是 1-3 位的数字)
// 例子:
// (new Date()).Format("yyyy-MM-dd hh:mm:ss.S") ==> 2006-07-02 08:09:04.423
// (new Date()).Format("yyyy-M-d h:m:s.S") ==> 2006-7-2 8:9:4.18
Date.prototype.Format = function (fmt) { //author: meizz
var o = {
"M+": this.getMonth() + 1, // 月份
"d+": this.getDate(), // 日
@greycode
greycode / CodeWar-kyu.js
Last active August 29, 2015 13:57
CodeWar 代码练习
/**
Implement pluck, which takes an array of objects and a property name,
and returns an array containing the named property of each object.
For example:
pluck([{a:1}, {a:2}], 'a') // -> [1,2]
If an object is missing the property, you should just leave it as undefined in the output array.
*/
// mine
@greycode
greycode / printCallStack.js
Created February 13, 2014 09:25
打印 JavaScript 函数调用堆栈
/*
* 打印 JavaScript 函数调用堆栈
*/
function printCallStack() {
var i = 0;
var fun = arguments.callee;
do {
fun = fun.arguments.callee.caller;
console.log(++i + ': ' + fun);
} while (fun);
@greycode
greycode / nthFibo.js
Created February 10, 2014 04:55
计算第N个斐波那契数
function nthFibo(n) {
var Phi = (1 + Math.sqrt(5))/ 2;
return Math.round ((Math.pow(Phi, (n-1)) - Math.pow(Phi*-1, (n-1)*-1)) / Math.sqrt(5))
}
@greycode
greycode / sshd.go
Created June 26, 2013 09:40 — forked from nictuku/sshd.go
package main
import (
"fmt"
"io"
"io/ioutil"
"log"
"code.google.com/p/go.crypto/ssh"
"code.google.com/p/go.crypto/ssh/terminal"