Skip to content

Instantly share code, notes, and snippets.

View jamesnguyen101's full-sized avatar

Loi Nguyen jamesnguyen101

View GitHub Profile
@jamesnguyen101
jamesnguyen101 / restTemplate.ssl.java
Created February 20, 2020 02:31
Spring restTemplate Trust override
@Bean
public RestTemplate restTemplate(RestTemplateBuilder builder) throws NoSuchAlgorithmException, KeyManagementException {
TrustManager[] trustAllCerts = new TrustManager[] {
new X509TrustManager() {
public java.security.cert.X509Certificate[] getAcceptedIssuers() {
return new X509Certificate[0];
}
public void checkClientTrusted(
java.security.cert.X509Certificate[] certs, String authType) {
@jamesnguyen101
jamesnguyen101 / oracle-table-row-lock-issue
Created March 18, 2019 19:49
Remove Oracle table row lock, example on SEC_USER
## script 1
-- step 1
select
c.owner,
c.object_name,
c.object_type,
b.sid,
b.serial#,
b.status,
@jamesnguyen101
jamesnguyen101 / HttpURLConnectionExample.java
Created January 16, 2019 07:28 — forked from hitenpratap/HttpURLConnectionExample.java
Send HTTP POST/GET request using HttpURLConnection in java
package com.hprog99;
import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import javax.net.ssl.HttpsURLConnection;
@jamesnguyen101
jamesnguyen101 / Call SOAP_XML
Created January 16, 2019 07:27 — forked from kodiyan/Call SOAP_XML
Call SOAP URL and send the Request XML and Get Response XML back
/* Call SOAP URL and send the Request XML and Get Response XML back */
import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
@jamesnguyen101
jamesnguyen101 / ssl-self-signed.txt
Last active January 14, 2019 10:03
ssl with self-signed cert
## PA 1: Import the certificate into the Java Store
keytool -import -keystore $JAVA_HOME/jre/lib/security/cacerts -file $CERT_FILE -storepass "changeit" -alias $ALIAS
## PA 2: run java app with arguments
java -Djavax.net.ssl.trustStore=my-domain.com.jks -Djavax.net.ssl.trustStorePassword=sb1234 Get https://selfsigned.my-domain.com
## PA 3: custom code
...
@jamesnguyen101
jamesnguyen101 / make-swap.sh
Last active January 7, 2019 14:57
make 4G swap on CentOS
#!/bin/sh
SWAP_SIZE=4G
echo "create $SWAP_SIZE swap"
# on centos 6
#fallocate -l $SWAP_SIZE /swapfile
# on centos 7
dd if=/dev/zero of=/swapfile count=4096 bs=1MiB
@jamesnguyen101
jamesnguyen101 / schema.sql
Created December 21, 2018 03:22 — forked from fernandomantoan/schema.sql
Schema for PostgreSQL to use with JdbcTokenStore (Spring Security OAuth2)
create table oauth_client_details (
client_id VARCHAR(256) PRIMARY KEY,
resource_ids VARCHAR(256),
client_secret VARCHAR(256),
scope VARCHAR(256),
authorized_grant_types VARCHAR(256),
web_server_redirect_uri VARCHAR(256),
authorities VARCHAR(256),
access_token_validity INTEGER,
refresh_token_validity INTEGER,
@jamesnguyen101
jamesnguyen101 / RequestAndResponseLoggingFilter.java
Created November 27, 2018 16:48 — forked from int128/RequestAndResponseLoggingFilter.java
Spring Web filter for logging request and response
import lombok.extern.slf4j.Slf4j;
import lombok.val;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.web.filter.OncePerRequestFilter;
import org.springframework.web.util.ContentCachingRequestWrapper;
import org.springframework.web.util.ContentCachingResponseWrapper;
import javax.servlet.FilterChain;
import javax.servlet.ServletException;
@jamesnguyen101
jamesnguyen101 / nginx-rtmp-install.sh
Created June 29, 2018 03:25
Install nginx with nginx-tmp-module from source
#!/bin/sh
# set -e
#to remove trailing \r character
#sed -i 's/\r$//' file_name.sh or using dos2unix to format: yum install dos2unix -y
#Nginx from source
#http://www.ehowstuff.com/how-to-install-nginx-on-centos-7-rhel-7/
#
#Note: enable AIO
# Nginx RTMP Module
@jamesnguyen101
jamesnguyen101 / nginx-image-filter.conf
Last active June 29, 2018 08:15
Nginx filter module - dynamic resize image
server {
# Internal image resizing server.
server_name localhost;
listen 888 ;
allow 127.0.0.1;
deny all;
access_log /var/log/nginx/image_access.log;
error_log /var/log/nginx/image_error.log;