# on 15-Oct-2018 (Mon)

#### Flashcard 3419845823756

Question
In python 3, what is the easy way to sort a list, using "sorted" method, using a custom comparison function (for example, how to sort release_numbers = [1.2, 4.4.4, 1.2.1], using custom "compare" function that compares 1.2 to 1.2.1)?
sorted(release_numbers, key=functools.cmp_to_key(compare))
^^ note, in python 3, sorted does not have the cmp argument so you have to use the key argument via the functools.cmp_to_key conversion method)
^^ note 2, make sure you have "import functools" in your code

status measured difficulty not learned 37% [default] 0

#### Flashcard 3419877543180

Question
In Linux, for the vi editor, what key do you press to exit from control mode to input mode (and viceversa)?
ESC

status measured difficulty not learned 37% [default] 0
6. Editing Text Files
a little more about other, more user-friendly editors. Type simply, vi <filename> to edit any file, or the compatible, but more advanced vim <filename> To exit vi , press , then the <span>key sequence :q! and then press . vi has a short tutorial which should get you going in 20 minutes. If you get bored in the middle, you can skip it and learn vi as you need to edit things.

#### Flashcard 3419967982860

Question
In linux, in bash shell scripting, the while loop syntax is:
while [condition]
[...]
<<some lines of code here>>
[...]
do
done

status measured difficulty not learned 37% [default] 0
7. Shell Scripting

#### Flashcard 3419976371468

Question
In Linux, write a simple bash script that print the numbers from 1 to 4 out to the stdout in a loop (to demonstrate your knowledge of while loop).
#!/bin/bash
n=1
while [ $n -le 4 ] do ​​​​​​​ echo$n
n = $[n+1] done ​​​​​​​ status measured difficulty not learned 37% [default] 0 7. Shell Scripting ere is an example ( -le stands for less than or equal): 5 N=1 while test "$N" -le "10" do echo "Number $N" N=$[N+1] done The N=1 creates a variable called N and places the number 1 into it. The <span>while command executes all the commands between the do and the done repetitively until the test condition is no longer true (i.e., until N is greater than 10 ). The -le stands for less than o

#### Flashcard 3419979517196

Question
In linux, in bash scripting, the [...] statement is identical to the while statement except that the reverse logic is applied in the condition clause.
until

status measured difficulty not learned 37% [default] 0
7. Shell Scripting

#### Flashcard 3420021198092

Question
In linux, in shell scripting, the [...] construct is often used to take actions on a bunch of files, one at a time.
for loop

status measured difficulty not learned 37% [default] 0
7. Shell Scripting
plied. The same functionality can be achieved with -gt (greater than): N=1 ; until test "$N" -gt "10"; do echo "Number$N"; N=$[N+1] ; done 7.3 Looping to Repeat Commands: the for Statement The <span>for command also allows execution of commands multiple times. It works like this: 5 for i in cows sheep chickens pigs do echo "$i is a farm animal" done echo -e "but\nGNUs are not farm anim

#### Flashcard 3420024343820

Question
In linux, write simple bash script that goes through and prints name of all files in current directory (to show your knowledge of for loop).
#!/bin/bash

for file in $(ls) do echo$file
done
[default - edit me]

status measured difficulty not learned 37% [default] 0
7. Shell Scripting
est "$N" -gt "10"; do echo "Number$N"; N=$[N+1] ; done 7.3 Looping to Repeat Commands: the for Statement The for command also allows execution of commands multiple times. It works like this: 5 <span>for i in cows sheep chickens pigs do echo "$i is a farm animal" done echo -e "but\nGNUs are not farm animals" The for command takes each string after the in , and executes the lines between

#### Flashcard 3420027489548

Question
In linux, in bash scripting, a [...] is used to put two lines of code on the same line (usually used in while/do/done and if/then/fi cluases to combine the while/do and if/then in one line)
;
^^ semi-colon

status measured difficulty not learned 37% [default] 0
7. Shell Scripting
ion is met ( -gt stands for greater than, -lt stands for less than). The if command executes all the lines between the if and the fi (if'' spelled backwards). 5 X=10 Y=5 if test "$X" -gt "$Y" <span>; then echo "$X is greater than$Y" fi The if command in its full form can contain as much as: 5 X=10 Y=5 if test "$X" -gt "$Y" ; then echo "$X is greater than$Y" elif test "$X" -lt "$Y"

#### Flashcard 3420030635276

Question
In linux, in bash scripting, while loops are inclosed in do/done, while if/else statements are enclosed in [...] / [...]
if/fi

status measured difficulty not learned 37% [default] 0
7. Shell Scripting
lt stands for less than). The if command executes all the lines between the if and the fi (if'' spelled backwards). 5 X=10 Y=5 if test "$X" -gt "$Y" ; then echo "$X is greater than$Y" fi The <span>if command in its full form can contain as much as: 5 X=10 Y=5 if test "$X" -gt "$Y" ; then echo "$X is greater than$Y" elif test "$X" -lt "$Y" ; then echo "$X is less than$Y" else echo

