Tutorial by Examples: am

Define a new type Person using namedtuple like this: Person = namedtuple('Person', ['age', 'height', 'name']) The second argument is the list of attributes that the tuple will have. You can list these attributes also as either space or comma separated string: Person = namedtuple('Person', 'age,...
A Simple FXML document outlining an AnchorPane containing a button and a label node: <?xml version="1.0" encoding="UTF-8"?> <?import java.lang.*?> <?import java.util.*?> <?import javafx.scene.*?> <?import javafx.scene.control.*?> <?import ...
There is also an option to dynamically request components. You can do it using the $injector service: myModule.controller('myController', ['$injector', function($injector) { var myService = $injector.get('myService'); }]); Note: while this method could be used to prevent the circular depen...
WITH CTE (StudentId, Fname, LName, DOB, RowCnt) as ( SELECT StudentId, FirstName, LastName, DateOfBirth as DOB, SUM(1) OVER (Partition By FirstName, LastName, DateOfBirth) as RowCnt FROM tblStudent ) SELECT * from CTE where RowCnt > 1 ORDER BY DOB, LName This example uses a Common Table ...
A namespace is a URI, but to avoid verbosity, prefixes are used as a proxy. In the following example, the prefix my-prefix is bound to the namespace http://www.example.com/my-namespace by using the special attribute xmlns:my-prefix (my-prefix can be replaced with any other prefix): <?xml versio...
In XML, element and attribute names live in namespaces. By default, they are in no namespace: <?xml version="1.0"?> <foo attr="value"> <!-- the foo element is in no namespace, neither is the attr attribute --> </foo>
import pandas as pd Create a DataFrame from a dictionary, containing two columns: numbers and colors. Each key represent a column name and the value is a series of data, the content of the column: df = pd.DataFrame({'numbers': [1, 2, 3], 'colors': ['red', 'white', 'blue']}) Show contents of d...
Create a DataFrame of random numbers: import numpy as np import pandas as pd # Set the seed for a reproducible sample np.random.seed(0) df = pd.DataFrame(np.random.randn(5, 3), columns=list('ABC')) print(df) # Output: # A B C # 0 1.764052 0.400157 0.9787...
Maps are the Elixir key-value (also called dictionary or hash in other languages) type. You create a map using the %w{} syntax: %{} // creates an empty map %{:a => 1, :b => 2} // creates a non-empty map Keys and values can use be any type: %{"a" => 1, "b" => 2} ...
If you want to get rid of the username field and use email as unique user identifier, you will have to create a custom User model extending AbstractBaseUser instead of AbstractUser. Indeed, username and email are defined in AbstractUser and you can't override them. This means you will also have to r...
Read text file from path: val sc: org.apache.spark.SparkContext = ??? sc.textFile(path="/path/to/input/file") Read files using wildcards: sc.textFile(path="/path/to/*/*") Read files specifying minimum number of partitions: sc.textFile(path="/path/to/input/file&qu...
This example demonstrates that HTTP is a text-based Internet communications protocol, and shows a basic HTTP request and the corresponding HTTP response. You can use Telnet to manually send a minimal HTTP request from the command line, as follows. Start a Telnet session to the web server www.e...
def numberOrCharacterSwitch(toggleNumber: Boolean)(number: Int)(character: Char): String = if (toggleNumber) number.toString else character.toString // need to explicitly specify the type of the parameter to be curried // resulting function signature Boolean => String val switchBetween3A...
def minus(left: Int, right: Int) = left - right val numberMinus5 = minus(_: Int, 5) val fiveMinusNumber = minus(5, _: Int) numberMinus5(7) // 2 fiveMinusNumber(7) // -2
A Map is a basic mapping of keys to values. Maps are different from objects in that their keys can be anything (primitive values as well as objects), not just strings and symbols. Iteration over Maps is also always done in the order the items were inserted into the Map, whereas the order is undefine...
Java provides specialized Streams for three types of primitives IntStream (for ints), LongStream (for longs) and DoubleStream (for doubles). Besides being optimized implementations for their respective primitives, they also provide several specific terminal methods, typically for mathematical operat...
With Calendar class it is easy to find AM or PM. Calendar cal = Calendar.getInstance(); cal.setTime(new Date()); if (cal.get(Calendar.AM_PM) == Calendar.PM) System.out.println("It is PM");
To perform actions in Django using commandline or other services (where the user/request is not used), you can use the management commands. Django modules can be imported as needed. For each command a separate file needs to be created: myapp/management/commands/my_command.py (The management and...
Delegates can be used as typed function pointers: class FuncAsParameters { public void Run() { DoSomething(ErrorHandler1); DoSomething(ErrorHandler2); } public bool ErrorHandler1(string message) { Console.WriteLine(message); var shouldWeContinue = ... re...
This is an example of a function which returns a string. In the example, the function is called in a statement assigning a value to a variable. The value in this case is the return value of the function. function Get-Greeting{ "Hello World" } # Invoking the function $greeting ...

Page 17 of 129