This file contains hidden or 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
priority_queue<string> pqZtoA; | |
pqZtoA.push("hello"); pqZtoA.push("word"); | |
unordered_map<string, priority_queue<string>> mpZtoA; | |
mpZtoA["key"] = pqZtoA; | |
mpZtoA["key"].push("allen"); | |
while (!mpZtoA["key"].empty()) { | |
cout << mpZtoA["key"].top() << ", "; | |
mpZtoA["key"].pop(); | |
} | |
cout << endl; |
This file contains hidden or 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
string minWindow(string s, string t) { | |
vector<int> hash(128); // ASCII 0-127; | |
int match = 0, start = 0, end = 0; | |
int pos = start, len = INT_MAX; // return s.substr(pos, len); | |
for (char c : t) hash[c]++; | |
while (end < s.length()) { | |
// Means it's one of the char in t | |
if (hash[s[end]] > 0) { match++; } |
This file contains hidden or 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
class Solution { | |
public: | |
int kthGrammar(int N, int K) { | |
if (N == 1 && K == 1) return 0; | |
if (K % 2) { | |
return kthGrammar(N - 1, (K + 1) / 2) ? 1 : 0; | |
} else { | |
return kthGrammar(N - 1, (K + 1) / 2) ? 0 : 1; | |
} |
This file contains hidden or 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
import io.vertx.core.*; | |
public class ConcurrentLoop { | |
private static String runTask(int idx) { | |
System.out.println("run task " + idx + " on " + Thread.currentThread().getName()); | |
long sum = 0; | |
for (long j = 0; j < Long.MAX_VALUE / 1000000000; j++) { | |
sum += 1; |
This file contains hidden or 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
{ | |
"created_at": "Fri Apr 04 05:40:26 +0000 2014", | |
"id": 451957445636534300, | |
"id_str": "451957445636534272", | |
"text": "RT @anneotago: @jendab @chelsea_goulton @LogiBeer88 hoping for a good result this week in #gigatowndun :)", | |
"source": "<a href=\"http://twitter.com/download/iphone\" rel=\"nofollow\">Twitter for iPhone</a>", | |
"truncated": false, | |
"in_reply_to_status_id": null, | |
"in_reply_to_status_id_str": null, | |
"in_reply_to_user_id": null, |
This file contains hidden or 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 | |
wget https://gist.githubusercontent.com/yanhsiah/bd1c59d06f9daf149480182f85d117dd/raw/058cdd4c3511bbd83b1b2368edddc152f2c15c79/.tmux.conf; | |
sudo apt update; sudo apt install -y default-jre default-jdk openjdk-8-jdk maven; | |
sudo add-apt-repository ppa:webupd8team/java; sudo apt-get install -y oracle-java8-installer oracle-java8-set-default; | |
echo "JAVA_HOME=/usr/lib/jvm/java-8-oracle" >> ~/.bash_profile; | |
echo "JRE_HOME=/usr/lib/jvm/java-8-oracle/jre" >> ~/.bash_profile; | |
. ~/.bash_profile; | |
gcloud init; gcloud auth application-default login; | |
git clone https://github.com/GoogleCloudPlatform/cloud-bigtable-examples.git; | |
git clone https://github.com/CloudComputingTeamProject/CaptainMAL-S19.git; |
This file contains hidden or 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
unbind C-b | |
set -g prefix ^A | |
bind a send-prefix | |
# set colors | |
set-window-option -g window-status-current-fg blue | |
set-window-option -g window-status-current-bg yellow | |
set-window-option -g window-status-current-attr default | |
# switch to next window |
This file contains hidden or 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
vector<string> rearrange(vector<int>& baskets); | |
// [ 2 , 1 , 4 , 5 , 3 , empty_basket ] | |
vector<int> baskets = {2,1,4,5,3,0}; | |
vector<string> commands = rearrange(baskets); | |
for (string command : commands) { | |
cout << command << endl; | |
} |
This file contains hidden or 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
https://gist.github.com/alexklibisz/7cffdfe90c97986f8393 | |
https://www.ibm.com/developerworks/cn/linux/thread/posix_thread2/index.html | |
https://github.com/trenskow/TrReadWriteLock |
This file contains hidden or 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
- (NSArray<NSIndexPath *> *)indexPathsFromItems:(NSArray *)items section:(NSUInteger)section | |
{ | |
NSMutableArray *indexPaths = [NSMutableArray arrayWithCapacity:items.count]; | |
[items enumerateObjectsUsingBlock:^(id tag, NSUInteger idx, BOOL *stop) { | |
[indexPaths addObject:[NSIndexPath indexPathForItem:idx inSection:section]]; | |
}]; | |
return indexPaths; | |
} | |
[self.collectionView performBatchUpdates:^{ |
NewerOlder