Skip to content

Instantly share code, notes, and snippets.

View jackygurui's full-sized avatar

Rui Gu jackygurui

  • Sheffield
View GitHub Profile
@jackygurui
jackygurui / block_brute_force_wp.sh
Last active August 29, 2015 14:24
Block IP that brute forcing wordpress logins in one line. Requres UFW
#!/bin/sh
grep 11/Jul/2015 access_log | grep "POST /wp-login.php" | awk '{ print $1 }' | sort -n | uniq -c | sort -rn | grep "\\([1-9][0-9][0-9][0-9]\\+\\) " | awk '{ print $2 }' | xargs -n 1 ufw insert 1 deny from
# or change the grep criteria to suit your need.
@jackygurui
jackygurui / ufw_http_https_rules
Created July 12, 2015 20:46
UFW firewall limits for HTTP and HTTPS
### Start HTTP ###
# Enter rule
-A ufw-before-input -p tcp --dport 80 -j ufw-http
-A ufw-before-input -p tcp --dport 443 -j ufw-http
# Limit connections per Class C
-A ufw-http -p tcp --syn -m connlimit --connlimit-above 50 --connlimit-mask 24 -j ufw-http-logdrop
# Limit connections per IP
@jackygurui
jackygurui / live_object.md
Last active June 29, 2022 22:16
Introducing Redisson Live Object

What is a Live Object?

A Live Object can be understood as an enhanced version of standard Java object, of which an instance reference can be shared not only between threads in a single JVM, but can also be shared between different JVMs across different machines. Wikipedia discribes it as:

Live distributed object (also abbreviated as live object) refers to a running instance of a distributed multi-party (or peer-to-peer) protocol, viewed from the object-oriented perspective, as an entity that has a distinct identity, may encapsulate internal state and threads of execution, and that exhibits a well-defined externally visible behavior.

How Redisson Live Object works

Redisson Live Object (RLO) realised this idea by mapping all the fields inside a Java class to a redis hash through a runtime-constructed proxy class. All the get/set methods of each field are translated to hget/hset commands operated on the redis hash, making it accessable to/from any clients connected to the same redis server. As we a

@jackygurui
jackygurui / fibonacci.md
Last active August 4, 2016 23:57
Fastest running code for classic Java interview question: Display fibonacci sequences with recursion.

Performance king (remember the question: with recursion)

Print from 1st to 92th in less than 0.7ms (Intel first generation i7-920 2.66G) This solutions is limited to upto 92th number due to the size of long but very memory efficient while remain high performance.

More sequences results see code below this.

public class Fibonacci {

 private static StringBuffer sb = new StringBuffer();
@jackygurui
jackygurui / streams.txt
Last active October 6, 2017 20:43 — forked from antirez/streams.txt
# Let's add a few entries in our stream "mystream". Every entry in a stream is like
# an hash, composed of fields and values, but every entry can have different fields.
# XADD appends a new entry in a stream, and returns an unique ID which is guaranteed
# be incrementing.
# The first part of the ID is the millisecond unixtime during the
# addition (or the time of the last entry in the stream, if greater than the current time).
# The second part of an entry is a 64 bit counter for entries added in the same ms.
127.0.0.1:6379> XADD mystream name pamela nicknake kill-9
2017-10-23T23:05:00.790+0100 [main] INFO org.redisson.Version - Redisson 3.5.4
2017-10-23T23:05:06.025+0100 [redisson-netty-1-6] INFO org.redisson.connection.pool.MasterConnectionPool - 10 connections initialized for localhost/127.0.0.1:6379
2017-10-23T23:05:06.025+0100 [redisson-netty-1-7] INFO org.redisson.connection.pool.MasterPubSubConnectionPool - 1 connections initialized for localhost/127.0.0.1:6379
2017-10-23T23:05:06.056+0100 [main] INFO org.redisson.Version - Redisson 3.5.4
2017-10-23T23:05:06.067+0100 [redisson-netty-5-6] INFO org.redisson.connection.pool.MasterConnectionPool - 10 connections initialized for localhost/127.0.0.1:6379
2017-10-23T23:05:06.067+0100 [redisson-netty-5-7] INFO org.redisson.connection.pool.MasterPubSubConnectionPool - 1 connections initialized for localhost/127.0.0.1:6379
2017-10-23T23:05:06.138+0100 [main] INFO org.redisson.RedissonNode - 8 map reduce worker(s) registered
2017-10-23T23:05:06.141+0100 [main] INFO org.redisson.RedissonNode - 1 worker(s) for 'MyExecutor' Exe
@jackygurui
jackygurui / Redisson_Timeout_Explained
Created March 27, 2018 13:52
Redisson Timeout Explained
See attatched