Tutorial by Examples: com

Different from stored properties, computed properties are built with a getter and a setter, performing necessary code when accessed and set. Computed properties must define a type: var pi = 3.14 class Circle { var radius = 0.0 var circumference: Double { get { ret...
In order to compare the equality of custom classes, you can override == and != by defining __eq__ and __ne__ methods. You can also override __lt__ (<), __le__ (<=), __gt__ (>), and __ge__ (>). Note that you only need to override two comparison methods, and Python can handle the rest (== ...
If you have already added a file to your Git repository and now want to stop tracking it (so that it won't be present in future commits), you can remove it from the index: git rm --cached <file> This will remove the file from the repository and prevent further changes from being tracked by...
The following is how to properly use the java.util.Scanner class to interactively read user input from System.in correctly( sometimes referred to as stdin, especially in C, C++ and other languages as well as in Unix and Linux). It idiomatically demonstrates the most common things that are requested ...
You can overload all comparison operators: == and != > and < >= and <= The recommended way to overload all those operators is by implementing only 2 operators (== and <) and then using those to define the rest. Scroll down for explanation Overloading outside of class/struct: ...
Sometimes we will need to run commands against a lot of files. This can be done using xargs. find . -type d -print | xargs -r chmod 770 The above command will recursively find all directories (-type d) relative to . (which is your current working directory), and execute chmod 770 on them. The -...
Tuples can be decomposed into individual variables with the following syntax: let myTuple = (name: "Some Name", age: 26) let (first, second) = myTuple print(first) // "Some Name" print(second) // 26 This syntax can be used regardless of if the tuple has unnamed properti...
If you want to squash the previous x commits into a single one, you can use the following commands: git reset --soft HEAD~x git commit Replacing x with the number of previous commits you want to be included in the squashed commit. Mind that this will create a new commit, essentially forgetting...
Commits can be squashed during a git rebase. It is recommended that you understand rebasing before attempting to squash commits in this fashion. Determine which commit you would like to rebase from, and note its commit hash. Run git rebase -i [commit hash]. Alternatively, you can type HE...
Overview SelectorDescriptiondiv spanDescendant selector (all <span>s that are descendants of a <div>)div > spanChild selector (all <span>s that are a direct child of a <div>)a ~ spanGeneral Sibling selector (all <span>s that are siblings after an <a>)a + spanA...
The strcase*-functions are not Standard C, but a POSIX extension. The strcmp function lexicographically compare two null-terminated character arrays. The functions return a negative value if the first argument appears before the second in lexicographical order, zero if they compare equal, or positi...
Given some JSON file "foo.json" like: {"foo": {"bar": {"baz": 1}}} we can call the module directly from the command line (passing the filename as an argument) to pretty-print it: $ python -m json.tool foo.json { "foo": { "bar...
The following example shows common AngularJS constructs in one file: <!DOCTYPE html> <html ng-app="myDemoApp"> <head> <style>.started { background: gold; }</style> <script src="https://code.angularjs.org/1.5.8/angular.min.js">&lt...
Let's say I have this data: Table items idnametag1exampleunique_tag2foosimple42barsimple3bazhello51quuxworld I'd like to get all those lines and know if a tag is used by other lines SELECT id, name, tag, COUNT(*) OVER (PARTITION BY tag) > 1 AS flag FROM items The result will be: idnametag...
Use putAll to put every member of one map into another. Keys already present in the map will have their corresponding values overwritten. Map<String, Integer> numbers = new HashMap<>(); numbers.put("One", 1) numbers.put("Three", 3) Map<String, Integer> othe...
Evaluates its left operand, discards the resulting value, and then evaluates its rights operand and result yields the value of its rightmost operand. int x = 42, y = 42; printf("%i\n", (x *= 2, y)); /* Outputs "42". */ The comma operator introduces a sequence point between i...
This demonstrates a filter on a for-loop, and the use of yield to create a 'sequence comprehension': for ( x <- 1 to 10 if x % 2 == 0) yield x The output for this is: scala.collection.immutable.IndexedSeq[Int] = Vector(2, 4, 6, 8, 10) A for comprehension is useful when you need to crea...
git cherry-pick <commit-hash> will apply the changes made in an existing commit to another branch, while recording a new commit. Essentially, you can copy commits from branch to branch. Given the following tree (Source) dd2e86 - 946992 - 9143a9 - a6fd86 - 5a6057 [master] \ ...
To publish the changes you made in your working copy, run the svn commit command. IMPORTANT: Review your changes before committing them! Use svn status and svn diff to review the changes. Also, make sure you are in the correct path before performing a commit. If you updated many files across vari...
docker run docker/whalesay cowsay 'Hello, StackExchange!' This command tells Docker to create a container from the docker/whalesay image and run the command cowsay 'Hello, StackExchange!' in it. It should print a picture of a whale saying Hello, StackExchange! to your terminal. If the entrypoin...

Page 3 of 65