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 / 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
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 / 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
@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