Skip to content

Instantly share code, notes, and snippets.

View jsgao0's full-sized avatar

Anson jsgao0

View GitHub Profile
@jsgao0
jsgao0 / custom-btn.html
Created August 3, 2020 07:42
custom styles for file upload button
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>Custom Button of Upload File</title>
<style>
.upload-btn {
position: relative;
width: 40px;
@jsgao0
jsgao0 / index.html
Created July 10, 2020 16:39
slicing file
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<input type="file" />
<script>
@jsgao0
jsgao0 / interceptor.js
Last active May 2, 2018 06:57
Intercept the data of google poi while user clicks on the map.
var url = {
getQueryParameter: function (name, url) {
if (!url) {
url = window.location.href;
}
name = name.replace(/[\[\]]/g, "\\$&");
var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
results = regex.exec(url);
if (!results) return null;
if (!results[2]) return '';
@jsgao0
jsgao0 / select_permissions.sql
Created April 21, 2017 05:56
Find all users' permissions.
select permission_name, state_desc, type_desc, U.name, OBJECT_NAME(major_id)
from sys.database_permissions P
JOIN sys.tables T ON P.major_id = T.object_id
JOIN sysusers U ON U.uid = P.grantee_principal_id
@jsgao0
jsgao0 / Human.java
Created March 28, 2017 07:51
An example of IOC and DI.
public class Human {
private IHuman human;
public Human(IHuman human) {
this.human = human;
}
public void doSomeWork() {
human.doWork();
}
public static void main(String[] args)
{
@jsgao0
jsgao0 / objectLeftJoin.js
Last active March 13, 2017 05:57
Object.leftJoin() implements a function to join 2 objects x and y based on the properties of x. However, if the properties of y are not shown in x then skip copy.
var x = {a:1, b:2 };
var y = {a:5, c:3, d:5};
Object.leftJoin = function(leftObj, rightObj) {
var acceptKeyList = Object.keys(leftObj);
var returnObj = {};
for(var key of Object.keys(rightObj)) {
if(acceptKeyList.indexOf(key) < 0) {
Object.defineProperty(rightObj, key, {
@jsgao0
jsgao0 / PDFOperator.java
Last active March 8, 2017 08:28
The sample of pdfbox. How to convert pdf to images and how to set protect password using Java pdfbox.
package com.test;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.Date;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDPage;
import org.apache.pdfbox.pdmodel.encryption.AccessPermission;
@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'
@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 / 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(){}