Skip to content

Instantly share code, notes, and snippets.

View hiepph's full-sized avatar

Hiep Pham hiepph

View GitHub Profile
@hiepph
hiepph / hostfile.sh
Created August 22, 2020 04:25
host file locations
# Windows
C:\Windows\System32\drivers\etc
@hiepph
hiepph / set.py
Created August 21, 2020 08:02
Get set of unique characters from a list of strings
import dask.bag as db
labels = ["abc", "abd", "bcd"]
b = db.from_sequence(labels)
def join_2_set(a, b):
return set(a) | set(b)
char_sets = b.map(set).fold(join_2_set).compute()
# ref: https://www.geeksforgeeks.org/lru-cache-in-python-using-ordereddict/
from collections import OrderedDict
class LRUCache:
def __init__(self, capacity):
self.cache = OrderedDict()
self.capacity = capacity
def get(self, k):
@hiepph
hiepph / hack_assembler.go
Created July 5, 2020 17:18
Hack Assembler
package main
import (
"bufio"
"fmt"
"io"
"os"
"strconv"
"strings"
)
@hiepph
hiepph / xml_to_csv.go
Created May 27, 2020 09:51
LabelMe xml to csv
package main
import (
"encoding/xml"
"fmt"
"io/ioutil"
"os"
)
type Annotation struct {
@hiepph
hiepph / springer.go
Created May 5, 2020 10:00
Worker pool for concurrently downloading files (Go)
// spawn 10 concurrent workers to download links
package main
import (
"bufio"
"fmt"
"io"
"net/http"
"os"
)
@hiepph
hiepph / tabnet.hs
Created April 23, 2020 04:26
Tabnet preparation
-- Prepare {src,tgt}-train.txt for OpenNMT Image2Text
-- labels (json) >> prepareDataOpenNMT.hs >> src+tgt+vocab.txt (io)
-- src: tgt
-- 123.jpg <tr><td></td>
-- 456.jpg <tr colspan=2 ><td></td>
--
-- vocab:
-- <td
-- colspan="2"
-- >
@hiepph
hiepph / fibonacci.py
Created March 24, 2020 15:54
Fibonacci with memoization
# refer: https://stackoverflow.com/questions/18172257/efficient-calculation-of-fibonacci-series/23462371#23462371
import functools
@functools.lru_cache(None)
def fib(n):
if n < 2:
return n
return fib(n-1) + fib(n-2)
@hiepph
hiepph / ssh_tunnel.sh
Created March 16, 2020 04:15
SSH tunneling/port-forwarding
# tunnel 3888->8888 from the 'fti' server
ssh -L 3888:fti:8888 fti -N
@hiepph
hiepph / _gists.rb
Last active March 6, 2020 06:45
Search gists and return raw values of code
#!/usr/bin/env ruby
require 'net/http'
require 'json'
q = ARGV[0]
def get (url)
uri = URI(url)
return Net::HTTP.get(uri)
end