Skip to content

Instantly share code, notes, and snippets.

View hongster's full-sized avatar

Hong hongster

View GitHub Profile
@hongster
hongster / tcp_timeout.go
Created October 2, 2015 11:30
Golang example on handling TCP connection and setting timeout.
package main
import (
"fmt"
"net"
"time"
"bufio"
)
func handleConnection(conn net.Conn) {
@hongster
hongster / ssh-sha256.php
Created August 7, 2023 16:18
Extract SSL SHA256 Fingerprint
#!/usr/bin/env php
<?php
/**
* Get SHA5 digest for remote SSL cert
*
* @param string $host Domain or IP address
* @param int $port Port number, default 443.
* @return string Hexadecimal in lowercase
*/
function getSHA256Digest($host, $port = 443) {
@hongster
hongster / go_mem_usage.go
Last active July 10, 2023 13:29
Go runtime memory usage.
package main
import (
"fmt"
"runtime"
)
func main() {
// https://golang.org/pkg/runtime/#MemStats
var memStats runtime.MemStats
@hongster
hongster / alias.sh
Last active June 13, 2022 10:11
Yet another set of aliases.
alias ..='cd ..'
alias grep='grep --color=auto'
alias mkdir='mkdir -p -v'
alias more='less'
alias ping='ping -c 5'
alias view='vim -R'
alias scat='sudo cat'
alias sudo='sudo '
alias svim='sudo vim'
@hongster
hongster / primitive_pythagorean_triples.py
Created January 4, 2016 04:54
Generate Primitive Pythagorean Triples using Euclid's formula.
#!/usr/bin/python
"""
Exercise in generate Primitive Pythagorean Triples using Euclid's formula.
Ref: http://bit.ly/1MOK3kY
"""
import fractions
import math
def pythagorean_triple(s, t):
@hongster
hongster / odbc.ini
Created May 14, 2020 10:43
Sample odbc.ini for Netezza
[ODBC Data Sources]
NZSQL = NetezzaSQL
[NZSQL]
;Path of a driver used for database connection
Driver = NetezzaSQL
;A decription used to identify the database connection properties.
Description = NetezzaSQL ODBC
@hongster
hongster / build_number_gen.php
Last active April 12, 2019 07:40
Generating build number from git branch name and commit count.
<?php
/**
* Generate a build number based on Git commit count and current branch.
* @return string Format: "{$branch}.{$commitCount}"
*/
public function buildNumber()
{
$branch = exec('git rev-parse --abbrev-ref HEAD');
$commitCount = exec('git rev-list HEAD --count');
@hongster
hongster / s3_result_scraper.py
Created August 26, 2018 11:09
Scrape ballroom dance competition result from (HTML) result generated by Skating System Software.
#!/usr/local/bin/python
from bs4 import BeautifulSoup
import urllib2
import re
import sys
import codecs
def process_folder(folder_url):
page = urllib2.urlopen(folder_url)
@hongster
hongster / log-killer.php
Created August 21, 2018 10:12
Delete log files so that total size of all log files is kept within certain size limit.
#!/usr/bin/env php
<?php
/* This script is designed to delete logs files if it exceeds a defined size limit.
* Size limit is applied to all log files, instead of individual file.
* The logs are sorted by filename in reversed alphabetical order.
* Each file's size is counted and sum with previous file. If size limit is exceeded,
* subsequent files are deleted.
*/
const MB = 1024 * 1024;

Keybase proof

I hereby claim:

  • I am hongster on github.
  • I am hongster (https://keybase.io/hongster) on keybase.
  • I have a public key whose fingerprint is DAD6 71CB E980 8801 48B7 20C8 7C1C E5E3 11EC E1DC

To claim this, I am signing this object: