-
Only the original promise (created with new) can control when it will resolve/reject (callee decide)
-
Each subsequent promise (subscriber) created with then will either resolve when the
onFulfilled
andonRejected
return OR if no handler resolve with the same value as the parent -
A promise should NEVER be resolved with another promise.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package mp; | |
import java.util.ArrayDeque; | |
import java.util.Deque; | |
public class ToPostfix { | |
/** | |
* Don't handle error | |
* missing: escape char |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <sys/type.h> | |
#include <unistd.h> | |
void* malloc(size_t size) { | |
void *p; | |
p = sbrk(0); // Initially, `break` is positioned at start of heap | |
if (sbrk(size) == (void*) -1) | |
return NULL; | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def swap(ar, i, j): | |
tmp = ar[i] | |
ar[i] = ar[j] | |
ar[j] = tmp | |
def genheapperm(ar, n): | |
if n == 1: | |
print ar | |
return |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
!#/bin/bash | |
# 7000-7001/tcp, 7199/tcp, 9042/tcp, 9160/tcp | |
docker run --name c33 -p 7000:7000 -p 7001:7001 -p 7199:7199 -p 9042:9042 -p 9160:9160 -d cassandra:3.3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
import codecs | |
import cPickle as pickle | |
import os | |
import re | |
import string | |
PUNCTUATIONS = string.punctuation + u'“' + u'”' + u'…' | |
PATTERN_D_REPLACE = re.compile(r'Đ', flags=re.UNICODE) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class SudokuSolver { | |
int[] board = new int[81]; | |
char[] in = null; | |
boolean[][] findLimits() { | |
boolean[][] ok = new boolean[81][9]; | |
for (int i = 0; i < 81; i++) { | |
for (int j = 0; j < 9; j++) { | |
ok[i][j] = true; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Bash colors # | |
############### | |
txtblk='\e[0;30m' # Black - Regular | |
txtred='\e[0;31m' # Red | |
txtgrn='\e[0;32m' # Green | |
txtylw='\e[0;33m' # Yellow | |
txtblu='\e[0;34m' # Blue | |
txtpur='\e[0;35m' # Purple | |
txtcyn='\e[0;36m' # Cyan | |
txtwht='\e[0;37m' # White |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <algorithm> | |
using namespace std; | |
/* print the fractions of denominator <= n between n1/d1 and n2/d2 */ | |
void genfrac(int n, int n1, int d1, int n2, int d2) { | |
if (d1 + d2 > n) return; | |
genfrac(n, n1, d1, n1 + n2, d1 + d2); | |
cout << n1 + n2 << "/" << d1 + d2 << "\n"; | |
genfrac(n, n1 + n2, d1 + d2, n2, d2); |