# on 17-Oct-2018 (Wed)

#### Flashcard 3412319931660

Question
In python, you have dictionary, d = {'a':1, 'b':2}, how do you delete item with key 'a' from d, and get the value of 'a' returned, all in one command (and do it in safe way so None is returned if key 'a' does not exist)?
d.pop('a', None)

status measured difficulty not learned 37% [default] 0

#### pdf

cannot see any pdfs

#### 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 3420100627724

Question
In linux, write simple bash script that prints out all the command line arguments of the script no matter how many or few (e.g. if you run script test.sh as "./tests.sh one two three", it will print out "one\n two\n three")
#!/bin/bash
while [ "$1" != "" ]; do echo$1
shift
done
^^ note the use of shift
^^ also note the "$1" in the conditional clause of while loop (line 2) wrapped in "", as this is needed for string comparison!!! status measured difficulty not learned 37% [default] 0 7. Shell Scripting d argument is: birds Now we need to loop through each argument and decide what to do with it. A script like for i in$1 $2$3 $4 ; do <statments> done doesn't give us much flexibilty. The <span>shift keyword is meant to make things easier. It shifts up all the arguments by one place so that$1 gets the value of $2 ,$2 gets the value of $3 , and so on. ( != tests that the "$1" is no

#### Annotation 3428650978572

 1. Zaciśnij zęby i powstrzymaj chęć natychmiastowego sprzeciwu!

#### pdf

cannot see any pdfs

#### Annotation 3428652551436

 2. Pomyśl o emocjach, jakie odczuwa dziecko. 3. Nazwij te emocje i wypowiedz zdanie, którym je określisz.

#### pdf

cannot see any pdfs

#### Annotation 3428676930828

 So. Postgres user handling is Bloody Fucking Weird, and very VERY archaic in some places. To begin with, Postgres users are not the same users as your computer. Except when you use peer authentication, which is default for "local" connections (in-machine). With peer authentication, you need to have the same username inside the database as outside. So root cannot connect as postgres into the database. Postgres also supports other kinds of authentication, for example trust, which basically says yessir, you're ok no matter who you say you are (not very good). It also supports the ancient and untrustworthy ident protocol, that noone in their sane mind would ever use, and which was designed in the 80s/90s. Then comes the slightly more modern authentications, md5. md5 is basically a username & password combination for your database, where both the username and password are stored in the database system. Then it no longer matters who you are connecting as on the computer ( be it root, postgres, joedope). This is the sane method, and you should use it. By default, postgres might use it if you give it a hostname of localhost. ( -h localhost). Then comes the pg_hba.conf file, which is an amazing hairy construct. It's basically a firewall file for your database system. It tells you which users & databases are allowed to connect from which systems, including your local machine. Then, because ident wasn't stupid enough, they re-envisoned ident as a config file, allowing you to override the username and other combinations in a file on your machine. Don't use it. Really don't. What you want to do is this: - Ignore peer authentication for anything but the postgres user. - Create a new admin user (createuser) with password. - Add your new admin user to pg_hba.conf like this: local all mysuperuser md5 

Cannot get into shell using psql command. : PostgreSQL

