Skip to content

Instantly share code, notes, and snippets.

@leonmak
leonmak / lc-locked.csv
Created February 1, 2019 05:41
leetcode locked questions
id difficulty title
253 Medium Meeting Rooms II
269 Hard Alien Dictionary
681 Medium Next Closest Time
159 Hard Longest Substring with At Most Two Distinct Characters
642 Hard Design Search Autocomplete System
158 Hard Read N Characters Given Read4 II - Call multiple times
683 Hard K Empty Slots
716 Easy Max Stack
755 Medium Pour Water
@leonmak
leonmak / alien_dict.py
Created January 30, 2019 07:58
269. Alien Dictionary
from collections import defaultdict
class Solution(object):
def alienOrder(self, words):
"""
:type words: List[str]
:rtype: str
"""
graph = defaultdict(list)
@leonmak
leonmak / setup.md
Last active November 2, 2018 00:56
Setup ssh in remote VM

In VM

sudo adduser ubuntu
sudo su ubuntu
cd /home/ubuntu

mkdir .ssh
chmod 700 .ssh

cd .ssh
@leonmak
leonmak / set_gopath.sh
Created June 11, 2018 02:07
go environment setup for gotchas
# . set_gopath.sh
export GOPATH=`pwd`
export PATH="$GOPATH/bin:$PATH"
# for mac osx
# export GOBIN=$GOPATH/bin
# unset if `flogo build`
git config --global --unset alias.gb
import io
import re
import sys
import collections
if len(sys.argv) != 7:
print(sys.argv[0] + " <base_dict> <base_lm> <ext_dict> <ext_lm> <merged_dict> <merged_lm>")
sys.exit(2)
[basedic, baselm, extdic, extlm, outdic, outlm] = sys.argv[1:7]
@leonmak
leonmak / sox-folder.sh
Created February 7, 2018 19:55
Convert format of all audio files in folder with sox
#!/bin/bash
outputdir="../audio-8k"
mkdir -p $outputdir
for file in **/*.wav
do
filename=$(basename $file)
dir=$(dirname $file)
echo $dir
outputfile="${outputdir}/${file}"
mkdir -p $(dirname $outputfile)
@leonmak
leonmak / setup-jupyter.md
Last active November 16, 2017 22:04
Setup jupyter notebook

Notes on setting up Jupyter notebook on instances

Configuring instance

For gcloud:

  • Specified protocols and ports > Enter tcp:<PORT-NUMBER> for this field if this is the page you see.
  • Targets > All instances in the network.
  • Allowed protocols and ports

For others:

  • Specify ip port if you want to expose one
@leonmak
leonmak / post-install-cuda.sh
Created November 7, 2017 23:08
Post installation of cuda on K80 GPU google cloud ubuntu 16.04 instance
export PATH=/usr/local/cuda-9.0/bin${PATH:+:${PATH}}
export LD_LIBRARY_PATH=/usr/local/cuda-9.0/lib64 ${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
sudo ldconfig /usr/local/cuda/lib64
@leonmak
leonmak / README.md
Last active August 30, 2017 19:52
Install opencv3 for python3 on mac

Summary of installation

  • install XCode, homebrew
  • install python3:
    • brew install python3
    • brew linkapps python3
  • if existing virtual environment is installed, activate it
  • else activate new virtualenv cv (using virtualenvwrapper):
@leonmak
leonmak / wifi_rebooter.sh
Created August 17, 2017 19:35
Raspberry Pi cron wifi restart
#!/bin/bash
# The IP for the server you wish to ping (8.8.8.8 is a public Google DNS server)
SERVER=8.8.8.8
# Only send two pings, sending output to /dev/null
ping -c2 ${SERVER} > /dev/null
# If the return code from ping ($?) is not 0 (meaning there was an error)
if [ $? != 0 ]