Skip to content

Instantly share code, notes, and snippets.

@mylesjao
mylesjao / ConfigurableUrlByteSource.java
Created May 13, 2014 10:49
guava ByteSource with timeout configuration support
public class ConfigurableUrlByteSource extends ByteSource{
private final URL url;
private int connectTimeout = 0;
private int readTimeout = 0;
public ConfigurableUrlByteSource(URL url) {
this.url = Preconditions.checkNotNull(url, "url is null");
@mylesjao
mylesjao / ObjectMapperHolder.java
Last active August 29, 2015 14:01
get ObjectMapper with singleton pattern
/**
* get {@code ObjectMapper} with singleton pattern
*
* @author myles
*
*/
public enum ObjectMapperHolder {
INSTANCE;
@mylesjao
mylesjao / source-jar.gradle
Created May 16, 2014 01:59
custom tasks for creating source jars
task sourcesJar(type: Jar, dependsOn:classes) {
classifier = 'sources'
from sourceSets.main.allSource
}
artifacts {
archives sourcesJar
}
@mylesjao
mylesjao / maven-publish.gradle
Last active August 29, 2015 14:01
publish to maven proxy repository by gradle
apply plugin: 'maven'
uploadArchives {
repositories {
mavenDeployer {
//release repository for version with no suffix '-SNAPSHOT'
repository(url: "http://x.x.x.x/nexus/content/repositories/releases") {
authentication(userName: "name", password: "passwd")
}
//snapshot repository for version with suffix '-SNAPSHOT'
@mylesjao
mylesjao / install-mongo.sh
Created May 22, 2014 07:45
mongodb installation on ubuntu
#!/bin/bash
echo "Import the public key used by the package management system...."
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10
echo 'Create a list file for MongoDB...'
echo 'deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen' | sudo tee /etc/apt/sources.list.d/mongodb.list
echo 'Reload local package database.'
sudo apt-get update
@mylesjao
mylesjao / app-init.sh
Last active August 29, 2015 14:01
get script file path and set to APP_HOME environment variable
#!/bin/bash
SCRIPT_DIR=$(readlink -f $(dirname ${BASH_SOURCE[0]}))
# assume this script is in APP_HOME/bin directory
cd $SCRIPT_DIR/..
APP_HOME="`pwd -P`"
@mylesjao
mylesjao / show-git-branch.sh
Created June 6, 2014 02:54
show current git branch in shell
#show current git branch in shell
function git_branch {
ref=$(git symbolic-ref HEAD 2> /dev/null) || return;
echo "("${ref#refs/heads/}") ";
}
PS1="[\[\033[1;32m\]\w\[\033[0m\]] \[\033[0m\]\[\033[1;36m\]\$(git_branch)\[\033[0;33m\]\[\033[0m\]$ "
@mylesjao
mylesjao / node_global.sh
Created June 18, 2014 12:43
Changing the global node version of nvm used
n=$(which node);n=${n%/bin/node}; chmod -R 755 $n/bin/*; sudo cp -r $n/{bin,lib,share} /usr/local
@mylesjao
mylesjao / vlc.html
Last active July 28, 2019 02:05
vlc web plugin sample. only for IE and Firefox
<!DOCTYPE html>
<html>
<body>
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
</head>
<object
@mylesjao
mylesjao / WebConfig.java
Last active August 29, 2015 14:11
enable spring matrix variable support
@Configuration
public class WebConfig extends WebMvcConfigurerAdapter {
@Override
public void configurePathMatch(PathMatchConfigurer configurer) {
// enable matrix variable support
if (configurer.getUrlPathHelper() == null) {
UrlPathHelper urlPathHelper = new UrlPathHelper();
urlPathHelper.setRemoveSemicolonContent(false);
configurer.setUrlPathHelper(urlPathHelper);