#### Annotation 3433516371212

 #has-images “光”跑的这么快，它的速度是如何测量的？ 　　想必大家在日常生活中都有这样的经验，在雷雨天气，我们总是先看到闪电的光，然后过了好久才听到轰隆隆的雷声。这其中的原因也不难理解，那就是因为光的速度比声音的速度快多了。 　　空气中声音的速度大概是340m/s，一马赫的速度，就是指的是声音在空气中的速度。对于光，它的速度似乎是无限的，在日常生活中，光似乎能瞬间从一个地点到另一个地点，例如我们打开手电筒，几乎就在同时我们就看到了手电筒发出的光传播的很远。其实光的速度也是有限的，只不过非常大。　　光在空气中的速度约为3*10^8 m/s。这个速度有多快呢？光在一秒钟内前进的距离大约就可以绕地球赤道7圈半，也就是说，几乎一眨眼的时间光就可以毫不费力的环游世界。从地球到月球的距离约为38万公里，光打个来回也仅仅需要两秒多（事实上，地球和月球之间的准确距离就是计算激光来回所花费时间得到的）。而人类在1969年第一次登上月球，花费了三天多的时间才到达月球，由此可见光速有多快。光速是目前人类已知速度的上限，没有什么东西能运动的比光速还快。既然光速这么快，那科学家们是如何知道光速的准确数值的呢？ 激光测距 　　光速测量史　　人类历史上首次测量光速是在1676年。当时丹麦天文学家奥勒·罗默通过研究木星的卫星木卫一发现光速是有限的，并不是无限的，并由此估计出了光速的值。他估算的过程如下图所示： 光速的估量 　　其中的大环是地球绕太阳的轨道，小环是木卫一绕木星的轨道。当地球远离木星（从L到K）和接近木星（从F到G）时，木卫一从木星的阴影里（C到D）出来的时间会产生变化，从这个变化可以就知道光速是有限的，再加上木卫一绕木星的公转周期和地球的公转周期以及公转速度，就可以估算出光速了。从这中方法估计出的光速误差很大，约为2.2x10^8m/s， 比实际值小26%。　　在1728年，英国天文学家詹姆斯·布拉德利进一步提高了光速的准确度。他所使用的是恒星的光行差。光行差如下图所示 光行差示意图 　　光行差，简单的来说就是地球的运动，会使恒星的方位产生变化。举例来说就是，假设在无风的天气里下雨，雨滴会垂直下落到你的身上，当你以一定的速度奔跑是，雨滴就会以另外一个角度落到你身上，不再垂直。结合这个角度的改变和你的速度，就可以估计出雨滴下落的速度。同样使用恒星光行差，结合地球的公转速度和恒星角度的变化，就可以估算出光速。使用这种方法估算出的光速约为3.01*10^8 m/s，误差仅仅为0.4%。　　提升光速测量精度　　首次准确在地球上，而不是依靠天体运动来测量光速的实验是在1849年由法国物理学家阿曼德·斐索实行的，他使用的方法叫做齿轮测速法。 齿轮法测光速 　　这个方法的关键在于齿轮的转速，齿轮从很低的转速开始逐渐提速，在转速提升到某一关键速度的时候，齿轮转过两个齿的角度时，光线刚好从远处的镜子里折回。这样根据两齿之间的角度以及齿轮的转速，镜子的距离就可以计算出光速的大小。假设齿轮的转速刚好是，齿轮一共有N个齿，远处的镜子距离观察者L。那么光速。 　　1849年阿曼德·斐索用这种装置测出的光速是3.15*10^8m/s，误差为5%，但是随后，法国科学家莱昂·傅科（就是用傅科摆演示地球自转的那个科学家），提高了这个装置的精确度，用旋转镜面代替了旋转的之轮，测出了2.98*10^8m/s的光速值，误差缩小到了0.5%。 旋转齿轮法和旋转镜面法对于光速的准确测量产生了很深远的影响，这种方法简单易行，结果很有说服力。直到1926年，这种方法都一直被当做测量光速的首选，精度一直提高到了0.001%左右。　　齿轮测速法较为精确并且可信地测出了光速的值。之后不久（1861-1862年）就出现了伟大的麦克斯韦（1831-1879，苏格兰物理学家），给出了麦克斯韦方程组，完美的描述了电磁波的运动，他从方程组中得出电磁波的速度约为 　　非常接近当时光速的值，于是他大胆的猜测光就是一种特殊频率的电磁波。后来的实验确实证明了他的猜测。 史上最伟大的物理学家之一—詹姆斯·克拉克·麦克斯韦 　　当知道光是电磁波之后，我们就可以从另外一种方式得到准确的光速，那就是通过测量（真空磁导率）和（真空介电常数）来计算光速，也就是上面提到的 　　在1907年，美国科学家爱德华（Edward Bennett Rosa）和多尔西（N.E。 Dorsey）通过这种方法给出了当时最精确的光速值2.99788*10^8m/s，误差仅仅为0.003%。。　　20世纪50年代以后，随着电子工业技术的发展， 各种测量光速的新技术相继出现，例如谐振腔法（1950年），无线电干涉法（1958年），激光干涉法（1972年）等。下面我们一一介绍。　　谐振腔法主要依据的物理原理就是光也是电磁波，因为任意波长的电磁波具有相同...

