Tutorial by Examples: er

In C#, types can define custom Conversion Operators, which allow values to be converted to and from other types using either explicit or implicit casts. For example, consider a class that is meant to represent a JavaScript expression: public class JsExpression { private readonly string expres...
Suppose you have types like the following: interface IThing { } class Thing : IThing { } LINQ allows you to create a projection that changes the compile-time generic type of an IEnumerable<> via the Enumerable.Cast<>() and Enumerable.OfType<>() extension methods. IEnumerabl...
A simple context tree (containing some common values that might be request scoped and included in a context) built from Go code like the following: // Pseudo-Go ctx := context.WithValue( context.WithDeadline( context.WithValue(context.Background(), sidKey, sid), time.Now().A...
Matplotlib supports both object-oriented and imperative syntax for plotting. The imperative syntax is intentionally designed to be very close to Matlab syntax. The imperative syntax (sometimes called 'state-machine' syntax) issues a string of commands all of which act on the most recent figure or a...
With automatic reference counting (ARC), the compiler inserts retain, release, and autorelease statements where they are needed, so you don't have to write them yourself. It also writes dealloc methods for you. The sample program from Manual Memory Management looks like this with ARC: @interface M...
Modern A weak reference looks like one of these: @property (weak) NSString *property; NSString *__weak variable; If you have a weak reference to an object, then under the hood: You're not retaining it. When it gets deallocated, every reference to it will automatically be set to nil Obje...
Add the following dependency to the build.gradle file: compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.5' Add the following permissions to the AndroidManifest.xml file: <uses-permission android:name="android.permission.INTERNET" /> <uses-permiss...
If you need an ActiveRecord method to raise an exception instead of a false value in case of failure, you can add ! to them. This is very important. As some exceptions/failures are hard to catch if you don't use ! on them. I recommended doing this in your development cycle to write all your ActiveRe...
for loop: arr=(a b c d e f) for i in "${arr[@]}";do echo "$i" done Or for ((i=0;i<${#arr[@]};i++));do echo "${arr[$i]}" done while loop: i=0 while [ $i -lt ${#arr[@]} ];do echo "${arr[$i]}" i=$(expr $i + 1) done Or i=0...
Let's assume that we want to remove 2 upvotes from all the articles of the author with id 51. Doing this only with Python would execute N queries (N being the number of articles in the queryset): for article in Article.objects.filter(author_id=51): article.upvotes -= 2 article.save() ...
Vim supports the use of regular expressions when searching through a file. The character to indicate that you wish to perform a search is /. The simplest search you can perform is the following /if This will search the entire file for all instances of if. However, our search if is actually a r...
Transactions can be used to make multiple changes to the database atomically. Any normal transaction follows this pattern: // You need a writable database to perform transactions final SQLiteDatabase database = openHelper.getWritableDatabase(); // This call starts a transaction database.beginT...
Following statement matches all records having FName that starts with a letter from A to F from Employees Table. SELECT * FROM Employees WHERE FName LIKE '[A-F]%'
package main import ( "fmt" "io/ioutil" ) func main() { files, err := ioutil.ReadDir(".") if err != nil { panic(err) } fmt.Println("Folders in the current directory:") for _, fileInfo := range files { ...
git does not recognice the concept of folders, it just works with files and their filepaths. This means git does not track empty folders. SVN, however, does. Using git-svn means that, by default, any change you do involving empty folders with git will not be propagated to SVN. Using the --rmdir fl...
Some basic types and classes in Java are fundamentally mutable. For example, all array types are mutable, and so are classes like java.util.Data. This can be awkward in situations where an immutable type is mandated. One way to deal with this is to create an immutable wrapper for the mutable type...
enable_shared_from_this enables you to get a valid shared_ptr instance to this. By deriving your class from the class template enable_shared_from_this, you inherit a method shared_from_this that returns a shared_ptr instance to this. Note that the object must be created as a shared_ptr in first pl...
This example shows how to create a delegate that encapsulates the method that returns the current time static DateTime UTCNow() { return DateTime.UtcNow; } static DateTime LocalNow() { return DateTime.Now; } static void Main(string[] args) { Func<DateTime> method = U...
Func also supports Covariant & Contravariant // Simple hierarchy of classes. public class Person { } public class Employee : Person { } class Program { static Employee FindByTitle(String title) { // This is a stub for a method that returns // an employee that h...
This example shows how to use a request interceptor with OkHttp. This has numerous use cases such as: Adding universal header to the request. E.g. authenticating a request Debugging networked applications Retrieving raw response Logging network transaction etc. Set custom user agent Retrof...

Page 113 of 417