Tutorial by Examples

This code compiles: Integer arg = null; int x = arg; But it will crash at runtime with a java.lang.NullPointerException on the second line. The problem is that a primitive int cannot have a null value. This is a minimalistic example, but in practice it often manifests in more sophisticated f...
Sometimes a RecyclerView will need to use several types of Views to be displayed in the list shown in the UI, and each View needs a different layout xml to be inflated. For this issue, you may use different ViewHolders in single Adapter, by using a special method in RecyclerView - getItemViewType(i...
When adding content from sources outside your domain, or from the local file system the canvas is marked as tainted. Attempt to access the pixel data, or convert to a dataURL will throw a security error. vr image = new Image(); image.src = "file://myLocalImage.png"; image.onload = funct...
At run time the following would display a list of url in your console and continue computation payload = [{url:..., title:...}, {url=..., title=...}] main = payload |> List.map .url -- only takes the url |> Debug.log " My list of URLs" -- pass the url...
Cons-cells, structures, vectors, lists and such can be matched with constructor patterns. (loop for i from 1 to 30 do (format t "~5<~a~;~>" (match (cons (mod i 3) (mod i 5)) ((cons 0 0) "Fizzbuzz")...
Guard patterns can be used to check that a value satisfies an arbitrary test-form. (dotimes (i 5) (format t "~d: ~a~%" i (match i ((guard x (oddp x)) "Odd!") (_ "Even!")))) ; 0: Even! ; 1: Odd! ; 2: Even! ; 3: Odd! ; 4: ...
CL-PPCRE:REGISTER-GROUPS-BIND will match a string against a regular expression, and if it matches, bind register groups in the regex to variables. If the string does not match, NIL is returned. (defun parse-date-string (date-string) (cl-ppcre:register-groups-bind (year month day) (...
A pointer to base class can be converted to a pointer to derived class using static_cast. static_cast does not do any run-time checking and can lead to undefined behaviour when the pointer does not actually point to the desired type. struct Base {}; struct Derived : Base {}; Derived d; Base* p1 ...
Simple Single Port RAM with one address for read/write operations. module ram_single #( parameter DATA_WIDTH=8, //width of data bus parameter ADDR_WIDTH=8 //width of addresses buses )( input [(DATA_WIDTH-1):0] data, //data to be written input [(ADDR_WIDTH-1):0] ad...
The shell provisioner runs a shell script when provisioning. $setup = <<SETUP # You can write your shell script between here ... sudo echo "Hello, World!" > /etc/motd.tail # ... and here. SETUP Vagrant.configure("2") do |config| config.vm.box = "ubuntu/tr...
Say you want to print variables in a 3 character column. Note: doubling { and } escapes them. s = """ pad {{:3}} :{a:3}: truncate {{:.3}} :{e:.3}: combined {{:>3.3}} :{a:>3.3}: {{:3.3}} :{a:3.3}: {{:3.3}} :{c:3...
A class, functions as a template that defines the basic characteristics of a particular object. Here's an example: class Person(object): """A simple class.""" # docstring species = "Homo Sapiens" ...
If logic of generic class or method requires checking equality of values having generic type, use EqualityComparer<TType>.Default property: public void Foo<TBar>(TBar arg1, TBar arg2) { var comparer = EqualityComparer<TBar>.Default; if (comparer.Equals(arg1,arg2) {...
By default the Large Object Heap is not compacted unlike the classic Object Heap which can lead to memory fragmentation and further, can lead to OutOfMemoryExceptions Starting with .NET 4.5.1 there is an option to explicitly compact the Large Object Heap (along with a garbage collection): GCSettin...
In Symfony it's possible to define multiple routes for one action. This can be very helpful if you have functions that do the same but have different parameters. class TestController extends Controller { /** * @Route("/test1/{id}", name="test") * @Route("/...
Prolog doesn't have iteration, but all iteration can be rewritten using recursion. Recursion appears when a predicate contains a goal that refers to itself. When writing such predicates in Prolog, a standard recursive pattern always has at least two parts: Base (non-recursive) clause: Typically...
Member member/2 has signature member(?Elem, ?List) and denotes true if Elem is a member of List. This predicate can be used to access variables in a list, where different solutions are retrieved through backtracking. Example queries: ?- member(X, [1,2,3]). X = 1 ; X = 2 ; X = 3. ?- member(X...
To simulate a phone call, press the 'Extended controls' button indicated by three dots, choose 'Phone' and select 'Call'. You can also optionally change the phone number.
We can omit the argument in the call if that argument is an Optional Argument Every Optional Argument has its own default value It will take default value if we do not supply the value A default value of a Optional Argument must be a Constant expression. Must be a value type such as enum or s...
Generic interfaces and delegates can have their type parameters marked as covariant or contravariant using the out and in keywords respectively. These declarations are then respected for type conversions, both implicit and explicit, and both compile time and run time. For example, the existing inte...

Page 401 of 1336