[Ò»ÄÉÌìÎÄ]¡°¹â¡±ÅÜµÄÕâÃ´¿ì£¬ËüµÄËÙ¶ÈÊÇÈçºÎ²âÁ¿µÄ£¿ - ¼¼ÐgÓÕ^ | ²ÝÁñÉç^ - t66y.com

#### Flashcard 3433536556300

Question
In linux, in bash scripting, what does $0 mean (give an example to illustrate your knowledge)? Answer$0 references the name of the bash program/script itself (for example, if you run the script as "./test.sh one two", $0 is ./test.sh status measured difficulty not learned 37% [default] 0 7. Shell Scripting og2.sh "$@" fi $0 means the name of the program itself and not any command-line argument. It is the command used to invoke the current program. In the above cases, it is ./myprog.sh . Note that <span>$0 is immune to shift operations. 7.10 Single Forward Quote Notation Single forward quotes ' protect the enclosed text from the shell. In other words, you can place any odd characters insi

#### Flashcard 3433539177740

Question
In linux, in bash scripting if you have script that you run as: ./test.sh one two three
And the above test script has line: echo $0 What is the output? Answer ./test.sh status measured difficulty not learned 37% [default] 0 7. Shell Scripting rsion 0.0.3" exit 0 ;; -*) echo "Error: no such option$1" usage exit 1 ;; esac shift done myprog.sh can now run with multiple arguments on the command-line. 7.9 More on Command-Line Arguments: <span>$@ and$0 Whereas $1 ,$2 , $3 , etc. expand to the individual arguments passed to the program,$@ expands to all arguments. This behavior is useful for passing all remaining arguments ont

#### Flashcard 3433542323468

Question
In linux, in bash scripting if you have script that you run as: ./test.sh one two three
And the above test script has line: echo $@ What is the output? Answer one two three status measured difficulty not learned 37% [default] 0 7. Shell Scripting rsion 0.0.3" exit 0 ;; -*) echo "Error: no such option$1" usage exit 1 ;; esac shift done myprog.sh can now run with multiple arguments on the command-line. 7.9 More on Command-Line Arguments: <span>$@ and$0 Whereas $1 ,$2 , $3 , etc. expand to the individual arguments passed to the program,$@ expands to all arguments. This behavior is useful for passing all remaining arguments onto a sec

#### Flashcard 3433545469196

Question
In linux, in bash scripting, what does $@ mean (give an example to illustrate your knowledge)? Answer it expands all the command line variables for example (not including$0): if you have command: ./test.sh one two three, $@ would be: one two three. ^^note: it is useful in cases where you want to give the remaining command-line args to another command, after perhaps removing some via "shift" status measured difficulty not learned 37% [default] 0 7. Shell Scripting g.sh can now run with multiple arguments on the command-line. 7.9 More on Command-Line Arguments:$@ and $0 Whereas$1 , $2 ,$3 , etc. expand to the individual arguments passed to the program, <span>$@ expands to all arguments. This behavior is useful for passing all remaining arguments onto a second command. For instance, if test "$1" = "--special" ; then shift myprog2.sh "$@" fi$0

#### Flashcard 3433548614924

Question
In linux, in bash scripting, [...] is different that $1,$2, $3, etc, in that it is not changed by the shift statement Answer$0

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

#### Flashcard 3433554906380

Question
In linux, in bash scripting, the purpose of the ' charactor (single quote charactor) is to protect the enclosed text from [...] .
the shell
^^ e.g. if you want to do echo '$1000' and not have to escape the special shell meaning of$

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

#### Flashcard 3433561197836

Question
In linux, write simple bash scripts (with just one line) that just prints out following line:
The cost is $1000 Answer echo 'the cost is$1000'
^^ note the wrapping around single quotes
^^ can also be done as: echo "the cost is \$1000", but the first option of single quote wrapping is cleaner/better status measured difficulty not learned 37% [default] 0 7. Shell Scripting at them literally and reproduce your text exactly. For instance, you may want to echo an actual$ to the screen to produce an output like costs $1000 . You can use echo 'costs$1000' instead of <span>echo "costs $1000" . 7.11 Double-Quote Notation Double quotes " have the opposite sense of single quotes. They allow all shell interpretations to take place inside them. The reason they are used at all is #### Flashcard 3433564343564 Question In linux, in bash scripting, command expansion syntax can be either, for example: echo$(ls) , or equavilantly: echo [...]
ls
^^ note the use of the single backward quotes around ls

status measured difficulty not learned 37% [default] 0
7. Shell Scripting
n factorial 20 and see the output. If we want to assign the output to a variable, we can do this with X=factorial 20 . Note that another notation which gives the effect of a backward quote is <span>$( command ) , which is identical to  command  . Here, I will always use the older backward quote style. Next: 8. Streams and sed Up: rute Previous: 6. Editing Text Files Contents <span> #### Flashcard 3433569062156 Question In linux, in bash scripting, expression expansion syntax can be either, for example: echo$[2*2] , or equavilantly: echo [...]
expr 2 '*' 2
^^ note the use of single backwards quotes wrapped around statement
^^ note the escaping of the shell special char * around single normal quotes, escaping of * can also be done via: \*

status measured difficulty not learned 37% [default] 0
7. Shell Scripting
do A=expr $A '*'$N N=expr $N - 1 done echo$A } We can see that the square braces used further above can actually suffice for most of the times where we would like to use expr . (However, <span>\$[] notation is an extension of the GNU shells and is not a standard feature on all varients of UNIX.) We can now run factorial 20 and see the output. If we want to assign the output to a v

