Skip to content

Instantly share code, notes, and snippets.

View jarrett91's full-sized avatar

Jarrett jarrett91

  • Somewhere in Sunny Singapore
  • 20:59 (UTC +08:00)
View GitHub Profile
@jarrett91
jarrett91 / production.sh
Created September 23, 2016 03:19
Bash script that start up all the application in the node
#!/usr/bin/fish
# Catered and used for production servers only
# Collab
cd ~/collab
npm run build
pm2 start npm -i 0 --no-automation --name collab -- run start
# Collab Dashboard
cd ~/collab-dashboard
Eliom-base-app depends on dev version of Eliom (branch shared react),
and dev version of js_of_ocaml, ojquery, macaque, ocsigen-widgets and reactiveData. Use opam to install it, after pinning the github repositories.
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt/ precise-pgdg main" >> /etc/apt/sources.list.d/postgresql.list'
# Also probably optional but I like to update sources and upgrade
sudo apt-get update
sudo apt-get upgrade
procedure A {
m = 5; //1
call B; // 2
while looper{ //3
if looper then{ //4
p = p * (x+y-z); //5
call B; //6
p = p + q; //7
}
for(int i = 0 ; i < nodes.size(); i++) {
TNode * currentNode = nodes[i];
if(currentNode->getTType() == PLUSN) {
result += "+";
} else if(currentNode->getTType() == MINUSN) {
result += "-";
} else if(currentNode->getTType() == VARN) {
result += "|" + getValue(PKB::getPKB()->getVarTable()->getVarName(getValue(currentNode)));
} else if(currentNode->getTType() == CONSTN) {
result += "|" + getValue(currentNode);
Sample input/output Input
2
3 2
1 -2 3
-1 2 -3
6 4
1 2 4
-2 3 -5
-3 4 -5
-3 5 6
Algorithm for Wildcard Support
Rational: We need to support PQL query such as Uses(a,v) which has 2 unknowns and our current API only accepts 1 unknown which is mostly stmtLine or VarIndex.
Data Structure:
A multimap can be used to store all StmtLine of a certain type and this multimap can be preprocessed during parsing.
Pre-parsing Example:
Currently parsing stmt #7, check stmt root for type. If assign, push 7 into multimap eg. Multimap.insert(ASSIGNN, 7)
So at the end of the preparsing, we can now retrieve all stmt# of the same type by calling
static { // suppress log output from Jetty
try {
Logger.getLogger("org.mortbay.log").setLevel(Level.WARNING);
} catch (Exception ignored) {
}
try {
System.setProperty("org.apache.commons.logging.simplelog.log.org.mortbay.log", "warn");
} catch (Exception ignored) {
}
}
@Test
public void sortAlphabetically() {
clearFile();
assertEquals("Test empty sort should return message",
"nothing to sort", TextBuddy.executeCommand("sort"));
assertEquals("Test whether add function works", "added to " + TEST_FILE
+ ": \"z\"", TextBuddy.executeCommand("add z"));
assertEquals("Test whether add function works", "added to " + TEST_FILE
+ ": \"c\"", TextBuddy.executeCommand("add c"));
/* base case when the tree is empty */
if(expressionTree == null){
return null;
}
/* base case when the tree is a leaf */
if(expressionTree.isLeaf()){
return new BinaryTree<String>(new Node<String>(expressionTree.root.getData()));
}