#### Flashcard 3420033781004

Question
In linux, in bash scripting, for the if/else statements, if and elif have the [...] keyword after the condition clause while else does not have it.
then

status measured difficulty not learned 37% [default] 0
7. Shell Scripting
fi (if'' spelled backwards). 5 X=10 Y=5 if test "$X" -gt "$Y" ; then echo "$X is greater than$Y" fi The if command in its full form can contain as much as: 5 X=10 Y=5 if test "$X" -gt "$Y" ; <span>then echo "$X is greater than$Y" elif test "$X" -lt "$Y" ; then echo "$X is less than$Y" else echo "$X is equal to$Y" fi Now let us create a script that interprets its arguments. Create a

#### Flashcard 3420036926732

Question
In linux, in bash scripting, write if cluase where you already have two vars, x and y, and you print "great" if x is greater than y, "less" if x is smaller than y, and "equal" otherwise.
if [ $x -gt$y ]; then
echo "great"
elif [ $x -lt$y ]; then
echo "less"
else
echo "equal"
fi

status measured difficulty not learned 37% [default] 0
7. Shell Scripting
^^^ the $1, prints our the first command line argument,$2 the second, $3 the third, etc status measured difficulty not learned 37% [default] 0 7. Shell Scripting Now create a file important_data with anything in it and then run ./backup-lots.sh important_data , which will copy the file 10 times with 10 different extensions. As you can see, the variable <span>$1 has a special meaning--it is the first argument on the command-line. Now let's get a little bit more sophisticated ( -e test whether the file exists): 5 10 #!/bin/sh if test "$1" = "" ; #### Flashcard 3420043218188 Question In linux, write simple bash script that takes file name as command line argument, and prints out that file name ONLY if that file exists in the current directory (e.g. running "tests.sh test.txt" would print "yes" only if file test.txt exists). Answer #!/bin/bash if [ -e$1 ]; then
echo "yes"
fi

#### Flashcard 3420049509644

Question
In linux, in bash scripting, if you are in while/until/for loop and you wan the current loop iteration to end and just go to the next iteration (i.e. start at top of loop), you use the [...] keyword
continue

status measured difficulty not learned 37% [default] 0
7. Shell Scripting
causes program execution to break out of both loops; and so on for values above 2 . The continue statement is also useful for terminating the current iteration of the loop. This means that if a <span>continue statement is encountered, execution will immediately continue from the top of the loop, thus ignoring the remainder of the body of the loop: 5 10 #!/bin/sh for i in 0 1 2 3 4 5 6 7 8 9

#### Flashcard 3420052655372

Question
In linux, in bash scripting, what is the difference between the break and continue keywords used in loops?
break will completely exit the loop (and go to after the "done" keyword) while continue will break out of just the current iteration of loop and go to top of loop for next iteration

status measured difficulty not learned 37% [default] 0
7. Shell Scripting
3 4 5 6 7 8 9 ; do NEW_FILE=$1.BAK-$i if test -e $NEW_FILE ; then echo "backup-lots.sh: **warning**$NEW_FILE" echo " already exists - skipping" continue fi cp $1$NEW_FILE done Note that both <span>break and continue work inside for , while , and until loops. 7.5 Looping Over Glob Expressions We know that the shell can expand file names when given wildcards. For instance, we can type ls *.txt to lis

#### Flashcard 3420057111820