#### Annotation 3433576664332

 Można zaakceptować wszystkie uczucia. Należy ograniczyć niektóre działania!

#### pdf

cannot see any pdfs

#### Flashcard 3433740766476

Question
In Linux, how do you save the output of running "ls" to a file, called "ls.output", that does NOT already exist.
ls > ls.output
^^ note if ls.output already existed, it would be overwritten with output of ls.

status measured difficulty not learned 37% [default] 0
8. Streams and sed -- The Stream Editor
hat contain the word GNU and one line that contains the word GNU as well as the word Linux . Then run grep GNU myfile.txt . The result is printed to stdout as usual. Now try grep GNU myfile.txt <span>> gnu_lines.txt . What is happening here is that the output of the grep command is being redirected into a file. The > gnu_lines.txt tells the shell to create a new file gnu_lines.txt

#### Flashcard 3433745222924

Question
In Linux, how do you append the output of the command, ls, to the end of an already existing file called outputs.txt?
ls >> output.txt
^^ note the double >> for append!

status measured difficulty not learned 37% [default] 0
8. Streams and sed -- The Stream Editor
[Shortened to zero length.] Now suppose you want to append further output to this file. Using >> instead of > does not truncate the file, but appends output to it. Try echo "morestuff" <span>>> gnu_lines.txt then view the contents of gnu_lines.txt . 8.3 Piping Using | Notation The real power of pipes is realized when one program can read from the output of another program. Con

#### Flashcard 3433748368652

Question
In linux, you have file called test.txt, how do you just print out the lines from test.txt that have both the words 'GNU' AND the word 'Test" (in any order)?
grep -w 'GNU' test.txt | grep -w 'Test'
^^ note the use of two greps in a pipe to do the AND filtering.

status measured difficulty not learned 37% [default] 0
8. Streams and sed -- The Stream Editor
he second grep command scans that data for lines with the word Linux in them. grep is often used this way as a filter [Something that screens data.] and can be used multiple times, for example, <span>grep L myfile.txt | grep i | grep n | grep u | grep x The < character redirects the contents of a file in place of stdin. In other words, the contents of a file replace what would normally come from a keyboard. Try grep GNU < gnu_lin

