Skip to content

Instantly share code, notes, and snippets.

View johwanghee's full-sized avatar

johwanghee johwanghee

View GitHub Profile
def extract_hash_tags(s):
tags = set([i for i in s.split() if i.startswith("#")])
tags = set([re.sub(r"(\W+)$", "", j, flags=re.UNICODE) for j in tags]) # encoded
tags = set([re.sub(r"#+", "#", k) for k in tags]) # remove duplicate hash
return tags
@johwanghee
johwanghee / download.py
Created June 19, 2018 00:47
python requests file download
import requests
import re
import time
url_base = 'http://xxx.site/{}.mp3'
def download(name):
url = url_base.format(name)
print(url)
r = requests.get(url, allow_redirects=True)
@johwanghee
johwanghee / decimal_encode.py
Last active March 21, 2018 02:07
python3.6 decimal encode
# Decimal to Hex
'{:02x}'.format(100000)
import base36
# base36 https://pypi.python.org/pypi/base36/0.1.1
base36.dumps(100000)
package main
import "fmt"
import "strings"
func main() {
path := "folder/path/filename.mp4"
fmt.Println(strings.LastIndex(path, "/"))
fmt.Println(path[:strings.LastIndex(path, "/")])
fmt.Println(path[:strings.LastIndex(path, ".")])
echo '0002' | xxd -r -p | nc localhost 8888 | xxd -l 120 -ps -c 100
echo -ne '0002' | sed -e 's/../\\x&/g'
@johwanghee
johwanghee / golang hex
Last active January 7, 2018 07:24
golang hex sample
package main
import (
"encoding/hex"
"fmt"
)
func main() {
bs := make([]byte, 7)
copy(bs[:], "0000003")
s := fmt.Sprintf("number is %d, string is %s", 1234, "STRING")
fmt.Println(s)
/* print JAVA */
System.out.println(String.format("Hi, My name is %s. I'm %d years old.", "HWANG", 30));
/* print GO */
fmt.Printf("Hi, My name is %s. I'm %d years old.\n", "HWANG", 30)
@johwanghee
johwanghee / basicbash.sh
Created February 28, 2017 06:21
basic bash shell script
$ vi hello.sh
(hello.sh)
#!/bin/bash
echo hello world
$ chmod 755 hello.sh
$ ./hello.sh
hello world
@johwanghee
johwanghee / gist:a5ad139fd26978b6494284f6cc23dd2d
Last active September 19, 2017 09:32
change current time to string(java, go)
/* Java */
Calendar cal = Calendar.getInstance();
SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
System.out.println(fmt.format(cal.getTime()));
// Output "2017-02-28 11:35:01"
/* Go */
time.Now().format("2006-01-02 15:04:05")
// Output "2017-02-28 11:35:01"