Edited, memorised or added to reading queue

on 15-Oct-2018 (Mon)

Do you want BuboFlash to help you learning these things? Click here to log in or create user.

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)?
Answer
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

statusnot learnedmeasured difficulty37% [default]last interval [days]               
repetition number in this series0memorised on               scheduled repetition               
scheduled repetition interval               last repetition or drill






Flashcard 3419877543180

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

statusnot learnedmeasured difficulty37% [default]last interval [days]               
repetition number in this series0memorised on               scheduled repetition               
scheduled repetition interval               last repetition or drill
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>>
[...]
Answer
do
done

statusnot learnedmeasured difficulty37% [default]last interval [days]               
repetition number in this series0memorised on               scheduled repetition               
scheduled repetition interval               last repetition or drill
7. Shell Scripting
program flow so that the shell reads particular commands repeatedly. The while command executes a sequence of commands many times. Here is an example ( -le stands for less than or equal): 5 N=1 <span>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 while command executes all the commands between the do and







Flashcard 3419973225740

Question
In linux, in bash scripting, the while loop sytax is:
while [...]
do
<<some lines of code here>>
done
Answer
[condition]
^^^ note that the condition goes inside square brackets, as it is expression being evaluated for truthiness

statusnot learnedmeasured difficulty37% [default]last interval [days]               
repetition number in this series0memorised on               scheduled repetition               
scheduled repetition interval               last repetition or drill
7. Shell Scripting
program flow so that the shell reads particular commands repeatedly. The while command executes a sequence of commands many times. Here is an example ( -le stands for less than or equal): 5 N=1 <span>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 while command executes all the commands between the do and







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).
Answer
#!/bin/bash
n=1
while [ $n -le 4 ]
do
​​​​​​​    echo $n
    n = $[n+1]
done
​​​​​​​

statusnot learnedmeasured difficulty37% [default]last interval [days]               
repetition number in this series0memorised on               scheduled repetition               
scheduled repetition interval               last repetition or drill
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.
Answer
until

statusnot learnedmeasured difficulty37% [default]last interval [days]               
repetition number in this series0memorised on               scheduled repetition               
scheduled repetition interval               last repetition or drill
7. Shell Scripting
(Try counting down from 10 with -ge (greater than or equal).) It is easy to see that shell scripts are extremely powerful, because any kind of command can be executed with conditions and loops. <span>The until statement is identical to while except that the reverse logic is applied. 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 Th







Flashcard 3420017528076

Question
In linux, in bash scripting, for integer comparisons you use things like -le, -gt, -lt, -eq, etc, while for [...] comparisons you use == (or simply =) and !=
Answer
string

statusnot learnedmeasured difficulty37% [default]last interval [days]               
repetition number in this series0memorised on               scheduled repetition               
scheduled repetition interval               last repetition or drill
Other Comparison Operators
Other Comparison Operators Advanced Bash-Scripting Guide: Prev Chapter 7. Tests Next 7.3. Other Comparison Operators A binary comparison operator compares two variables or quantities. Note that integer and string comparison use a different set of operators. integer comparison -eq is equal to if [ "$a"







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.
Answer
for loop

statusnot learnedmeasured difficulty37% [default]last interval [days]               
repetition number in this series0memorised on               scheduled repetition               
scheduled repetition interval               last repetition or drill
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).
Answer
#!/bin/bash

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

statusnot learnedmeasured difficulty37% [default]last interval [days]               
repetition number in this series0memorised on               scheduled repetition               
scheduled repetition interval               last repetition or drill
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)
Answer
;
^^ semi-colon

statusnot learnedmeasured difficulty37% [default]last interval [days]               
repetition number in this series0memorised on               scheduled repetition               
scheduled repetition interval               last repetition or drill
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 [...] / [...]
Answer
if/fi

statusnot learnedmeasured difficulty37% [default]last interval [days]               
repetition number in this series0memorised on               scheduled repetition               
scheduled repetition interval               last repetition or drill
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.
Answer
then

statusnot learnedmeasured difficulty37% [default]last interval [days]               
repetition number in this series0memorised on               scheduled repetition               
scheduled repetition interval               last repetition or drill
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.
Answer
if [ $x -gt $y ]; then
    echo "great"
elif [ $x -lt $y ]; then
    echo "less"
else
    echo "equal"
fi

statusnot learnedmeasured difficulty37% [default]last interval [days]               
repetition number in this series0memorised on               scheduled repetition               
scheduled repetition interval               last repetition or drill
7. Shell Scripting
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 "$X is equal to $Y" <span>fi Now let us create a script that interprets its arguments. Create a new script called backup-lots.sh , containing: #!/bin/sh for i in 0 1 2 3 4 5 6 7 8 9 ; do cp $1 $1.BAK-$i done Now cr







Flashcard 3420040072460

Question
In linux, in bash scripting, how do you print out the first command line argument given when script is run (e.g. if you run "./test.sh hello", "hello" would be printed)
Answer
echo $1
^^^ the $1, prints our the first command line argument, $2 the second, $3 the third, etc

statusnot learnedmeasured difficulty37% [default]last interval [days]               
repetition number in this series0memorised on               scheduled repetition               
scheduled repetition interval               last repetition or drill
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
^^^ not the use of -e to check existance of file, recall $1 is used to access first command line arg

