Skip to content

Instantly share code, notes, and snippets.

class Solution:
def searchRange(self, nums, target):
"""
:type nums: List[int]
:type target: int
:rtype: List[int]
"""
def searchOccurrence(nums, target, isFirst):
N = len(nums)
if N == 1:
class Solution(object):
def search(self, nums, target):
"""
:type nums: List[int]
:type target: int
:rtype: int
"""
start, end = 0, len(nums)-1
while start <= end:
mid = (start+end)//2
class Solution:
def maxSlidingWindow(self, nums, k):
"""
:type nums: List[int]
:type k: int
:rtype: List[int]
"""
output = []
@jovianlin
jovianlin / LeetCode_LongestAbsoluteFilePath.py
Created December 5, 2018 03:43
Longest Absolute File Path
class Solution:
def lengthLongestPath(self, input):
"""
:type input: str
:rtype: int
"""
def is_dir(val):
return False if '.' in val else True
@jovianlin
jovianlin / eng-fra.txt
Created February 10, 2018 14:49
eng-fra.txt
This file has been truncated, but you can view the full file.
Go. Va !
Run! Cours !
Run! Courez !
Wow! Ça alors !
Fire! Au feu !
Help! À l'aide !
Jump. Saute.
Stop! Ça suffit !
Stop! Stop !
Stop! Arrête-toi !
# reference: https://hub.docker.com/_/ubuntu/
FROM ubuntu:16.04
# Adds metadata to the image as a key value pair example LABEL version="1.0"
LABEL maintainer="Hamel Husain <youremail@gmail.com>"
# Set environment variables
ENV LANG=C.UTF-8 LC_ALL=C.UTF-8
RUN apt-get update --fix-missing && apt-get install -y wget bzip2 ca-certificates \
@jovianlin
jovianlin / load_glove_embeddings.py
Created January 11, 2018 08:26
load_glove_embeddings
# coding: utf-8
import numpy as np
def load_glove_embeddings(fp, embedding_dim, include_empty_char=True):
"""
Loads pre-trained word embeddings (GloVe embeddings)
Inputs: - fp: filepath of pre-trained glove embeddings
- embedding_dim: dimension of each vector embedding
@jovianlin
jovianlin / du.sh
Created January 10, 2018 02:00
[Linux/Ubuntu] Top level directory size/usage only
sudo du -h --max-depth=1 /home
@jovianlin
jovianlin / sg_location_data_demo.html
Created December 7, 2017 10:54
SG Location Data Demo
<!DOCTYPE html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<script>L_PREFER_CANVAS = false; L_NO_TOUCH = false; L_DISABLE_3D = false;</script>
<script src="https://cdn.jsdelivr.net/npm/leaflet@1.2.0/dist/leaflet.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Leaflet.awesome-markers/2.0.2/leaflet.awesome-markers.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/leaflet@1.2.0/dist/leaflet.css" />
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" />
@jovianlin
jovianlin / SVY21.py
Last active November 25, 2022 10:49
Singapore has a special coordinate system called SVY21. This converts the special coordinates to lat/lng.
#! /usr/bin/python
import math
class SVY21:
# Ref: http://www.linz.govt.nz/geodetic/conversion-coordinates/projection-conversions/transverse-mercator-preliminary-computations/index.aspx
# WGS84 Datum
a = 6378137
f = 1 / 298.257223563