COMP9311 Extension

COMP9311 extension

This is an extension knowledge about COMP9311

Auto deploy PostgreSQL

You can find the shell script here. You can execute the following command in grieg server to deploy the SQL server.

1
2
3
chmod +x deploy.sh

./deploy.sh

The code in deploy.sh is:

1
2
3
4
5
6
7
8
9
10
11
user=$(whoami)

priv srvr

~cs9311/bin/pginit

echo "if [ \`hostname\` = \"grieg\" ]
then
source /srvr/$user/env
fi
" >> ~/.bash_profile

Backgroud information

  • grieg means a server named grieg

Login CSE/GRIEG

You can log in to cse server by using the following command:

1
ssh ZID@cse.unsw.edu.au

PS: Please replace ZID with your zid, and the password is same as your zid passowrd (typing the password in terminal is unvisitable).

After log in to the cse server, then you can log in to grieg server by using the following command:

1
ssh grieg

Also, you can log in to grieg directly by using the following command:

1
ssh ZID@grieg.cse.unsw.edu.au

PS: Please replace ZID with your zid, and the password is same as your zid passowrd (typing the password in terminal is unvisitable).

Log in to cse server without password

You can log in to cse server without password by uploading ssh-key into the server. If you did not have a ssh-key, you can generate a ssh-key by using the following command (please execute these commands in personal computer) :

1
ssh-keygen

Then you can use ssh-copy-id to copy your key to server:

1
ssh-copy-id ZID@cse.unsw.edu.au

PS: Please replace ZID with your zid.

You can find more details here

.bash_profile settings

When you logging in to cse server, you may can not find these files (.bash_profile, .bashrc or .profile). You can use touch command to create a empty file in home directory.

1
2
cd ~  // switch the directory into home directory
touch .bash_profile

Then you can find the .bash_profile file by using:

1
ls -al

Then you can add the following config code into .bash_profile:

1
2
3
4
if [ `hostname` = "grieg" ]
then
source /srvr/ZID/env
fi

PS: Please replace ZID with your zid.

Terminal display

Several students asked how to modify the Linux terminal display. After logging in to grieg server, on the left hand side it looks like:

1
grieg %

It only shows the hostname which is very inconvenient when we want to know which folder we are in. The following commands can help you to solve the issue:

  1. Log in to grieg server
  2. Add this line export PS1="\u@\h \w $ " into the .bash_profile file
  3. Execute source ~/.bash_profile

Then the terminal display should like:

1
ZID@grieg ~ $

Where ~ means home directory.

You can find more details here

Upload files to cse server

Use scp (srcure copy) command can upload files/directory from local (Linux or Mac system) to remote cse server:

1
scp [source file] [username]@[destination server]:/path/

For example:

1
scp schema.sql ZID@cse.unsw.edu.au:~

Which means upload the schema.sql file into your cse server home directory.

If you want to upload a directory you can use:

1
scp -r [source directory] [username]@[destination server]:/path/

If you are using windows system, you can have a look winscp. And UNSW gives a guideline about that

SSH config

After finished configuration of log in without password. (section 1.3). You can config the ssh config file like:

1
2
3
4
Host cse
HostName cse.unsw.edu.au
Port 22
User ZID

Where ZID is your zid. Now, you can use ssh cse instead of ssh zid@cse.unsw.edu.au.

Lab 02

The lab 02 slides is available here, if you have any issues, please email me.

Lab03

Step up

  1. Download the weblog.zip by using wget command in the terminal: wget https://www.cse.unsw.edu.au/~cs9311/21T1/lab/04/weblog.zip

  2. Unzip the weblog.zip files: unzip weblog.zip

  3. Create a database for this lab: createdb weblog

  4. Load SQL file

    1. switch to the weblog directory: cd weblog

    2. load schema: psql weblog -f schema.sql

    3. load data sql file:

      1
      2
      3
      psql weblog -f Hosts.sql
      psql weblog -f Sessions.sql
      psql weblog -f Accesses.sql

Regex online test regex

K-Core decomposition

Given a graph G, the k-core of G can be computed by recursively deleting every node and its adjacent edges if its degree is less than k.
The python code of k-core as shown in the following part.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import copy

edges = {
'a': ['b', 'c', 'd'],
'b': ['a', 'c', 'd'],
'c': ['a', 'b', 'd'],
'd': ['a', 'b', 'c'],
}


def compute_k_core(k, edges):
deleted_nodes = []

while True:
for node in edges:
if len(edges[node]) < k:
deleted_nodes.append(node)

if len(deleted_nodes) == 0:
break

for u in deleted_nodes:
if u not in edges:
continue
for v in edges[u]:
edges[v].remove(u)

del edges[u]
deleted_nodes.clear()

print(", ".join(edges.keys()))
for u in edges:
for v in edges[u]:
print("{}, {}".format(u,v))


if __name__ == '__main__':
compute_k_core(2, edges=copy.deepcopy(edges))
----- End Thanks for reading-----