Skip to content

Instantly share code, notes, and snippets.

@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 / udfs.py
Created March 4, 2019 03:18
Union Disjoint Find Set
# 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 March 4, 2019 03:18
Union Disjoint Find Set
# 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 March 4, 2019 03:18
Union Disjoint Find Set
# 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 / mac_word_move.plist
Last active May 30, 2019 05:59
iterm2 mac profile - word movement, deletion and pane selection
<?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 / pecs.java
Last active May 26, 2020 06:07
Producer extend Consumer super
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 / Firebase Remote Notifications - IOS Swift 3.md
Last active September 27, 2020 18:01
Firebase Remote Notifications - IOS Swift 3

Rough notes on Remote Notifications (i.e. sent from firebase server/ console > Notifications, not Local Notifications):

  1. New single page app - Select project -> Target capabilities -> Select ON for Background modes(check remote) and push notifications

  2. pod init

   pod 'Firebase/Core'
   pod 'Firebase/Messaging'

then pod install

@leonmak
leonmak / auth.js
Last active May 24, 2021 14:05
chrome extension login id token
// need to use launchWebAuthFlow in chrome extension
// can't use gapi in extension
// https://github.com/google/google-api-javascript-client/issues/64
async function getIdTokenInfo(id_token: string) {
const resp = await fetch(
`https://oauth2.googleapis.com/tokeninfo?id_token=${id_token}`
);
return resp.json();
}
@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 / test.json
Last active January 27, 2022 08:48
test
[
{
"id": "dateOfBirth",
"required": true,
"type": "date",
"question": "生年月日",
"format": "yyyy/MM/dd",
"min": "2008/01/02"
}
]