Skip to content

Instantly share code, notes, and snippets.

View huangsam's full-sized avatar
🌱
Continuous learning

Samuel Huang huangsam

🌱
Continuous learning
View GitHub Profile
@huangsam
huangsam / app.py
Created October 11, 2019 06:53
Long polling demo with Flask + axios
from datetime import datetime
from random import randint
from time import sleep
from flask import Flask, jsonify, render_template
app = Flask(__name__)
@huangsam
huangsam / ssh_tunnel.sh
Created September 20, 2019 16:19
Bash function for creating a SSH tunnel
function ssh_tunnel() {
target_host="$1"
target_port="$2"
tunnel_host="$3"
source_port="$4"
[[ `ps axu | grep $target_port | grep ssh` ]] && return
ssh -Nf -L "$source_port:$target_host:$target_port" "$tunnel_host"
}
@huangsam
huangsam / kafka-demo.sh
Created April 25, 2019 17:17
Basic operations with Apache Kafka
#!/bin/bash
# kafka-demo.sh: A playground for running Kafka on a Docker container
# https://www.tutorialspoint.com/apache_kafka/apache_kafka_basic_operations.htm
# Initialization step
# openjdk:8 image uses the following software:
# Java 1.8.0_212 and Debian 9 (stretch)
docker run --rm -it --name kafka openjdk:8 bash
# All the commands below are run within the Docker container
@huangsam
huangsam / domains.py
Created March 9, 2019 08:36
DNS resolution with Python
import dns.message
import dns.name
import dns.rdatatype
import dns.query
def do_work(target, nameserver):
qname = dns.name.from_text(target)
responses = []
for dtype in (dns.rdatatype.A, dns.rdatatype.NS):
@huangsam
huangsam / configure.sh
Last active March 9, 2019 08:41
Bind nameserver demo
#!/bin/bash
yum install bind bind-utils -y
vi /etc/named.conf
vi /var/named/mydomain.com.zone
systemctl start named
systemctl status named
dig @localhost mydomain.com
@huangsam
huangsam / domains.py
Created February 22, 2019 04:48
DNS queries with Python
import dns.message
import dns.name
import dns.rdatatype
import dns.query
def do_work(target, nameserver):
qname = dns.name.from_text(target)
responses = []
for dtype in (dns.rdatatype.A, dns.rdatatype.NS):
@huangsam
huangsam / Makefile
Last active February 23, 2019 18:35
HTTP checker in Go
all: complex simple
complex: complex.go
go build complex.go
simple: simple.go
go build simple.go
clean:
rm complex simple
@huangsam
huangsam / awk.sh
Created January 20, 2019 01:40
Awk in action
#!/bin/bash
find . -name 'meta-*.yml' | xargs awk -F':' -f metadata.awk
@huangsam
huangsam / chan1.go
Last active January 28, 2019 17:45
Go channels in action
package main
import "fmt"
func main() {
jobs := make(chan int)
done := make(chan bool)
// Wait for job and send done signal
go func() {