Question
In linux, bash carries out file name expansions (e.g. *.txt will represent all files that end in .txt"), and this is a process called [...] ing
globbing

status measured difficulty not learned 37% [default] 0
Globbing
Chapter 18. Regular Expressions Next 18.2. Globbing Bash itself cannot recognize Regular Expressions. Inside scripts, it is commands and utilities -- such as sed and awk -- that interpret RE's. <span>Bash does carry out filename expansion [1] -- a process known as globbing -- but this does not use the standard RE set. Instead, globbing recognizes and expands wild cards. Globbing interprets the standard wild card characters [2] -- * and ?, character lists

#### Flashcard 3420060781836

Question
In linux, in bash scripting, you can use the "for in" loop to loop over files, without using the $(ls) command expansion. For example rewrite the following without using$(ls) command expansion:
for file in $(ls *.txt); do echo "found another text file!" done Answer for file in *.txt; do echo "found another text file!" done status measured difficulty not learned 37% [default] 0 7. Shell Scripting the shell can expand file names when given wildcards. For instance, we can type ls *.txt to list all files ending with .txt . This applies equally well in any situation, for instance: #!/bin/sh <span>for i in *.txt ; do echo "found a file:"$i done The *.txt is expanded to all matching files. These files are searched for in the current directory. If you include an absolute path then the shell will search in that directory: #!/bin/

#### Flashcard 3420065238284

Question
In linux, in bash scripting, the [...] statement can execute commands based on a word pattern matching decision.
case

status measured difficulty not learned 37% [default] 0
The case statement [Bash Hackers Wiki]
or ;& or ;;& in Bash 4 [(] <PATTERN2> ) <LIST2> ;; [(] <PATTERN3> | <PATTERN4> ) <LIST3-4> ;; ... [(] <PATTERNn>) <LISTn> [;;] esac Description <span>The case-statement can execute commands based on a pattern matching decision. The word <WORD> is matched against every pattern <PATTERNn> and on a match, the associated list <LISTn> is executed. Every commandlist is terminated by ;;. This rule

#### Flashcard 3420068908300

Question
In linux, write simple bash script, using case statement to check for first command line argument, if it is --help or -h print "help", if it is --version or -v print "1.0", otherwise print "unkown choice".
case $1 in --help|-h) echo "help" ;; --version|-v) echo "1.0" ;; *) echo "unknown choice" ;; esac ^^ note the esac at end ^^ note the ;; seperating each option statement ^^ note the ) that is each pattern matching condition, also note that the left ( is missing/optional ^^ note the * catch all glob/pattern for the final condition status measured difficulty not learned 37% [default] 0 7. Shell Scripting ng files and expand an absolute path. 7.6 The case Statement The case statement can make a potentially complicated program very short. It is best explained with an example. 5 10 15 20 #!/bin/sh <span>case$1 in --test|-t) echo "you used the --test option" exit 0 ;; --help|-h) echo "Usage:" echo " myprog.sh [--test|--help|--version]" exit 0 ;; --version|-v) echo "myprog.sh version 0.0.1" exit 0 ;; -*) echo "No such option $1" echo "Usage:" echo " myprog.sh [--test|--help|--version]" exit 1 ;; esac echo "You typed \"$1\" on the command-line" Above you can see that we are trying to process the first argument to a program. It can be one of several options, so using if statements wil

#### Flashcard 3420072054028

Question
In linux, in bash scripting, for the case statement, the entire block starts with keyword case and ends with keyword [...]
esac
^^ case in reverse, similar to if/fi

status measured difficulty not learned 37% [default] 0
7. Shell Scripting
sh for i in /usr/doc/*/*.txt ; do echo "found a file:" $i done This example demonstrates the shell's ability to search for matching files and expand an absolute path. 7.6 The case Statement The <span>case statement can make a potentially complicated program very short. It is best explained with an example. 5 10 15 20 #!/bin/sh case$1 in --test|-t) echo "you used the --test option" exit

#### Flashcard 3420075199756

Question
In linux, in bash scripting, when you have a case statement block, each condition block must close with the [...] syntax
;;
^^ double semi-colon

status measured difficulty not learned 37% [default] 0
7. Shell Scripting
sh for i in /usr/doc/*/*.txt ; do echo "found a file:" $i done This example demonstrates the shell's ability to search for matching files and expand an absolute path. 7.6 The case Statement The <span>case statement can make a potentially complicated program very short. It is best explained with an example. 5 10 15 20 #!/bin/sh case$1 in --test|-t) echo "you used the --test option" exit 0 ;; --hel

#### Flashcard 3420078345484

Question
In linux, in bash scripts, when using case statement, for each condition clause, the condition is enclosed in [...] , where the left one is optional.
round brackets
i.e. ")", since left one is optional and usually ommitted.

status measured difficulty not learned 37% [default] 0
7. Shell Scripting
sh for i in /usr/doc/*/*.txt ; do echo "found a file:" $i done This example demonstrates the shell's ability to search for matching files and expand an absolute path. 7.6 The case Statement The <span>case statement can make a potentially complicated program very short. It is best explained with an example. 5 10 15 20 #!/bin/sh case$1 in --test|-t) echo "you used the --test option" exit 0 ;; --hel

#### Flashcard 3420081491212

Question
In linux, write simple shell script function called usage that simply prints our "usage" when called (note: this excersice just checks your recall of function syntax in bash scripting).
function usage()
{
echo "usage"
}
^^ note the function keyword
^^ note the function block enclosed in {}

status measured difficulty not learned 37% [default] 0
7. Shell Scripting

#### Annotation 3420113997068

 we’ve built an extensive network of points of presence (PoPs) around the world

Dropbox traffic infrastructure: Edge network | Dropbox Tech Blog
tered users who trust us with exabytes of data and petabytes of corresponding metadata. For the Traffic team this means millions of HTTP requests and terabits of traffic. To support all of that <span>we’ve built an extensive network of points of presence (PoPs) around the world that we call Edge. Why do we need Edge? Many of the readers know the basic idea of CDNs: terminating TCP and TLS connections closer to the user leads to improved user experience because

#### Annotation 3420117142796

 GSLB is responsible for loadbalancing users across PoPs. That usually means sending each user to the closest PoP, unless it is over capacity or under maintenance. GSLB is called the “most important part” here because if it misroutes users to the suboptimal PoPs frequently, then it makes the Edge network useless, and potentially even harms performance.