#### Flashcard 3433751514380

Question
In Linux, call the grep command to search for word 'hello' and read from the file test.txt, instad of from stdin (i.e. use file redirection syntax).
grep -w 'hello' < test.txt
^^ note the use of the < char to read input from a file instead of from stdin (which grep reads from when no file is supplied).

status measured difficulty not learned 37% [default] 0
8. Streams and sed -- The Stream Editor
i | grep n | grep u | grep x The < character redirects the contents of a file in place of stdin. In other words, the contents of a file replace what would normally come from a keyboard. Try <span>grep GNU < gnu_lines.txt 8.4 A Complex Piping Example In Chapter 5 we used grep on a dictionary to demonstrate regular expressions. This is how a dictionary of words can be created (your dictionary might be und

#### Flashcard 3433754660108

Question
In linux, if you run the command "ls exiting_file.txt non-existing_file.txt", and the output on the prompt is:
ls: cannot access non-existing_file.txt: No such file or directory
-rw-rw-r-- 1 kevin kevin 6 Oct 17 16:03 existing_file.txt

Reissue the ls command above such that you capture all of the above output (i.e. the error message and the output line) to a file called "output.txt"?

ls existing_file.txt non-existing_file.txt > output.txt 2>&1
^^ note: the 2>&1, means redirect stderr (2) to stdout(1) and since things are executed from right to left this must be declared before the "> output.txt" part
^^ note: the first >, is same as 1> which means redirect stdout (i.e. 1) to output.txt

^^^ shorthand is just: ls existing_file.txt non-existing_file.txt &> output.txt

status measured difficulty not learned 37% [default] 0
8. Streams and sed -- The Stream Editor
ipe x into pipe y. Redirection is specified from right to left on the command-line. Hence, the above command means to mix stderr into stdout and then to redirect stdout to the file A . Finally, <span>ls existing_file non-existing_file 2>A 1>&2 cat A We notice that this has the same effect, except that here we are doing the reverse: redirecting stdout into stderr and then redirecting stderr into a file A . To see what happens

#### Flashcard 3433757805836

Question
ln linux, when you issue command:
ls existing_file.txt non-existing_file.txt > output.txt 2>&1
the 2>&1, means redirect [...] to [...]
stderr to stdout
^^ above reads stardard error to standard output

status measured difficulty not learned 37% [default] 0
8. Streams and sed -- The Stream Editor
riptor 1 when you don't specify a file descriptor. Now A contains the stdout output, while the error message has been redirected to the screen. Now try ls existing_file non-existing_file 1>A <span>2>&1 cat A Now A contains both the error message and the normal output. The >& is called a redirection operator. x >& y tells the shell to write pipe x into pipe y. Redirection

#### Flashcard 3433760951564

Question
ln linux, when you issue command:
ls existing_file.txt non-existing_file.txt > output.txt 2>&1
Why does it matter what order you place the "> output.txt" part vs the "2>&1" part in (i.e. why can't you reverse the order of these parts)?
Because the order of redirection execution is done right to left.
In other words, 2>&1 is done first. i.e. send stderr to stdout, then send stdout, 1> or just >, (which now combines stderr) to output.txt. Putting them in reverse would send stdout to output.txt (without combining it with stderr) then just combine stderr with stdout (which would just be seen in the prompt only)

status measured difficulty not learned 37% [default] 0
8. Streams and sed -- The Stream Editor
1>A 2>&1 cat A Now A contains both the error message and the normal output. The >& is called a redirection operator. x >& y tells the shell to write pipe x into pipe y. <span>Redirection is specified from right to left on the command-line. Hence, the above command means to mix stderr into stdout and then to redirect stdout to the file A . Finally, ls existing_file non-existing_file 2>A 1>&2

#### Flashcard 3433764097292

Question
In linux, sed stands for [...] [...]
stream editor

status measured difficulty not learned 37% [default] 0
8. Streams and sed -- The Stream Editor
x stderr and stdout because the redirection to A came first. 8.6 Using sed to Edit Streams ed used to be the standard text editor for UNIX. It is cryptic to use but is compact and programmable. <span>sed stands for stream editor and is the only incarnation of ed that is commonly used today. sed allows editing of files non-interactively. In the way that grep can search for words and filter lines of text, sed can

#### Flashcard 3433767243020

Question
In linux, what is the most common usage of sed?
To search for and replace words in a stream (it does so by parsing a file, or stdin, one line at a time and outputing to stdout)

status measured difficulty not learned 37% [default] 0
8. Streams and sed -- The Stream Editor
arch-replace operations and insert and delete lines into text files. sed is one of those programs with no man page to speak of. Do info sed to see sed 's comprehensive info pages with examples. <span>The most common usage of sed is to replace words in a stream with alternative words. sed reads from stdin and writes to stdout. Like grep , it is line buffered, which means that it reads one line in at a time and then writes that line out again after performing whateve

#### Flashcard 3433770388748

Question
In linux, sed, just like grep, reads from stdin (or a file) and writes to [...]
stdout

status measured difficulty not learned 37% [default] 0
8. Streams and sed -- The Stream Editor
ose programs with no man page to speak of. Do info sed to see sed 's comprehensive info pages with examples. The most common usage of sed is to replace words in a stream with alternative words. <span>sed reads from stdin and writes to stdout. Like grep , it is line buffered, which means that it reads one line in at a time and then writes that line out again after performing whatever editing operations. Replacements are typi

#### Annotation 3433805516044

 The packet filtering mechanism provided by iptables is organized into three different kinds of structures: tables, chains and targets. Simply put, a table is something that allows you to process packets in specific ways. The default table is the filter table, although there are other tables too.Again, these tables have chains attached to them. These chains allow you to inspect traffic at various points, such as when they just arrive on the network interface or just before they’re handed over to a process. You can add rules to them match specific packets — such as TCP packets going to port 80 — and associate it with a target. A target decides the fate of a packet, such as allowing or rejecting it.When a packet arrives (or leaves, depending on the chain), iptables matches it against rules in these chains one-by-one. When it finds a match, it jumps onto the target and performs the action associated with it. If it doesn’t find a match with any of the rules, it simply does what the default policy of the chain tells it to. The default policy is also a target. By default, all chains have a default policy of allowing packets.

An In-Depth Guide to iptables, the Linux Firewall - Boolean World
functionality in netfilter. However, to keep this article simple, we won’t make a distinction between iptables and netfilter in this article, and simply refer to the entire thing as “iptables”. <span>The packet filtering mechanism provided by iptables is organized into three different kinds of structures: tables, chains and targets. Simply put, a table is something that allows you to process packets in specific ways. The default table is the filter table, although there are other tables too. Again, these tables have chains attached to them. These chains allow you to inspect traffic at various points, such as when they just arrive on the network interface or just before they’re handed over to a process. You can add rules to them match specific packets — such as TCP packets going to port 80 — and associate it with a target. A target decides the fate of a packet, such as allowing or rejecting it. When a packet arrives (or leaves, depending on the chain), iptables matches it against rules in these chains one-by-one. When it finds a match, it jumps onto the target and performs the action associated with it. If it doesn’t find a match with any of the rules, it simply does what the default policy of the chain tells it to. The default policy is also a target. By default, all chains have a default policy of allowing packets. Now, we’re going to take a deeper look into each of these structures. Tables As we’ve mentioned previously, tables allow you to do very specific things with packets. On a modern Linux d

#### Annotation 3433808923916

 Lookups occur on the local computer, not on the remote computer. They are executed with in the directory containing the role or play, as opposed to local tasks which are executed with the directory of the executed script. You can pass wantlist=True to lookups to use in jinja2 template “for” loops. Lookups are an advanced feature. You should have a good working knowledge of Ansible plays before incorporating them.