Tutorial by Examples

The @property decorator can be used to define methods in a class which act like attributes. One example where this can be useful is when exposing information which may require an initial (expensive) lookup and simple retrieval thereafter. Given some module foobar.py: class Foo(object): def __...
In jQuery you can select elements in a page using many various properties of the element, including: Type Class ID Possession of Attribute Attribute Value Indexed Selector Pseudo-state If you know CSS selectors you will notice selectors in jQuery are the same (with minor exceptions). Ta...
InterruptedException is a confusing beast - it shows up in seemingly innocuous methods like Thread.sleep(), but handling it incorrectly leads to hard-to-manage code that behaves poorly in concurrent environments. At its most basic, if an InterruptedException is caught it means someone, somewhere, c...
If you want to use @property to implement custom behavior for setting and getting, use this pattern: class Cash(object): def __init__(self, value): self.value = value @property def formatted(self): return '${:.2f}'.format(self.value) @formatted.setter def ...
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...
Simply use the javascript: protocol to run the text as JavaScript instead of opening it as a normal link: <a href="javascript:myFunction();">Run Code</a> You can also achieve the same thing using the onclick attribute: <a href="#" onclick="myFunction(); r...
SELECT your_columns, COUNT(*) OVER() as Ttl_Rows FROM your_data_set idnameTtl_Rows1example52foo53bar54baz55quux5 Instead of using two queries to get a count then the line, you can use an aggregate as a window function and use the full result set as the window. This can be used as a base for fur...
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...
Given this data: dateamount2016-03-122002016-03-11-502016-03-141002016-03-151002016-03-10-250 SELECT date, amount, SUM(amount) OVER (ORDER BY date ASC) AS running FROM operations ORDER BY date ASC will give you dateamountrunning2016-03-10-250-2502016-03-11-50-3002016-03-12200-1002016-03-1410...
use feature qw( say ); # Numbers are true if they're not equal to 0. say 0 ? 'true' : 'false'; # false say 1 ? 'true' : 'false'; # true say 2 ? 'true' : 'false'; # true say -1 ? 'true' : 'false'; # true say 1-1 ? 'true' : 'false'; # fa...
var line = 0 var maximum_lines = 5 while (line < maximum_lines) { line = line + 1 println("Line number: " + line) }
var line = 0 var maximum_lines = 5 do { line = line + 1 println("Line number: " + line) } while (line < maximum_lines) The do/while loop is infrequently used in functional programming, but can be used to work around the lack of support for the break/continue construct, as...
Breakpoints pause your program once execution reaches a certain point. You can then step through the program line by line, observing its execution and inspecting the contents of your variables. There are three ways of creating breakpoints. From code, using the debugger; statement. From the brow...
The pipe operator, %>%, is used to insert an argument into a function. It is not a base feature of the language and can only be used after attaching a package that provides it, such as magrittr. The pipe operator takes the left-hand side (LHS) of the pipe and uses it as the first argument of the ...
QML comes with newer Version of the cross-platform application framework Qt. You can find the newest Version of Qt in the Downloads section. To create a new QML Project in the Qt Creator IDE, select "File -> New ..." and under "Applications" select "Qt Quick-Application...
3.0 Check if a string consists in exactly 8 digits: $ date=20150624 $ [[ $date =~ ^[0-9]{8}$ ]] && echo "yes" || echo "no" yes $ date=hello $ [[ $date =~ ^[0-9]{8}$ ]] && echo "yes" || echo "no" no
You can indent the text inside here documents with tabs, you need to use the <<- redirection operator instead of <<: $ cat <<- EOF This is some content indented with tabs `\t`. You cannot indent with spaces you __have__ to use tabs. Bash will remove empty space befo...
2.05b You can feed a command using here strings like this: $ awk '{print $2}' <<< "hello world - how are you?" world $ awk '{print $1}' <<< "hello how are you > she is fine" hello she You can also feed a while loop with a here string: $ while IFS...
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...
To begin making modifications to the project's data, you have to obtain a local copy of the versioned project. Use the command line svn client or your favorite SVN client (TortoiseSVN, for example). Your local copy of the project is called a working copy in Subversion and you get it by issuing the c...

Page 78 of 1336