Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View jimlinntu's full-sized avatar
🎯
Focusing

Jim Lin jimlinntu

🎯
Focusing
View GitHub Profile
@jimlinntu
jimlinntu / add_masquerade.sh
Created January 7, 2021 06:00
add_masquerade.sh
#!/bin/bash
interface=ipsec_bridge
target_ip="192.168.2.100"
cidr_ip=$(ip addr show "$interface" | grep 'inet ' | awk '{print $2}')
network=$(ipcalc "$cidr_ip" | grep "Network:" | awk '{print $2}')
function add_masquerade {
iptables -t nat -C POSTROUTING -s "$network" -j SNAT --to "$target_ip" || {
iptables -t nat -I POSTROUTING 1 -s "$network" -j SNAT --to "$target_ip"
@jimlinntu
jimlinntu / connectScript.sh
Created December 24, 2020 07:02
OpenVPN client-connect script
#!/bin/bash
allow_ips=("211.75.165.175")
function handle_connect {
ip=$trusted_ip
echo "Current IP: ${ip}"
for allow_ip in ${allow_ips[@]}; do
if [[ $allow_ip == $ip ]]; then
import cv2
import numpy as np
def main():
img = cv2.imread("./demo.jpeg", cv2.IMREAD_COLOR)
sobel_kernel = np.array([[-1, 0, 1], [-2, 0, 2], [-1, 0, 1]], dtype=np.int32)
# NOTE: filter2D is actually computing correlation so we flip the kernel here
# See: https://docs.opencv.org/4.5.0/d4/d86/group__imgproc__filter.html#ga27c049795ce870216ddfb366086b5a04
# for more information
img_grad_x = cv2.filter2D(img, -1, sobel_kernel)
import cv2
import numpy as np
def main():
img = cv2.imread("./demo.jpeg", cv2.IMREAD_COLOR)
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
edges = cv2.Canny(img, 100, 200)
cv2.imwrite("edge.jpeg", edges)
if __name__ == "__main__":
#include <stdio.h>
#include <iostream>
#include <random>
#include <bitset>
#include <assert.h>
#define MAXN 100
// P = R * 2^K + 1, G is its primitive root
#define P 1004535809LL
#define G 3
#define R 479
@jimlinntu
jimlinntu / detect.sh
Created August 31, 2018 14:38
GCPHelper
while :
do
echo "Sleep awhile"
sleep 10m
# Check if there is python process
if [[ $(ps -ef | grep -c 'python train.py') == 1 ]]; then
sudo shutdown now
fi
done