Skip to content

Instantly share code, notes, and snippets.

View xcooper's full-sized avatar

Cooper xcooper

  • Commscope
  • Taiwan
View GitHub Profile
@xcooper
xcooper / AbstractDumpI18nAction.java
Created July 29, 2013 09:58
This class is intentional to be extend to get all i18n key-value pairs using Map
package com.gss.tds.dc.struts2.action;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.ResourceBundle;
@xcooper
xcooper / grid-submit-json.js
Created August 12, 2013 09:55
overwrite jqGrid ajax mechanism, send json to backend instead of submitting a form. datatype should be "json" "xml" "script" postData is data you wanna send ajaxGridOptions is ajax configuration of jQuery serializeGridData is a function having only one argument which is postData you provided, it should return a Serialized data(e.g. String)
self.grid.jqGrid("setGridParam", {
serializeGridData: self.serializeData,
url: self.executionUrl,
datatype: "json",
ajaxGridOptions: {
cache: false,
contentType: "application/json",
processData: false,
type: "POST"
},
@xcooper
xcooper / install-guard-livereload.sh
Created August 20, 2013 02:53
install guard livereload on ubuntu 13.04
sudo apt-get install ruby-dev
sudo gem install rdoc
sudo gem install guard
sudo gem install guard-livereload
@xcooper
xcooper / backbone-jqgrid-reader.js
Created August 23, 2013 05:01
new this function to 'datatype' of jqgrid options, this will sync between Backbone collection and jqGrid
var BackboneJqGridReader = function(colleciton, grid) {
return function(postdata) {
var submitData = _.extend({}, postdata);
Backbone.sync("read", colleciton, {
attrs: submitData,
cache: false,
contentType: "application/json",
processData: false,
type: "POST",
@xcooper
xcooper / WebServiceAspect.java
Last active December 27, 2015 01:19
Aspect that check outside web service
@Aspect
public class WebServiceAspect {
@Pointcut("execution(public * com.service..*Service.*(..))")
void allService() {}
@Around("allService()")
@SuppressWarnings({ "rawtypes", "unchecked" })
public Object depressException(ProceedingJoinPoint joinPoint) throws Throwable {
MethodSignature signature = (MethodSignature) joinPoint.getSignature();
@xcooper
xcooper / test-generator-javabean.groovy
Last active August 29, 2015 14:18
Generate JavaBean instance from Interfaces using CGLIB
/**
* Dynamically create a Javabean from Interfaces.
* It's ugly, but works ;)
*
*/
@Grapes(@Grab(group='cglib', module='cglib', version='3.1'))
import net.sf.cglib.beans.*
import net.sf.cglib.proxy.*
interface Test {
@xcooper
xcooper / genkey.sh
Last active August 4, 2020 06:06
Generate private key, certification request, optional PEM files at once
#!/bin/bash
echo "edit this file before you execute it!!"
echo "make sure keytool and openssl commands are in PATH"
echo "Contiune?" | read ANS
echo "give me CN(www.xxx.com.tw)" | read CN
echo "give me default password(length >= 8)" | read -s PASS
set -e
# Edit these arguments
@xcooper
xcooper / setup-environment.sh
Last active April 25, 2016 03:08
My script to setup environment after Ubuntu installed.
#!/bin/bash
mkdir -p ~/bin
mkdir -p ~/workspace
# startup environment
cat >> ~/.profile <<EOF
export PATH=~/bin:$PATH
export TEMP=${TEMP:-"/tmp"}
EOF
chmod u+x ~/.profile
@xcooper
xcooper / init-postgres.txt
Last active August 29, 2015 14:22
PostgreSQL initdb
$ su
# postgresql-setup initdb
# su - postgres
$ psql
\password postgres
$ echo "host all all 192.168.133.0/24 md5" >> /var/lib/pgsql/data/pg_hba.conf
$ exit
# service postgres start
# exit
@xcooper
xcooper / httpd-proxy.conf
Last active August 31, 2015 10:35
Apache httpd reverse proxy
<IfModule proxy_module>
<IfModule proxy_http_module>
#LogLevel alert trace3
#################
# Reverse Proxy #
#################
ProxyRequests Off
ProxyTimeout 3600
# turn this on if there are https URL to handle with.