Skip to content

Instantly share code, notes, and snippets.

View saniaky's full-sized avatar
👋

John Doe saniaky

👋
  • Web
  • Online
View GitHub Profile
@saniaky
saniaky / CheckPort.java
Last active February 21, 2023 16:16
Check if port is open
public static boolean serverListening(String host, int port) {
Socket s = null;
try {
s = new Socket(host, port);
log.info("OK -> HOST: {}, PORT: {}", host, port);
return true;
} catch (Exception e) {
log.info("CLOSED -> HOST: {}, PORT: {}", host, port);
return false;
@saniaky
saniaky / Readme.md
Last active October 30, 2024 15:30
Docker + nginx-proxy + let's encrypt + watchtower + fail2ban

Complete solution for websites hosting

This gist contains example of how you can configure nginx reverse-proxy with autmatic container discovery, SSL certificates generation (using Let's Encrypt) and auto updates.

Features:

  • Automatically detect new containers and reconfigure nginx reverse-proxy
  • Automatically generate/update SSL certificates for all specified containers.
  • Watch for new docker images and update them.
  • Ban bots and hackers who are trying to bruteforce your website or do anything suspicious.
@saniaky
saniaky / aws-s3-policy.json
Last active January 14, 2022 01:06
Backup and restore a ALL MySQL databases from a running Docker MySQL container.
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "AllowPolicy",
"Effect": "Allow",
"Action": [
"s3:PutObject",
"s3:GetObject",
"s3:ListBucket"
@saniaky
saniaky / custom_proxy_settings.conf
Last active August 15, 2023 09:05
Docker + Wordpress + Nginx Proxy + Let's encrypt + Watcher
client_max_body_size 64m;
@saniaky
saniaky / package.json
Last active February 16, 2021 10:52
Reverse proxy server for API + create-react-app (CRA)
{
"name": "test",
"version": "0.1.0",
"private": true,
"scripts": {
"app": "concurrently \"node proxy-middleware.js\" \"npm start\"",
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
@saniaky
saniaky / Messages.java
Created December 5, 2017 11:10
Example of using message resources in Spring Boot service layer code, in as simple way.
import org.springframework.context.MessageSource;
import org.springframework.context.support.MessageSourceAccessor;
import org.springframework.stereotype.Component;
import java.util.Locale;
/**
* @author saniaky
* @since 12/5/17
*/
@saniaky
saniaky / TokenController.java
Last active February 3, 2021 15:53
How to logout (revoke token + refresh token) user in Spring Security using OAuth 2.0
@Controller
public class TokenController {
private final TokenStore tokenStore;
@Autowired
public TokenController(TokenStore tokenStore) {
this.tokenStore = tokenStore;
}
@saniaky
saniaky / gist:7acfeb88746e4d6acc7624d3c5f50886
Last active November 28, 2017 14:01
Create MySQL database in utf8
=======> Create database
CREATE DATABASE db_name CHARACTER SET utf8 COLLATE utf8_general_ci;
@saniaky
saniaky / gist:7fe9c245209403b2ab567e437b9882aa
Created May 4, 2017 13:34
Check remote server SSL certificate
true | openssl s_client -connect site.com:443 -servername site.com | openssl x509 -noout -text | grep DNS:
@saniaky
saniaky / example.java
Created August 29, 2015 19:42
Java reflection api
public void getObject(Object obj) {
try {
for (Field field : obj.getClass().getDeclaredFields()) {
//field.setAccessible(true); // if you want to modify private fields
System.out.println(field.getName()
+ " - " + field.getType()
+ " - " + field.get(obj));
}
} catch (IllegalAccessException e) {
e.printStackTrace();