statusnot learnedmeasured difficulty37% [default]last interval [days]               
repetition number in this series0memorised on               scheduled repetition               
scheduled repetition interval               last repetition or drill
7. Shell Scripting
file 10 times with 10 different extensions. As you can see, the variable $1 has a special meaning--it is the first argument on the command-line. Now let's get a little bit more sophisticated ( <span>-e test whether the file exists): 5 10 #!/bin/sh if test "$1" = "" ; then echo "Usage: backup-lots.sh <filename>" exit fi for i in 0 1 2 3 4 5 6 7 8 9 ; do NEW_FILE=$1.BAK-$i if test







Flashcard 3420046363916

Question
In linux, in shell scripting, if you are in a while, until or for loop, and you want looping to stop (i.e. execution to continue after "done" line), you use the [...] keyword
Answer
break

statusnot learnedmeasured difficulty37% [default]last interval [days]               
repetition number in this series0memorised on               scheduled repetition               
scheduled repetition interval               last repetition or drill
7. Shell Scripting
.sh: **warning** $NEW_FILE" echo " already exists - skipping" else cp $1 $NEW_FILE fi done 7.4 break ing Out of Loops and continue ing A loop that requires premature termination can include the <span>break statement within it: 5 10 #!/bin/sh for i in 0 1 2 3 4 5 6 7 8 9 ; do NEW_FILE=$1.BAK-$i if test -e $NEW_FILE ; then echo "backup-lots.sh: **error** $NEW_FILE" echo " already exists - e







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
Answer
continue

statusnot learnedmeasured difficulty37% [default]last interval [days]               
repetition number in this series0memorised on               scheduled repetition               
scheduled repetition interval               last repetition or drill
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?
Answer
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

statusnot learnedmeasured difficulty37% [default]last interval [days]               
repetition number in this series0memorised on               scheduled repetition               
scheduled repetition interval               last repetition or drill
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
Answer
globbing

statusnot learnedmeasured difficulty37% [default]last interval [days]               
repetition number in this series0memorised on               scheduled repetition               
scheduled repetition interval               last repetition or drill
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

statusnot learnedmeasured difficulty37% [default]last interval [days]               
repetition number in this series0memorised on               scheduled repetition               
scheduled repetition interval               last repetition or drill
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.
Answer
case

statusnot learnedmeasured difficulty37% [default]last interval [days]               
repetition number in this series0memorised on               scheduled repetition               
scheduled repetition interval               last repetition or drill
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".
Answer
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

statusnot learnedmeasured difficulty37% [default]last interval [days]               
repetition number in this series0memorised on               scheduled repetition               
scheduled repetition interval               last repetition or drill
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 [...]
Answer
esac
^^ case in reverse, similar to if/fi

statusnot learnedmeasured difficulty37% [default]last interval [days]               
repetition number in this series0memorised on               scheduled repetition               
scheduled repetition interval               last repetition or drill
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
Answer
;;
^^ double semi-colon

statusnot learnedmeasured difficulty37% [default]last interval [days]               
repetition number in this series0memorised on               scheduled repetition               
scheduled repetition interval               last repetition or drill
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.
Answer
round brackets
i.e. ")", since left one is optional and usually ommitted.

statusnot learnedmeasured difficulty37% [default]last interval [days]               
repetition number in this series0memorised on               scheduled repetition               
scheduled repetition interval               last repetition or drill
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).
Answer
function usage()
{
    echo "usage"
}
^^ note the function keyword
^^ note the function block enclosed in {}

statusnot learnedmeasured difficulty37% [default]last interval [days]               
repetition number in this series0memorised on               scheduled repetition               
scheduled repetition interval               last repetition or drill
7. Shell Scripting
e the same functionality. Function definitions provide a way to group statement blocks into one. A function groups a list of commands and assigns it a name. For example: 5 10 15 20 25 #!/bin/sh <span>function usage () { echo "Usage:" echo " myprog.sh [--test|--help|--version]" } case $1 in --test|-t) echo "you used the --test option" exit 0 ;; --help|-h) usage ;; --version|-v) echo "myprog.s







Flashcard 3420084636940

Question
In linux, you have following function defined in your shell script, how do you call it?
function usage ()
{
        echo "Usage:"
        echo "        myprog.sh [--test|--help|--version]"
}
Answer
usage
^^ note that missing ()!!!

statusnot learnedmeasured difficulty37% [default]last interval [days]               
repetition number in this series0memorised on               scheduled repetition               
scheduled repetition interval               last repetition or drill
7. Shell Scripting
For example: 5 10 15 20 25 #!/bin/sh function usage () { echo "Usage:" echo " myprog.sh [--test|--help|--version]" } case $1 in --test|-t) echo "you used the --test option" exit 0 ;; --help|-h) <span>usage ;; --version|-v) echo "myprog.sh version 0.0.2" exit 0 ;; -*) echo "Error: no such option $1" usage exit 1 ;; esac echo "You typed \"$1\" on the command-line" Wherever the usage keyword







we’ve built an extensive network of points of presence (PoPs) around the world
statusnot read reprioritisations
last reprioritisation on suggested re-reading day
started reading on finished reading on

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




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.

statusnot read reprioritisations
last reprioritisation on suggested re-reading day
started reading on finished reading on

Dropbox traffic infrastructure: Edge network | Dropbox Tech Blog
e can just brute-force through it and get a definitively optimal result instead of the one that can get stuck on a local optimum. GSLB Let’s start with the most important part of the Edge—GSLB. <span>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. The following is a discussion of commonly used GSLB techniques, their pros and cons, and how we use them at Dropbox. BGP anycast Anycast is the easiest loadbalancing method that relies