Tutorial by Examples: dc

Iterator methods can be broken into two distinct groups: Adapters Adapters take an iterator and return another iterator // Iterator Adapter // | | let my_map = (1..6).map(|x| x * x); println!("{:?}", my_map); Output Map { iter: 1..6 } Note that the v...
To help you find and count characters in a string, CharMatcher provides the following methods: int indexIn(CharSequence sequence) Returns the index of the first character that matches the CharMatcher instance. Returns -­1 if no character matches. int indexIn(CharSequence sequence, int sta...
Though the transaction class method is called on some ActiveRecord class, the objects within the transaction block need not all be instances of that class. This is because transactions are per-database connection, not per-model. In this example a balance record is transactionally saved even though ...
#demo-element { background: @theme-color; color: contrast(@theme-color, black, white, 50%); } @theme-color: red; The above example will set the text color of the element as white if the background-color is dark and vice-versa. This is achieved using the contrast() color operation functi...
You can define central config info's in a separate gradle include file Centralizing dependencies via "dependencies.gradle" file a stand alone properties file Versioning your builds via "version.properties" file or do it with root gradle.properties file the project structu...
Enums contains only constants and can be compared directly with ==. So, only reference check is needed, no need to use .equals method. Moreover, if .equals used incorrectly, may raise the NullPointerException while that's not the case with == check. enum Day { GOOD, AVERAGE, WORST; } publi...
layer.masksToBounds = true; layer.cornerRadius = 8;
The revert command allows discarding unwanted uncommitted changes. Reverting changes to a single file. hg revert example.c Reverting all changes. This will discard all changes not just the current directory. hg revert --all hg will output which files were reverted. reverting exa...
This example animates a clock showing the seconds as a filled wedge Annotated Code: <!doctype html> <html> <head> <style> body{ background-color:white; } #canvas{border:1px solid red; } </style> <script> window.onload=(function(){ // canva...
Let's take a sample class: public class Transaction { public string Category { get; set; } public DateTime Date { get; set; } public decimal Amount { get; set; } } Now, let us consider a list of transactions: var transactions = new List<Transaction> { new Transaction...
The example Checking a string for unwanted characters, describes how to test and reject strings that don't meet certain criteria. Obviously, rejecting input outright is not always possible, and sometimes you just have to make do with what you receive. In these cases, a cautious developer will attemp...
The elapsedMillis library provides a class with the same name that keeps track of the time that passed since it was created or set to a certain value: #include <elapsedMillis.h> #define OUTPIN LED_BUILTIN #define PERIOD 500 elapsedMillis ledTime; bool ledState = false; void setup...
.default-settings() { padding: 4px; margin: 4px; font-size: 16px; border: 1px solid gray; } #demo { .default-settings; } The above example when compiled would only produce the following output. The .default-settings() mixin definition would not be output in the compiled CSS fi...
One can verify whether a method was called on a mock by using Mockito.verify(). Original mock = Mockito.mock(Original.class); String param1 = "Expected param value"; int param2 = 100; // Expected param value //Do something with mock //Verify if mock was used properly Mockito.veri...
set alpha {a 1 b 2 c 3} dict get $alpha b # => 2 dict get $alpha d # (ERROR) key "d" not known in dictionary If dict get is used to retrieve the value of a missing key, an error is raised. To prevent the error, use dict exists: if {[dict exists $alpha $key]} { set result [d...
In most scripting languages, if a function call fails, it may throw an exception and stop execution of the program. Bash commands do not have exceptions, but they do have exit codes. A non-zero exit code signals failure, however, a non-zero exit code will not stop execution of the program. This can...
This is an example on how to call a web service from salesforce. The code below is calling a REST based service hosted on data.gov to find farmers markets close to the zipcode. Please remember in order to invoke a HTTP callout from your org, you need to tweak the remote settings for the org. strin...
The "child" components of a component are available on a special prop, props.children. This prop is very useful for "Compositing" components together, and can make JSX markup more intuitive or reflective of the intended final structure of the DOM: var SomeComponent = function ...
To check if a method was called on a mocked object you can use the Mockito.verify method: Mockito.verify(someMock).bla(); In this example, we assert that the method bla was called on the someMock mock object. You can also check if a method was called with certain parameters: Mockito.verify(som...
You can use Modules to build more complex classes through composition. The include ModuleName directive incorporates a module's methods into a class. module Foo def foo_method puts 'foo_method called!' end end module Bar def bar_method puts 'bar_method called!' end end ...

Page 14 of 28