Skip to content

Instantly share code, notes, and snippets.

View jsgao0's full-sized avatar

Anson jsgao0

View GitHub Profile
@jsgao0
jsgao0 / googleDrivePublicFile_s2.html
Last active July 11, 2016 05:07
Retrieve File From Google Drive Using Google Drive v2.
<html>
<head>
<script>
function driveRequest() {
var request = gapi.client.drive.files.get({
'fileId': 'File ID'
});
request.then(function(response) {
// response is the result.
});
@jsgao0
jsgao0 / Sample.java
Last active August 10, 2016 06:17
JPA Entity for DEMO.
package com.sample.entity;
import java.math.BigDecimal;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.IdClass;
import javax.persistence.Lob;
import javax.persistence.Table;
@jsgao0
jsgao0 / cssWaveAndStar.html
Last active August 12, 2016 15:58
The difference between CSS selector *= and ~=. DEMO link: http://codepen.io/jsgao0/pen/oLmgPO/.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>CSS selector *= vs ~=</title>
</head>
<body>
<h1 class="header" data-now="day">ALL SHOPS</h1>
<div class="promotion-bar" data-promotion-detail="day">John Bar</div>
@jsgao0
jsgao0 / killTomcatUsingGrep.sh
Created August 17, 2016 07:31
Useful shells.
ps aux | grep ^tomcat | awk '{print$2}' | xargs kill -9
@jsgao0
jsgao0 / master-post-receive.sh
Last active November 3, 2016 07:10
Git hooks: change directory, git pull, mvn package, scp.
#!/bin/bash
while read oldrev newrev ref
do
if [[ $ref =~ .*/master$ ]];
then
cd /git/project/path || exit
unset GIT_DIR
git pull
mvn clean package
sshpass -p password scp from_path username@remote_url:to_path
@jsgao0
jsgao0 / install-docker.sh
Last active September 14, 2016 05:48
Install docker and run a container of Tomcat on CentOS.
#!/bin/bash
# Program:
# Install docker engine.
# History:
# 2016/09/01 Anson First release
# 2016/09/02 Anson Second release: tomcat:8.5 & verify docker command is exist
# Set environment path.
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH
@jsgao0
jsgao0 / logstash.conf
Created September 20, 2016 05:50
Logstash config file on Ubuntu.
input {
file {
path => "/var/log/tomcat8/localhost_access_log*"
start_position => beginning
sincedb_path => "/dev/null"
ignore_older => 0
type => "access_log"
}
}
@jsgao0
jsgao0 / CustomException.java
Last active October 19, 2016 06:43
A custom Exception which is JSON-like.
package com.example;
import org.json.JSONObject;
public class ReturnException extends Exception {
// Because Exception implements Throwable which implements Serializable.
private static final long serialVersionUID = 1L;
public ReturnException(){}
@jsgao0
jsgao0 / CipherUtility.java
Last active July 15, 2024 08:45
Encryption with RSA using Java in Spring Framework.
package com.jsgao.bean;
import java.security.InvalidKeyException;
import java.security.Key;
import java.security.KeyFactory;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.security.PrivateKey;
@jsgao0
jsgao0 / curl.sh
Created February 16, 2017 08:19
Get response time with curl.
# Reference: https://viewsby.wordpress.com/2013/01/07/get-response-time-with-curl/
curl -o /dev/null -s -w %{time_total}\\n 'http://www.google.com'