Skip to content

Instantly share code, notes, and snippets.

View greentornado's full-sized avatar

Hai Nguyen greentornado

View GitHub Profile
@greentornado
greentornado / md5-example.go
Created December 27, 2019 07:14 — forked from sergiotapia/md5-example.go
Golang - How to hash a string using MD5.
import (
"crypto/md5"
"encoding/hex"
)
func GetMD5Hash(text string) string {
hasher := md5.New()
hasher.Write([]byte(text))
return hex.EncodeToString(hasher.Sum(nil))
}
@greentornado
greentornado / check.go
Created December 27, 2019 04:44 — forked from mattes/check.go
Check if file or directory exists in Golang
if _, err := os.Stat("/path/to/whatever"); os.IsNotExist(err) {
// path/to/whatever does not exist
}
if _, err := os.Stat("/path/to/whatever"); !os.IsNotExist(err) {
// path/to/whatever exists
}
@greentornado
greentornado / nginx.conf
Created October 22, 2019 15:34 — forked from CSRaghunandan/nginx.conf
Nginx configuration for serving mp4 videos
#user nobody;
worker_processes 4;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
@greentornado
greentornado / Linux
Created September 10, 2019 03:57 — forked from tovbinm/Linux
Increase ulimit
1.
# vim /etc/sysctl.conf
fs.file-max = 999999
net.ipv4.tcp_rmem = 4096 4096 16777216
net.ipv4.tcp_wmem = 4096 4096 16777216
net.ipv4.ip_local_port_range = 1024 65535
2.
# vim /etc/security/limits.conf
root - nofile 999999
package main
import (
"database/sql"
"gopkg.in/gorp.v1"
"log"
"strconv"
"github.com/gin-gonic/gin"
_ "github.com/go-sql-driver/mysql"
@greentornado
greentornado / scrape-sitemap.sh
Created May 27, 2019 17:52 — forked from pix0r/scrape-sitemap.sh
Use wget to scrape all URLs from a sitemap.xml Usage: scrape-sitemap.sh http://domain.com/sitemap.xml
#!/bin/sh
SITEMAP=$1
if [ "$SITEMAP" = "" ]; then
echo "Usage: $0 http://domain.com/sitemap.xml"
exit 1
fi
XML=`wget -O - --quiet $SITEMAP`
@greentornado
greentornado / run_scheduled.py
Created May 18, 2019 04:41 — forked from numberoverzero/run_scheduled.py
00.async.periodic.rst
import asyncio
import functools
import json
import secrets
import aiohttp
from concurrent.futures import ALL_COMPLETED
@greentornado
greentornado / sanic-websockets.py
Created April 30, 2019 14:10 — forked from ahopkins/# Sanic websocket feeds v2.md
Sanic based websocket pubsub feed
import json
import random
import string
from functools import partial
from sanic import Sanic
import aioredis
import asyncio
import websockets
@greentornado
greentornado / feed.py
Created April 25, 2019 15:45 — forked from ahopkins/# Sanic websocket feeds v1.md
Sanic Websocket Feed
from .objects import Feed
# from sanic_jwt.decorators import protected
feeds = {}
def get_feed(feed_name, app):
if feed_name in feeds:
return feeds.get(feed_name)
@greentornado
greentornado / progress.py
Created April 25, 2019 15:40 — forked from ahopkins/progress.py
Python command line progress bar in less than 10 lines of code.
# The MIT License (MIT)
# Copyright (c) 2016 Vladimir Ignatev
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the Software
# is furnished to do so, subject to the following conditions:
#