Skip to content

Instantly share code, notes, and snippets.

@leonmak
leonmak / food-expired.json
Last active June 24, 2017 06:45
scrape all the bad food!
{"food":[{"freezer":"","name":"abruzzese sausage, dry - unopened package","pantry":"4-6 weeks","refrigerator":"6 months","shortName":"abruzzese sausage"},{"freezer":"1-2 months","name":"abruzzese sausage, dry - opened package","pantry":"","refrigerator":"2-3 weeks","shortName":"abruzzese sausage"},{"freezer":"","name":"alfalfa sprouts - fresh, raw","pantry":"","refrigerator":"2-3 days","shortName":"alfalfa sprouts"},{"freezer":"4-6 months","name":"alfredo sauce - homemade","pantry":"","refrigerator":"3-4 days","shortName":"alfredo sauce"},{"freezer":"","name":"allspice, ground, dried, commercially bottled or purchased in bulk - unopened or opened","pantry":"3-4 years","refrigerator":"","shortName":"allspice"},{"freezer":"","name":"allspice, whole, dried, commercially bottled or purchased in bulk - unopened or opened","pantry":"4 years","refrigerator":"","shortName":"allspice"},{"freezer":"","name":"almond extract, pure or imitation, commercially bottled - unopened or opened","pantry":"4 years","refrigerator":
@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 / FB Login IOS.md
Created August 10, 2017 21:26
FB Login on iOS - Swift 3
  1. Pod file
pod 'FBSDKCoreKit'
pod 'FBSDKShareKit'
pod 'FBSDKLoginKit'
  1. AppDelegate
@leonmak
leonmak / Local Notifications - iOS Swift 3.md
Last active August 10, 2017 21:30
Local Notifications - iOS Swift 3

Local notifications

  1. ViewController
import UserNotifications
class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
 UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound, .badge], completionHandler: {didAllow, error in })
@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 ]
@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 / 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 / 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 / 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)
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]