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 / conflict.py
Last active January 30, 2019 03:49
Metaclasses in action
class MetaOne(type):
def __new__(mcs, name, bases, attrs):
kls = super().__new__(mcs, name, bases, attrs)
kls._numbers = [1, 2, 3]
return kls
class MetaTwo(type):
def __new__(mcs, name, bases, attrs):
kls = super().__new__(mcs, name, bases, attrs)
kls._numbers = {1, 2, 3}
@huangsam
huangsam / config.sh
Last active January 16, 2019 08:46
Testing out Pub/Sub service on GCP
#!/bin/bash
export GOOGLE_CLOUD_PROJECT="<Project ID>"
export GOOGLE_APPLICATION_CREDENTIALS="<Credentials File Path>"
@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() {
@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 / 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 / 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 / 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 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 / 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