Skip to content

Instantly share code, notes, and snippets.

@leonmak
leonmak / pecs.java
Last active May 26, 2020
Producer extend Consumer super
View pecs.java
import java.util.ArrayList;
import java.util.List;
class Scratch {
class Shark {
private final String name = "Sharkie";
public String getName() { return name; }
}// A
class HammerShark extends Shark{
@leonmak
leonmak / mac_word_move.plist
Last active May 30, 2019
iterm2 mac profile - word movement, deletion and pane selection
View mac_word_move.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>AlternateMouseScroll</key>
<true/>
<key>AppleAntiAliasingThreshold</key>
<integer>1</integer>
<key>AppleScrollAnimationEnabled</key>
<integer>0</integer>
@leonmak
leonmak / udfs.py
Created Mar 4, 2019
Union Disjoint Find Set
View udfs.py
# if not root, find parent, set parent, return parent
p = map(chr, range(n))
def find(p, x):
if p[x] != x:
p[x] = find(p, p[x])
return p[x]
def union(p, i, j):
pi, pj = find(p, i), find(p, j)
@leonmak
leonmak / udfs.py
Created Mar 4, 2019
Union Disjoint Find Set
View udfs.py
# if not root, find parent, set parent, return parent
p = map(chr, range(n))
def find(p, x):
if p[x] != x:
p[x] = find(p, p[x])
return p[x]
def union(p, i, j):
pi, pj = find(p, i), find(p, j)
@leonmak
leonmak / udfs.py
Created Mar 4, 2019
Union Disjoint Find Set
View udfs.py
# if not root, find parent, set parent, return parent
p = map(chr, range(n))
def find(p, x):
if p[x] != x:
p[x] = find(p, p[x])
return p[x]
def union(p, i, j):
pi, pj = find(p, i), find(p, j)
@leonmak
leonmak / lc-locked.csv
Created Feb 1, 2019
leetcode locked questions
View lc-locked.csv
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 Jan 30, 2019
269. Alien Dictionary
View alien_dict.py
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 Nov 2, 2018
Setup ssh in remote VM
View setup.md

In VM

sudo adduser ubuntu
sudo su ubuntu
cd /home/ubuntu

mkdir .ssh
chmod 700 .ssh

cd .ssh
@leonmak
leonmak / set_gopath.sh
Created Jun 11, 2018
go environment setup for gotchas
View set_gopath.sh
# . 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
View merge_word_dict.py
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]