Tutorial by Examples: dis

Consider the following block of code. try { using (var disposable = new MyDisposable()) { throw new Exception("Couldn't perform operation."); } } catch (Exception ex) { Console.WriteLine(ex.Message); } class MyDisposable : IDisposable { public vo...
In C# 5.0 and earlier the developer could only suppress warnings by number. With the introduction of Roslyn Analyzers, C# needs a way to disable warnings issued from specific libraries. With C# 6.0 the pragma directive can suppress warnings by name. Before: #pragma warning disable 0501 C# 6.0: ...
private static final int REQUEST_DISCOVERABLE_BT = 2; // Unique request code private static final int DISCOVERABLE_DURATION = 120; // Discoverable duration time in seconds // 0 means always discoverable ...
GROUP BY is used in combination with aggregation functions. Consider the following table: orderIduserIdstoreNameorderValueorderDate143Store A2520-03-2016257Store B5022-03-2016343Store A3025-03-2016482Store C1026-03-2016521Store A4529-03-2016 The query below uses GROUP BY to perform aggregated calc...
A 2-tuple or a 3-tuple represent a group of related items. (Points in 2D space, RGB values of a color, etc.) A 1-tuple is not very useful since it could easily be replaced with a single int. A 0-tuple seems even more useless since it contains absolutely nothing. Yet it has properties that make it v...
The Math.random() function should give random numbers that have a standard deviation approaching 0. When picking from a deck of card, or simulating a dice roll this is what we want. But in most situations this is unrealistic. In the real world the randomness tends to gather around an common normal...
The UIAlertController available since iOS8 allows you to use the same alert object for either Action sheets or more classic alerts. The only difference is the UIAlertControllerStyle passed as a parameter when creating. This line changes from an AlertView to an ActionSheet, compared to some other ex...
It was common practice to use NSRunLoop to show modal UIAlertView to block code execution until user input is processed in iOS; until Apple released the iOS7, it broke few existing apps. Fortunately, there is a better way of implementing it with C#’s async/await. Here’s the new code taking advantag...
When implementing SFINAE using std::enable_if, it is often useful to have access to helper templates that determines if a given type T matches a set of criteria. To help us with that, the standard already provides two types analog to true and false which are std::true_type and std::false_type. The...
The above forest methodology is actually a disjoint-set data structure, which involves three main operations: subalgo makeSet(v: a node): v.parent = v <- make a new tree rooted at v subalgo findSet(v: a node): if v.parent == v: return v return findSet(v.parent...
We can do two things to improve the simple and sub-optimal disjoint-set subalgorithms: Path compression heuristic: findSet does not need to ever handle a tree with height bigger than 2. If it ends up iterating such a tree, it can link the lower nodes directly to the root, optimizing future trav...
using (new Sitecore.SecurityModel.SecurityDisabler()) { var item = Sitecore.Context.Database.GetItem("/sitecore/content/home"); }
Often times you will see an exception Anti forgery token is meant for user "" but the current user is "username" This is because the Anti-Forgery token is also linked to the current logged-in user. This error appears when a user logs in but their token is still linked to bein...
Run command below to install nginx. sudo apt-get install nginx By default, Nginx automatically starts when it is installed. You can access the default Nginx landing page to confirm that the software is running properly by visiting your server's domain name or public IP address in your web browse...
Inline expansion can be disabled with the go:noinline pragma. For example, if we build the following simple program: package main func printhello() { println("Hello") } func main() { printhello() } we get output that looks like this (trimmed for readability): $ go ...
Higher-order functions can be used to ensure that system resources are disposed, even when a treatment raises an exception. The pattern used by with_output_file allows a clean separation of concerns: the higher-order with_output_file functions takes care of managing the system resources bound to fi...
If targeting Flash Player 11+, the built-in removeChildren method is the best way to remove all children: removeChildren(); //a start and end index can be passed For legacy applications, the same can be accomplished with a loop: while (numChildren > 0) { removeChildAt(0); }
A helper function to create a bitmap copy of an object. This can be used to convert vector objects, text or complex nested Sprite's to a flattened bitmap. function makeBitmapCopy(displayObj:IBitmapDrawable, transparent:Boolean = false, bgColor:uint = 0x00000000, smooth:Boolean = true):Bitmap { ...
Screen shot: Option 1 (pure adb) The shell adb command allows us to execute commands using a device's built-in shell. The screencap shell command captures the content currently visible on a device and saves it into a given image file, e.g. /sdcard/screen.png: adb shell screencap /sdcard/screen.png...
4.4 Recording the display of devices running Android 4.4 (API level 19) and higher: adb shell screenrecord [options] <filename> adb shell screenrecord /sdcard/demo.mp4 (press Ctrl-C to stop recording) Download the file from the device: adb pull /sdcard/demo.mp4 Note: Stop the scre...

Page 4 of 18