Skip to content

Instantly share code, notes, and snippets.

// Simple sample for explaining the resolve and reject of Promise
async function test(flag) {
//
return new Promise((resolve, reject)=>{
if(flag) {
resolve(0)
} else {
reject(-1)
@openroc
openroc / tmux.conf
Last active September 26, 2017 03:12
.tmux.conf
#!/usr/local/bin/tmux
# vim: syntax=tmux
# set 2nd bind key (like screen)
set -g prefix2 C-a
#
bind C-b last-window
# reload config
@openroc
openroc / backup.sh
Last active September 26, 2017 03:11
backup.sh for mackup
#!/bin/bash
# quick back file or dir via ln into Dropbox for syncing
BACKUPDIR=~/Dropbox/Mackup
PWD=`pwd`
function backup() {
@openroc
openroc / MinStack.py
Last active September 26, 2017 03:10
MinStack(Python)
class MinStack:
def __init__(self):
self.L=[]
self.count = 0
def pop(self):
self.count -= 1
return self.L.pop()[0]
def push(self,x):
minval = self.L[-1][1] if self.count > 0 else x
d = (x,x) if x < minval else (x, minval)
@openroc
openroc / DocumentDict.py
Last active October 18, 2021 21:58
DocumentDict (Python)
#!/user/bin/python
import json
class DocumentBase(object):
def traversal_for_init_dict(self, items):
for k in items:
if type(items[k]) == dict:
setattr(self, k, DocumentDict(**items[k]))
elif type(items[k]) == list: