Tutorial by Examples: anti

A task can be created by directly instantiating the Task class... var task = new Task(() => { Console.WriteLine("Task code starting..."); Thread.Sleep(2000); Console.WriteLine("...task code ending!"); }); Console.WriteLine("Starting task..."); t...
Copying an array will copy all of the items inside the original array. Changing the new array will not change the original array. var originalArray = ["Swift", "is", "great!"] var newArray = originalArray newArray[2] = "awesome!" //originalArray = ["...
Classes are reference types, meaning that multiple variables can refer to the same instance. class Dog { var name = "" } let firstDog = Dog() firstDog.name = "Fido" let otherDog = firstDog // otherDog points to the same Dog instance otherDog.name = "Rover" // modifying otherDog also...
Before publishing a package you have to version it. npm supports semantic versioning, this means there are patch, minor and major releases. For example, if your package is at version 1.2.3 to change version you have to: patch release: npm version patch => 1.2.4 minor release: npm version min...
import Data.Traversable as Traversable data MyType a = -- ... instance Traversable MyType where traverse = -- ... Every Traversable structure can be made a Foldable Functor using the fmapDefault and foldMapDefault functions found in Data.Traversable. instance Functor MyType where ...
Using generic constructors would require the anonymous types to be named, which is not possible. Alternatively, generic methods may be used to allow type inference to occur. var anon = new { Foo = 1, Bar = 2 }; var anon2 = new { Foo = 5, Bar = 10 }; List<T> CreateList<T>(params T[] it...
A new thread separate from the main thread's execution, can be created using Thread.new. thr = Thread.new { sleep 1 # 1 second sleep of sub thread puts "Whats the big deal" } This will automatically start the execution of the new thread. To freeze execution of the main Thread, ...
A one-liner that helps granting or revoking vulnerable permissions. granting adb shell pm grant <sample.package.id> android.permission.<PERMISSION_NAME> revoking adb shell pm revoke <sample.package.id> android.permission.<PERMISSION_NAME> Granting all run...
This is a type system extension that allows types that are existentially quantified, or, in other words, have type variables that only get instantiated at runtime†. A value of existential type is similar to an abstract-base-class reference in OO languages: you don't know the exact type in contains,...
You can access SharedPreferences in several ways: Get the default SharedPreferences file: import android.preference.PreferenceManager; SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); Get a specific SharedPreferences file: public static final String PREF_FILE_NAM...
Simple check To check if constant is defined use the defined function. Note that this function doesn't care about constant's value, it only cares if the constant exists or not. Even if the value of the constant is null or false the function will still return true. <?php define("GOOD&quo...
// explicit type declaration let some_value: Option<u32> = Some(13); // implicit type declaration let some_other_value = Some(66);
public static Unsafe getUnsafe() { try { Field unsafe = Unsafe.class.getDeclaredField("theUnsafe"); unsafe.setAccessible(true); return (Unsafe) unsafe.get(null); } catch (IllegalAccessException e) { // Handle } catch (IllegalArgumentExcept...
public class UnsafeLoader { public static Unsafe loadUnsafe() { return Unsafe.getUnsafe(); } } While this example will compile, it is likely to fail at runtime unless the Unsafe class was loaded with the primary classloader. To ensure that happens the JVM should be loaded with...
App::uses('YourModel', 'Model'); $model_1 = new YourModel(array('ds' => 'default')); $model_2 = new YourModel(array('ds' => 'database2'));
A common pitfall of child classes is that, if your parent and child both contain a constructor(__construct()) method, only the child class constructor will run. There may be occasions where you need to run the parent __construct() method from it's child. If you need to do that, then you will need to...
A class in Scala is a 'blueprint' of a class instance. An instance contains the state and behavior as defined by that class. To declare a class: class MyClass{} // curly braces are optional here as class body is empty An instance can be instantiated using new keyword: var instance = new MyClas...
var a:Object; trace(a); // null trace(a.b); // Error 1009 Here, an object reference is declared, but is never assigned a value, be it with new or assignment of a non-null value. Requesting its properties or method results in a 1009 error.
Swallowing Exceptions One should always re-throw exception in the following way: try { ... } catch (Exception ex) { ... throw; } Re-throwing an exception like below will obfuscate the original exception and will lose the original stack trace. One should never do this! The st...
Move semantics are a way of moving one object to another in C++. For this, we empty the old object and place everything it had in the new object. For this, we must understand what an rvalue reference is. An rvalue reference (T&& where T is the object type) is not much different than a norma...

Page 1 of 4