Skip to content

Instantly share code, notes, and snippets.

View lyhcode's full-sized avatar

Kyle Lin lyhcode

View GitHub Profile
@lyhcode
lyhcode / web.xml
Created February 14, 2012 12:45
CharacterEncodingFilter
<filter>
<filter-name>encodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<init-param>
<param-name>forceEncoding</param-name>
<param-value>true</param-value>
@lyhcode
lyhcode / build.gradle
Created February 15, 2012 02:25
Gradle + Jetty + AJP (Ajp13SocketConnector)
apply plugin: 'jetty'
apply plugin: 'java'
apply plugin: 'groovy'
repositories {
mavenCentral()
}
dependencies {
providedRuntime 'org.mortbay.jetty:jetty-ajp:6.1.26'
@lyhcode
lyhcode / eclipse.ini
Created February 20, 2012 09:07
eclipse.ini 3.7.1
-client
-startup
../../../plugins/org.eclipse.equinox.launcher_1.2.0.v20110502.jar
--launcher.library
../../../plugins/org.eclipse.equinox.launcher.cocoa.macosx.x86_64_1.1.100.v20110502
-product
org.eclipse.epp.package.java.product
--launcher.defaultAction
openFile
-showsplash
@lyhcode
lyhcode / htmlbuilder.groovy
Created February 21, 2012 10:17
Groovy output HTML with MarkupBuilder
import groovy.xml.MarkupBuilder
def sb = new StringWriter()
def html = new MarkupBuilder(sb)
html.doubleQuotes = true
html.expandEmptyElements = true
html.omitEmptyAttributes = false
html.omitNullAttributes = false
html.html {
@lyhcode
lyhcode / mongotest.js
Created February 29, 2012 08:58
MongoDB 1m data insert test
db.foo.remove();
var rnd = function() {
return Math.floor(Math.random() * 1000 + 100).toString();
}
var date1 = new Date();
for (var i=0; i<1000000; i++) {
var row1 = {key: rnd(), value: 'data'+rnd()}
db.foo.save(row1);
}
print(new Date().getTime()-date1.getTime());
@lyhcode
lyhcode / svnant.groovy
Created March 23, 2012 06:58
groovy + svnant + svnkit
@GrabConfig(systemClassLoader=true)
@GrabResolver(name='monkproject', root='http://www.monkproject.org/maven2/')
@Grab(group='org.tmatesoft.svnkit', module='svnkit', version='1.3.5')
@Grab(group='org.tmatesoft.svnkit', module='svnkit-javahl', version='1.3.5')
@Grab(group='org.monkproject', module='svnant', version='1.1.0-rc2')
@Grab(group='org.monkproject', module='svnClientAdapter', version='1.1.0-rc2')
def ant = new AntBuilder()
ant.typedef(resource: 'org/tigris/subversion/svnant/svnantlib.xml')
ant.svn(username: 'guest', password: 'password') {
@lyhcode
lyhcode / zlib-demo.js
Created April 2, 2012 10:38
Node.js + Gzip/Deflate Compression
var zlib = require('zlib');
var compress = function(req, res, result) {
var acceptEncoding = req.headers['accept-encoding'];
if (!acceptEncoding) { acceptEncoding = ''; }
if (acceptEncoding.match(/\bdeflate\b/)) {
zlib.deflate(result, function(err, result) {
if (!err) {
res.writeHead(200, { 'content-encoding': 'deflate' });
res.send(result);
@lyhcode
lyhcode / Ux.InputTextMask.js
Created April 29, 2012 01:55 — forked from loiane/Ux.InputTextMask.js
Ux.InputTextMask for ExtJS4
/**
* InputTextMask script used for mask/regexp operations.
* Mask Individual Character Usage:
* 9 - designates only numeric values
* L - designates only uppercase letter values
* l - designates only lowercase letter values
* A - designates only alphanumeric values
* X - denotes that a custom client script regular expression is specified</li>
* All other characters are assumed to be "special" characters used to mask the input component.
* Example 1:
@lyhcode
lyhcode / app.js
Created April 30, 2012 10:29
mongoskin + connect-mongodb
var mongo = require('mongoskin')
, db = mongo.db('localhost/collection')
, mongoStore = require('connect-mongodb');
//...
db.open(function(err, db) {
app.configure(function() {
//...
app.use(express.cookieParser());
@lyhcode
lyhcode / app.js
Created May 12, 2012 07:59
Express.js + connect-cache
// refer http://www.bishen.org/content/35579925757
var express = require('express')
, ejs = require('ejs')
, routes= require('./routes')
, cache = require('connect-cache');
var app = module.exports = express.createServer(
cache({rules: [
{regex: /.*/, ttl: 21600000},