Skip to content

Instantly share code, notes, and snippets.

View nguyendangminh's full-sized avatar

Nguyen Dang Minh nguyendangminh

View GitHub Profile
@nguyendangminh
nguyendangminh / favicon.ico.go
Last active February 23, 2025 02:33
Serve favicon.ico in Golang
...
func faviconHandler(w http.ResponseWriter, r *http.Request) {
http.ServeFile(w, r, "relative/path/to/favicon.ico")
}
...
func main() {
http.HandleFunc("/favicon.ico", faviconHandler)
}
@nguyendangminh
nguyendangminh / nmap.sh
Last active September 2, 2015 16:21
nmap cookbook
$ sudo apt-get install nmap
# Scan all hosts in the network (between 192.168.1.0 and 192.168.1.255) by ping
$ nmap -sP 192.168.1.0/24
# Scan all open ports on a host
$ nmap 192.168.1.123
# Detect OS, services
$ nmap -A minhnd.com
@nguyendangminh
nguyendangminh / beego.go
Last active August 29, 2015 12:04
Beego cookbook
# Get request parameters
## GET paramaters
### GET example.com/item?id=1203&name=minhnd
### or POST example.com/item (data: id=1203, name=minhnd)
id := c.GetInt("id")
name := c.GetString("name")
### Other methods
### c.GetString(key string) string
### c.GetStrings(key string) []string
### c.GetInt(key string) (int64, error)
@nguyendangminh
nguyendangminh / bootstrap.html
Created August 29, 2015 11:45
Bootstrap cookbook
# Button-like anchor element
<a href="/page.html" class="btn btn-primary" role="button">Add item</a>
@nguyendangminh
nguyendangminh / get_root.go
Created June 24, 2015 02:51
Check whether user is root
func get_root() (int) {
euid := os.Geteuid()
if euid != 0 {
fmt.Println("[-] You didn't run as root!")
fmt.Println("[-] Exiting...")
os.Exit(1)
}
return euid
}
@nguyendangminh
nguyendangminh / docker-cookbook.sh
Last active November 9, 2015 02:20
Docker cookbook
# Installation
$ wget -qO- https://get.docker.com/ | sh
# Some useful commands
$ docker pull ubuntu:latest
$ docker images
$ docker ps
$ docker ps -a
$ docker run -it ubuntu:latest /bin/bash
$ docker run -it --name="my_docker_image" ubuntu:latest /bin/bash
@nguyendangminh
nguyendangminh / tmux.sh
Last active March 28, 2016 02:12
tmux
# Create a new session
$ tmux
## or
$ tmux new
## or
$ tmux new -s <session-name>
# Detaching from a session
$ tmux detach
@nguyendangminh
nguyendangminh / git.txt
Created June 4, 2015 09:40
Git cookbook
# Ignore files from repository in the pull request
git update-index --assume-unchanged source/law/*.pyc
# add the following util.py to your application directory
# in the models.py
from .util import create_thumbnail
class Article(models.Model):
image = models.ImageField(default="")
thumbnail = models.ImageField()
def save(self):
# create a thumbnail
@nguyendangminh
nguyendangminh / virtualenv
Created June 1, 2015 16:42
virtualenv cookbok
# Installation
$ sudo apt-get install virtualenv
# Usage
$ virtualenv <yourdir>
$ cd <yourdir>
$ source bin/activate