Instantly share code, notes, and snippets.

🏠
Working from home

# Minh Pham phamtm

🏠
Working from home
Last active September 17, 2015 10:08
A solver for Sudoku
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; }
Last active September 17, 2015 10:12
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 #include 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);
Created October 19, 2015 01:43
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)
Last active May 30, 2016 06:49
Permutation generation methods
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
Last active June 4, 2016 00:16
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
Created April 4, 2016 03:48
cassandra-docker-start.sh
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
Last active January 2, 2017 09:14
Promise - Simple implementation

### Promise implementation

• 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` and `onRejected` return OR if no handler resolve with the same value as the parent

• A promise should NEVER be resolved with another promise.

### Who wait for whom?

Last active January 2, 2017 09:19
malloc implementation
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 #include 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;
Created January 23, 2017 02:00
Regular expression matcher
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