Tutorial by Examples

A singleton is a pattern that restricts the instantiation of a class to one instance/object. For more info on python singleton design patterns, see here. class SingletonType(type): def __call__(cls, *args, **kwargs): try: return cls.__instance except AttributeErr...
6 ES6's Object.assign() function can be used to copy all of the enumerable properties from an existing Object instance to a new one. const existing = { a: 1, b: 2, c: 3 }; const clone = Object.assign({}, existing); This includes Symbol properties in addition to String ones. Object rest/sp...
Perl tries to do what you mean: print "Hello World\n"; The two tricky bits are the semicolon at the end of the line and the \n, which adds a newline (line feed). If you have a relatively new version of perl, you can use say instead of print to have the carriage return added automatical...
An unordered list can be created with the <ul> tag and each list item can be created with the <li> tag as shown by the example below: <ul> <li>Item</li> <li>Another Item</li> <li>Yet Another Item</li> </ul> This will produce a...
An ordered list can be created with the <ol> tag and each list item can be created with the <li> tag as in the example below: <ol> <li>Item</li> <li>Another Item</li> <li>Yet Another Item</li> </ol> This will produce a numbere...
One common pitfall when using dictionaries is to access a non-existent key. This typically results in a KeyError exception mydict = {} mydict['not there'] Traceback (most recent call last): File "<stdin>", line 1, in <module> KeyError: 'not there' One way to avoid...
Right after you install Git, the first thing you should do is set your username and email address. From a shell, type: git config --global user.name "Mr. Bean" git config --global user.email [email protected] git config is the command to get or set options --global means that the ...
To see the log in a prettier graph-like structure use: git log --decorate --oneline --graph sample output : * e0c1cea (HEAD -> maint, tag: v2.9.3, origin/maint) Git 2.9.3 * 9b601ea Merge branch 'jk/difftool-in-subdir' into maint |\ | * 32b8c58 difftool: use Git::* functions instead of...
$ tail -f /var/log/syslog > log.txt [1]+ Stopped tail -f /var/log/syslog > log.txt $ sleep 10 & $ jobs [1]+ Stopped tail -f /var/log/syslog > log.txt [2]- Running sleep 10 &
Creating jobs To create an job, just append a single & after the command: $ sleep 10 & [1] 20024 You can also make a running process a job by pressing Ctrl + z: $ sleep 10 ^Z [1]+ Stopped sleep 10 Background and foreground a process To bring the Process to the f...
The function rand() can be used to generate a pseudo-random integer value between 0 and RAND_MAX (0 and RAND_MAX included). srand(int) is used to seed the pseudo-random number generator. Each time rand() is seeded wih the same seed, it must produce the same sequence of values. It should only be see...
Here's a standalone random number generator that doesn't rely on rand() or similar library functions. Why would you want such a thing? Maybe you don't trust your platform's builtin random number generator, or maybe you want a reproducible source of randomness independent of any particular library ...
> redirect the standard output (aka STDOUT) of the current command into a file or another descriptor. These examples write the output of the ls command into the file file.txt ls >file.txt > file.txt ls The target file is created if it doesn't exists, otherwise this file is truncated. ...
< reads from its right argument and writes to its left argument. To write a file into STDIN we should read /tmp/a_file and write into STDIN i.e 0</tmp/a_file Note: Internal file descriptor defaults to 0 (STDIN) for < $ echo "b" > /tmp/list.txt $ echo "a" >> ...
File descriptors like 0 and 1 are pointers. We change what file descriptors point to with redirection. >/dev/null means 1 points to /dev/null. First we point 1 (STDOUT) to /dev/null then point 2 (STDERR) to whatever 1 points to. # STDERR is redirect to STDOUT: redirected to /dev/null, # effect...
2 is STDERR. $ echo_to_stderr 2>/dev/null # echos nothing Definitions: echo_to_stderr is a command that writes "stderr" to STDERR echo_to_stderr () { echo stderr >&2 } $ echo_to_stderr stderr
Truncate > Create specified file if it does not exist. Truncate (remove file's content) Write to file $ echo "first line" > /tmp/lines $ echo "second line" > /tmp/lines $ cat /tmp/lines second line Append >> Create specified file if it does not e...
The type of the literal Without any extensions, the type of a string literal – i.e., something between double quotes – is just a string, aka list of characters: Prelude> :t "foo" "foo" :: [Char] However, when the OverloadedStrings extension is enabled, string literals be...
Defines an <initially-hidden> custom element which hides its contents until a specified number of seconds have elapsed. const InitiallyHiddenElement = document.registerElement('initially-hidden', class extends HTMLElement { createdCallback() { this.revealTimeoutId = null; } at...
It's possible to extent native elements, but their descendants don't get to have their own tag names. Instead, the is attribute is used to specify which subclass an element is supposed to use. For example, here's an extension of the <img> element which logs a message to the console when it's l...

Page 48 of 1336