Skip to content

Instantly share code, notes, and snippets.

View wancaibida's full-sized avatar

Charles Chen wancaibida

View GitHub Profile
@wancaibida
wancaibida / debian-12-install-docker.sh
Last active January 10, 2024 08:52
Install docker on Debian 12
sudo apt-get update
sudo apt-get install -y ca-certificates curl gnupg
sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/debian/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
sudo chmod a+r /etc/apt/keyrings/docker.gpg
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/debian \
$(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update
@wancaibida
wancaibida / Caddyfile
Created June 3, 2020 13:09
Caddyfile v2 example
yourdomain.com {
tls email@abc.com
root * /srv/www
file_server
handle_errors {
@404 {
expression int({http.error.status_code}) == 404
}
respond @404 "This is 404 error message"
@wancaibida
wancaibida / Dockerfile
Created April 14, 2020 13:17
Dockerfile multiple stage example
FROM ubuntu:18.04 AS builder
WORKDIR /app/
RUN apt-get update
RUN apt-get install -y build-essential libpoppler-private-dev libleptonica-dev pkg-config git
RUN git clone https://github.com/allenai/pdffigures.git
WORKDIR pdffigures
RUN make DEBUG=0
RUN ldd ./pdffigures | tr -s '[:blank:]' '\n' | grep '^/' | xargs -I % sh -c 'mkdir -p $(dirname deps%); cp % deps%;'
FROM ubuntu:18.04
@wancaibida
wancaibida / debian-install-docker.sh
Last active March 9, 2021 09:19
Install docker on google cloud debain
#!/bin/sh
set -e
sudo dpkg --remove docker docker-engine docker.io
sudo apt-get update
sudo apt-get install -y \
apt-transport-https \
ca-certificates \
curl \
gnupg2 \
@wancaibida
wancaibida / start-stop-daemon.sh
Created August 4, 2017 06:57
start-stop-daemon script for java application
#!/bin/sh
DESC="Java Service"
NAME=java-service
PIDFILE=/tmp/$NAME.pid
PATH_TO_JAR=~/java-service.jar
PATH_TO_JAVA=/usr/local/jdk1.8.0_131/bin/java
SERVICE_CONFIG='-Dserver.port=8080 -DLOG_PATH=/var/log'
COMMAND="$PATH_TO_JAVA -- $SERVICE_CONFIG -jar $PATH_TO_JAR"
@wancaibida
wancaibida / requestIp.java
Created July 20, 2017 03:10
Get real ip from request
public static String getClientIP(HttpServletRequest request)
{
String ip = request.getHeader("X-Real-IP");
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip))
ip = request.getHeader("X-Forwarded-For");
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip))
ip = request.getHeader("Proxy-Client-IP");
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip))
ip = request.getHeader("WL-Proxy-Client-IP");
if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip))