Tutorial by Examples: cet

// assign string from a string literal string s = "hello"; // assign string from an array of characters char[] chars = new char[] { 'h', 'e', 'l', 'l', 'o' }; string s = new string(chars, 0, chars.Length); // assign string from a char pointer, derived from a string string s; uns...
It is possible to emulate container types, which support accessing values by key or index. Consider this naive implementation of a sparse list, which stores only its non-zero elements to conserve memory. class sparselist(object): def __init__(self, size): self.size = size se...
You cannot pass a reference (or const reference) directly to a thread because std::thread will copy/move them. Instead, use std::reference_wrapper: void foo(int& b) { b = 10; } int a = 1; std::thread thread{ foo, std::ref(a) }; //'a' is now really passed as reference thread.join()...
If you wish to copy the contents of a slice into an initially empty slice, following steps can be taken to accomplish it- Create the source slice: var sourceSlice []interface{} = []interface{}{"Hello",5.10,"World",true} Create the destination slice, with: Length =...
One of the things that can really boost your productivity while writing the code is effectively navigating the workspace. This also means making it comfortable for the moment. It's possible to achieve this by adjusting which areas of workspaces you see. The buttons on the top of the navigation and ...
A type that conforms to the SequenceType protocol can iterate through it's elements within a closure: collection.forEach { print($0) } The same could also be done with a named parameter: collection.forEach { item in print(item) } *Note: Control flow statements (such as break or continu...
In a Service Provider register method we can bind an interface to an implementation: public function register() { App::bind( UserRepositoryInterface::class, EloquentUserRepository::class ); } From now on, everytime the app will need an instance of UserRepositoryInterface, Larave...
For performance reasons you should minimize the number of fields you are requesting from the API. You can use the select property to do so. This example fetches the name property of all accounts: $.ajax({ url: Xrm.Page.context.getClientUrl() + '/api/data/v8.0/accounts?$select=name', head...
Destructuring also gives you the ability to interpret a sequence as a map: (def my-vec [:a 1 :b 2]) (def my-lst '("smthg else" :c 3 :d 4)) (let [[& {:keys [a b]}] my-vec [s & {:keys [c d]} my-lst] (+ a b c d)) ;= 10 It is useful for defining functions with named p...
In many other languages, if you run the following (Java example) if("asgdsrf" == 0) { //do stuff } ... you'll get an error. You can't just go comparing strings to integers like that. In Python, this is a perfectly legal statement - it'll just resolve to False. A common gotcha ...
Type check: variable.isInstanceOf[Type] With pattern matching (not so useful in this form): variable match { case _: Type => true case _ => false } Both isInstanceOf and pattern matching are checking only the object's type, not its generic parameter (no type reification), except fo...
A reference to an option &Option<T> cannot be unwrapped if the type T is not copyable. The solution is to change the option to &Option<&T> using as_ref(). Rust forbids transferring of ownership of objects while the objects are borrowed. When the Option itself is borrowed (&a...
Let's say you have a User model class User < ActiveRecord::Base end Now to update the first_name and last_name of a user with id = 1, you can write the following code. user = User.find(1) user.update(first_name: 'Kashif', last_name: 'Liaqat') Calling update will attempt to update the gi...
Object obj = new Object(); // Note the 'new' keyword Where: Object is a reference type. obj is the variable in which to store the new reference. Object() is the call to a constructor of Object. What happens: Space in memory is allocated for the object. The constructor Object() is call...
We can get a comma delimited string from multiple rows using coalesce as shown below. Since table variable is used, we need to execute whole query once. So to make easy to understand, I have added BEGIN and END block. BEGIN --Table variable declaration to store sample records DECLARE @...
Objective-C supports a special type called `instancetype that can only be used as type returned by a method. It evaluates to the class of the receiving object. Consider the following class hierarchy: @interface Foo : NSObject - (instancetype)initWithString:(NSString *)string; @end @interf...
proc myproc {varName alpha beta} { upvar 1 $varName var set var [expr {$var * $alpha + $beta}] } set foo 1 myproc foo 10 5 puts $foo # => 15 In this particular case, the procedure is given the name of a variable in the current scope. Inside a Tcl procedure, such variables aren't...
Make sure your development workstation and iPhone are connected to the same WiFi network. Tethering, hotspots, and other ad-hoc networking won't work. Run sudo meteor run ios-device Deploy to your device!
Static variables and methods are not part of an instance, There will always be a single copy of that variable no matter how many objects you create of a particular class. For example you might want to have an immutable list of constants, it would be a good idea to keep it static and initialize it j...
java.lang.ref package provides reference-object classes, which support a limited degree of interaction with the garbage collector. Java has four main different reference types. They are: Strong Reference Weak Reference Soft Reference Phantom Reference 1. Strong Reference This is the usual...

Page 1 of 4