Tutorial by Examples

int x = 0; int y = 5 / x; /* integer division */ or double x = 0.0; double y = 5.0 / x; /* floating point division */ or int x = 0; int y = 5 % x; /* modulo operation */ For the second line in each example, where the value of the second operand (x) is zero, the behaviour is undefine...
Let's say we have two classes, Cat and Dog. class Cat def eat die unless has_food? self.food_amount -= 1 self.hungry = false end def sound puts "Meow" end end class Dog def eat die unless has_food? self.food_amount -= 1 self.hungry = f...
Note: The width and height attributes are not deprecated on images and never have been. Their use has been made much stricter though. The dimensions of an image can be specified using the width and height attributes of the image tag: <img src="images/200x200-img.png" width="2...
<input type="file" name="fileSubmission"> File inputs allow users to select a file from their local filesystem for use with the current page. If used in conjunction with a form element, they can be used to allow users to upload files to a server (for more info see Upload...
Let's say you want to generate counts or subtotals for a given value in a column. Given this table, "Westerosians": NameGreatHouseAllegienceAryaStarkCerceiLannisterMyrcellaLannisterYaraGreyjoyCatelynStarkSansaStark Without GROUP BY, COUNT will simply return a total number of rows: SELE...
/* define a list of preprocessor tokens on which to call X */ #define X_123 X(1) X(2) X(3) /* define X to use */ #define X(val) printf("X(%d) made this print\n", val); X_123 #undef X /* good practice to undef X to facilitate reuse later on */ This example will result in the prep...
Due to auto unboxing, one can use a Boolean in an if statement: Boolean a = Boolean.TRUE; if (a) { // a gets converted to boolean System.out.println("It works!"); } That works for while, do while and the condition in the for statements as well. Note that, if the Boolean is null...
Basics The Reflection API allows one to check the class structure of the code at runtime and invoke code dynamically. This is very powerful, but it is also dangerous since the compiler is not able to statically determine whether dynamic invocations are valid. A simple example would be to get the p...
Syntax for accessing rows and columns: [, [[, and $ This topic covers the most common syntax to access specific rows and columns of a data frame. These are Like a matrix with single brackets data[rows, columns] Using row and column numbers Using column (and row) names Like a list: Wi...
To use an accordion, one must have headers and content inside the headers in their HTML. Then one must instantiate the accordion() method of jQuery UI. <script> $(function() { $( "#accordion" ).accordion(); }); </script> In the HTML: <div id="accordion&quot...
$( "#accordion" ).accordion( "destroy" ); This will remove the accordion functionality completely and show default HTML removing all the jQuery-UI elements. This method does not take any arguments.
$( "#accordion" ).accordion( "disable" ); This method will disable the accordion, i.e. the headers are not selectable making the content read only and static. This method does not take any arguments.
$( "#accordion" ).accordion( "enable" ); This method will enable an accordion. This will enable a disabled accordion or simply do nothing on an already enabled accordion. This method does not take any arguments.
var options = $( "#accordion" ).accordion( "option" ); This will return a PlainObject giving all the options representing the selected accordion. This will contain all the values of the keys that are explained in the Parameters section. This method takes parameters which are ...
$( "#accordion" ).accordion( "refresh" ); This method recomputes the height of the accordion panels if headers or content was added or removed in the DOM.
var widget = $( "#accordion" ).accordion( "widget" ); This method returns a jQuery object containing the accordion.
var array = [3, 2, 1] Creating a new sorted array As Array conforms to SequenceType, we can generate a new array of the sorted elements using a built in sort method. 2.12.2 In Swift 2, this is done with the sort() method. let sorted = array.sort() // [1, 2, 3] 3.0 As of Swift 3, it has...
py.test is one of several third party testing libraries that are available for Python. It can be installed using pip with pip install pytest The Code to Test Say we are testing an addition function in projectroot/module/code.py: # projectroot/module/code.py def add(a, b): return a + b ...
A failing test will provide helpful output as to what went wrong: # projectroot/tests/test_code.py from module import code def test_add__failing(): assert code.add(10, 11) == 33 Results: $ py.test ================================================== test session starts ===============...
A typical email has three main components: A recipient (represented as an email address) A subject A message body Sending mail in PHP can be as simple as calling the built-in function mail(). mail() takes up to five parameters but the first three are all that is required to send an email (al...

Page 75 of 1336