Skip to content

Instantly share code, notes, and snippets.

View leewin12's full-sized avatar

greg.lee leewin12

View GitHub Profile
@leewin12
leewin12 / gist:5956083
Last active December 19, 2015 12:39
Play2 post json string and return its value
case class TestObj(name: String, msg: String)
def insertMulti() = Action {
implicit req =>
// parse posted json objs
val json = req.body.asJson.getOrElse(JsNull)
val objs = json.as[List[JsValue]].map {
json => Json.reads[TestObj].reads(json).get
}
// return what we got as json string
@leewin12
leewin12 / gist:6505726
Created September 10, 2013 06:36
org.bouncycastle + maven shade
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.x</groupId>
<artifactId>y</artifactId>
<name>z</name>
<packaging>jar</packaging>
<version>1.0.0</version>
<properties>
@leewin12
leewin12 / HibernateLazyIdUtil
Last active October 15, 2019 22:46
Safely get Id from Hibernate Lazy Object
import org.hibernate.proxy.HibernateProxy;
import org.hibernate.proxy.LazyInitializer;
import com.ngr.api.model.BaseModel;
/**
*
* public interface BaseModel<T> {
* public T getId();
* }
@leewin12
leewin12 / split_str.sql
Last active August 29, 2015 13:56 — forked from mikedamage/split_str.sql
MySQL Split User-defined function
-- SPLIT_STR MySQL Function
-- from http://blog.fedecarg.com/2009/02/22/mysql-split-string-function/
CREATE FUNCTION SPLIT_STR(
x VARCHAR(255),
delim VARCHAR(12),
pos INT
)
RETURNS VARCHAR(255)
-- use CHAR_LENGTH instead of LENGTH to support utf8
@leewin12
leewin12 / OneLineJsonSlurper.groovy
Last active August 29, 2015 14:07
Just I try to make it a line.
import groovy.json.JsonSlurper
new JsonSlurper() {
jsonSlurper -> new File('/Users/gregory/be.json').text.split('\n').collect { jsonSlurper.parseText(it).accountId }.unique().each { println it }
}
@leewin12
leewin12 / .htaccess
Last active August 29, 2015 14:08
private IP range config for apache
Order deny,allow
Deny from all
Allow from 10.1.0.0/8
Allow from 172.16.0.0/12
Allow from 192.168.0.0/16
@leewin12
leewin12 / asyncHttpClient.groovy
Created January 5, 2015 10:09
Groovy AsyncHttpClient
@Grab(group='org.codehaus.groovy.modules.http-builder', module='http-builder', version='0.7.1')
import groovyx.net.http.AsyncHTTPBuilder
import groovyx.net.http.URIBuilder
import static groovyx.net.http.Method.POST
import static groovyx.net.http.ContentType.TEXT
import groovy.json.JsonSlurper
def http = new AsyncHTTPBuilder( poolSize:100 )
@leewin12
leewin12 / AsyncHttpClient.java
Last active October 11, 2022 07:57
AsyncHttpClient based on Apache HttpClient4.3.5 and Apache Commons-IO 2.4
package util;
import org.apache.commons.io.IOUtils;
import org.apache.http.client.ResponseHandler;
import org.apache.http.client.config.CookieSpecs;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.DefaultHttpRequestRetryHandler;
import org.apache.http.impl.client.HttpClients;
@leewin12
leewin12 / LoggingConfig.groovy
Created March 20, 2015 04:03
Grails 2.4.4 logging with multi environment
// log4j configuration
log4j = {
appenders {
console name: 'stdout', encoder: pattern(conversionPattern: "%d{ISO8601} %p %c{2} %m%n")
appender new DailyRollingFileAppender(
name: 'rollingFileAppender',
file: "logs/cola.log", append: true, datePattern: "'.'yyMMdd",
layout: pattern(conversionPattern: "%d{ISO8601} %p %c{2} %m%n")
)
}
@leewin12
leewin12 / find_dead.sh
Created August 19, 2016 08:30
check dead ip(or hostname) using shell ping
# !/bin/bash
# ips: ip list file
# ./find_dead.sh > dead.log
# cat dead.log | grep -v ttl | awk '{ print $1 }'
IPS=`cat ips`
for i in $IPS; do
CODE=`ping -c 1 $i `
echo $i $CODE
done