Skip to content

Instantly share code, notes, and snippets.

View gchiam's full-sized avatar

Gordon Chiam gchiam

View GitHub Profile
@gchiam
gchiam / cm.py
Created May 2, 2017 06:11
context manager
import contextlib
@contextlib.contextmanager
def cm():
info = {}
print 'start'
yield info
print 'end', info
def fibonaci_recursive(n):
if n <= 2:
return 1
return fibonaci_recursive(n-1) + fibonaci_recursive(n-2)
def fibonaci_dp_1(n):
memo = {}
for i in range(1, n + 1):
"""Maximum Subarray Problem
The maximum subarray problem is the task of finding the largest
possible sum of a contiguous subarray, within a given one-dimensional
array A[1…n] of numbers.
https://link.medium.com/MPXDJMtDMU
"""
def maxsubarray(array):
"""Binary Tree: Longest path
https://link.medium.com/tHhd8C0KOU
"""
class Node(object):
def __init__(self, value):
self.value = value
self.left =
self.right = None
import functools
def merge_or_append(ranges, element):
if ranges and ranges[-1][0] <= element[0] <= ranges[-1][1]:
ranges[-1] = (ranges[-1][0], max(ranges[-1][1], element[1]))
else:
ranges.append(element)
return ranges
@font-face {
font-family: "Fura Code Nerd";
font-weight: normal;
src: url("https://cdn.jsdelivr.net/gh/ryanoasis/[email protected]/patched-fonts/FiraCode/Light/complete/Fura%20Code%20Light%20Nerd%20Font%20Complete%20Mono.otf") format('opentype');
}
@font-face {
font-family: "Fura Code Nerd";
font-weight: bold;
src: url("https://cdn.jsdelivr.net/gh/ryanoasis/[email protected]/patched-fonts/FiraCode/Medium/complete/Fura%20Code%20Medium%20Nerd%20Font%20Complete%20Mono.otf?raw=true") format('opentype');
}
@font-face {
font-family: "Iosevka Nerd";
font-weight: normal;
font-style: normal;
src: url("https://cdn.jsdelivr.net/gh/ryanoasis/[email protected]/patched-fonts/Iosevka/Extra-Light/complete/Iosevka%20Term%20Extralight%20Nerd%20Font%20Complete%20Mono.ttf") format('truetype');
}
@font-face {
font-family: "Iosevka Nerd";
font-weight: normal;
font-style: italic;
MAPPING = {
'{': '}',
'(': ')',
'[': ']',
}
def is_open(c):
return c in MAPPING
@gchiam
gchiam / resouce.java
Created August 18, 2020 04:07
Execute Around Method Pattern - Resource
/* Extracted from https://www.youtube.com/watch?v=xF0rupA848E */
class Resource {
public Resource() {
System.out.println("created...");
}
public Resource op1() {
System.out.println("op1...");
return this;
@gchiam
gchiam / Crostini_font.js
Created September 6, 2020 09:12
Set custom don't under Crostini
term_.prefs_.set('font-family', '"Iosevka Nerd", monospace');
term_.prefs_.set('user-css', 'https://cdn.jsdelivr.net/gh/gchiam/[email protected]/css/iosevka/iosevka-light-nerd-font.css');