Tutorial by Examples: comp

Partial functions are often used to define a total function in parts: sealed trait SuperType case object A extends SuperType case object B extends SuperType case object C extends SuperType val pfA: PartialFunction[SuperType, Int] = { case A => 5 } val pfB: PartialFunction[SuperType,...
To compare strings alphabetically, use localeCompare(). This returns a negative value if the reference string is lexicographically (alphabetically) before the compared string (the parameter), a positive value if it comes afterwards, and a value of 0 if they are equal. var a = "hello"; va...
A compound view is a custom ViewGroup that's treated as a single view by the surrounding program code. Such a ViewGroup can be really useful in DDD-like design, because it can correspond to an aggregate, in this example, a Contact. It can be reused everywhere that contact is displayed. This means t...
Component code: angular.module('myModule', []).component('myComponent', { bindings: { myValue: '<' }, controller: function(MyService) { this.service = MyService; this.componentMethod = function() { return 2; }; } }); The test: describe('myComponent', f...
If you are building a function that may be heavy on the processor (either clientside or serverside) you may want to consider a memoizer which is a cache of previous function executions and their returned values. This allows you to check if the parameters of a function were passed before. Remember, p...
The StringBuffer, StringBuilder, Formatter and StringJoiner classes are Java SE utility classes that are primarily used for assembling strings from other information: The StringBuffer class has been present since Java 1.0, and provides a variety of methods for building and modifying a "buf...
Generally, dialog relies on a div within the HTML. Sometimes you may want to create a dialog from scratch, programmatically. Here is an example of a complex modal dialog created dynamically with interactive functions. HTML <div id="users-contain" class="ui-widget"> &lt...
// Include sequence containers #include <vector> #include <deque> #include <list> // Insert sorting algorithm #include <algorithm> class Base { public: // Constructor that set variable to the value of v Base(int v): variable(v) { } i...
Assuming a source file of hello_world.v and a top level module of hello_world. The code can be run using various simulators. Most simulators are compiled simulators. They require multiple steps to compile and execute. Generally the First step is to compile the Verilog design. Second step is to ...
For programmers coming from GCC or Clang to Visual Studio, or programmers more comfortable with the command line in general, you can use the Visual C++ compiler from the command line as well as the IDE. If you desire to compile your code from the command line in Visual Studio, you first need to set...
You can use ReactJS's components easily in TypeScript. Just rename the 'jsx' file extension to 'tsx': //helloMessage.tsx: var HelloMessage = React.createClass({ render: function() { return <div>Hello {this.props.name}</div>; } }); ReactDOM.render(<HelloMessage name=&q...
The primary task of the manifest is to inform the system about the app's components. For example, a manifest file can declare an activity as follows: <?xml version="1.0" encoding="utf-8"?> <manifest ... > <application android:icon="@drawable/app_icon.pn...
Equality For basic equality testing, the equal operator == is used. For more comprehensive checks, use the identical operator ===. The identical operator works the same as the equal operator, requiring its operands have the same value, but also requires them to have the same data type. For exampl...
Once a model object has been fetched, it becomes a fully realized instance of the class. As such, any additional methods can be accessed in forms and serializers (like Django Rest Framework). Using python properties is an elegant way to represent additional values that are not stored in the databa...
If you want to extend a class as-if you are a static function, for example for class Something add static looking function fromString, this can only work if the class has a companion object and that the extension function has been declared upon the companion object: class Something { compani...
In the simple example, we simply set the width of the rectangle to that of it's parent. Let's consider a more complicated example: ApplicationWindow { visible: true width: 400 height: 640 Rectangle{ id: rect anchors.centerIn: parent height: 100 ...
// *** Case Insensitive comparison with exact title match *** NSPredicate *filterByNameCIS = [NSPredicate predicateWithFormat:@"self.title LIKE[cd] %@",@"Tom and Jerry"]; NSLog(@"Filter By Name(CIS) : %@",[array filteredArrayUsingPredicate:filterByNameCIS]);
// *** Case Insensitive comparison with matching subset *** NSPredicate *filterByName = [NSPredicate predicateWithFormat:@"self.title CONTAINS[cd] %@",@"Tom"]; NSLog(@"Filter By Containing Name : %@",[array filteredArrayUsingPredicate:filterByName]);
The following method computes the Nth Fibonacci number using recursion. public int fib(final int n) { if (n > 2) { return fib(n - 2) + fib(n - 1); } return 1; } The method implements a base case (n <= 2) and a recursive case (n>2). This illustrates the use of re...
All files are in folder files. First create list of DataFrames and then concat them: import pandas as pd import glob #a.csv #a,b #1,2 #5,8 #b.csv #a,b #9,6 #6,4 #c.csv #a,b #4,3 #7,0 files = glob.glob('files/*.csv') dfs = [pd.read_csv(fp) for fp in files] #duplicated ind...

Page 6 of 34