Tutorial by Examples

// Obtain an instance of JavaScript engine ScriptEngineManager manager = new ScriptEngineManager(); ScriptEngine engine = manager.getEngineByName("JavaScript"); //String to be evaluated String str = "3+2*4+5"; //Value after doing Arithmetic operation with operator preceden...
A struct can simply be copied using assignment. type T struct { I int S string } // initialize a struct t := T{1, "one"} // make struct copy u := t // u has its field values equal to t if u == t { // true fmt.Println("u and t are equal") // Prints: &qu...
Django uses special database settings when testing so that tests can use the database normally but by default run on an empty database. Database changes in one test will not be seen by another. For example, both of the following tests will pass: from django.test import TestCase from myapp.models...
This pattern is a more strict approach to starting an Activity. Its purpose is to improve code readability, while at the same time decrease code complexity, maintenance costs, and coupling of your components. The following example implements the starter pattern, which is usually implemented as a st...
The if construct (called a block IF statement in FORTRAN 77) is common across many programming languages. It conditionally executes one block of code when a logical expression is evaluated to true. [name:] IF (expr) THEN block [ELSE IF (expr) THEN [name] block] [ELSE [name] block] ...
Suppose you have a simple Customer model: class Customer(models.Model): first_name = models.CharField(max_length=255) last_name = models.CharField(max_length=255) is_premium = models.BooleanField(default=False) You register it in the Django admin and add search field by first_name...
In this example we aim to accomplish one of the most common tasks: I have a small DC motor laying around, how do I use my Arduino to control it? Easy, with PWM and serial communication, using the function analogWrite() and the Serial library. The basics Pulse Width Modulation or PWM for short is a...
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");
Interceptors are used to intercept OkHttp calls. The reason to intercept could be to monitor, rewrite and retry calls. It can be used for outgoing request or incoming response both. class LoggingInterceptor implements Interceptor { @Override public Response intercept(Interceptor.Chain chain) thr...
private static final Interceptor REWRITE_CACHE_CONTROL_INTERCEPTOR = new Interceptor() { @Override public Response intercept(Interceptor.Chain chain) throws IOException { Response originalResponse = chain.proceed(chain.request()); return originalResponse.newBuilder() .header(&q...
class Foo { private string[] cities = new[] { "Paris", "London", "Berlin" }; public string this[int index] { get { return cities[index]; } set { cities[index] = value; } } } Usage...
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 basic example on how to wire up and make an LED turn on/off when the pushbutton is pressed. /* Basic Digital Read * ------------------ * * turns on and off a light emitting diode(LED) connected to digital * pin 13, when pressing a pushbutton attached to pin 7. It illustrates...
When you want a complete copy of an object (i.e. the object properties and the values inside those properties, etc...), that is called deep cloning. 5.1 If an object can be serialized to JSON, then you can create a deep clone of it with a combination of JSON.parse and JSON.stringify: var existing...
Detailed instructions on getting nhibernate set up or installed.
If you want to calculate with BigDecimal you have to use the returned value because BigDecimal objects are immutable: BigDecimal a = new BigDecimal("42.23"); BigDecimal b = new BigDecimal("10.001"); a.add(b); // a will still be 42.23 BigDecimal c = a.add(b); // c will be ...
The Singleton pattern is a design pattern that restricts the instantiation of a class to one object. After the first object is created, it will return the reference to the same one whenever called for an object. var Singleton = (function () { // instance stores a reference to the Singlet...
Module Pattern The Module pattern is a creational and structural design pattern which provides a way of encapsulating private members while producing a public API. This is accomplished by creating an IIFE which allows us to define variables only available in its scope (through closure) while return...
The most simple data structure available in R is a vector. You can make vectors of numeric values, logical values, and character strings using the c() function. For example: c(1, 2, 3) ## [1] 1 2 3 c(TRUE, TRUE, FALSE) ## [1] TRUE TRUE FALSE c("a", "b", "c") ## ...

Page 202 of 1336