Tutorial by Examples: c

The switch statement can also be used to attempt casting into different types: func checkType(_ value: Any) -> String { switch value { // The `is` operator can be used to check a type case is Double: return "value is a Double" // The `as` operator will ...
static void testNumericPromotion() { char char1 = 1, char2 = 2; short short1 = 1, short2 = 2; int int1 = 1, int2 = 2; float float1 = 1.0f, float2 = 2.0f; // char1 = char1 + char2; // Error: Cannot convert from int to char; // short1 = short1 + short2; // Err...
Make project (compile modifed and dependent) Windows: Ctrl + F9 OS X / macOS: Cmd + F9 Compile selected file, package or module This is useful to know, as when debugging this shortcut can be used to quickly reload / hotswap classes. Windows: Ctrl + Shift + F9 OS X / macOS: Cmd + Shift + F9 Se...
Basic code completion (the name of any class, method or variable) Windows: Ctrl + Space OS X / macOS: Cmd + Space Smart code completion (filters the list of methods and variables by expected type) Windows: Ctrl + Shift + Space OS X / macOS: Cmd + Shift + Space Overwriting code with a suggestio...
Search everywhere Double Shift Find Windows / Linux: Ctrl + F OS X / macOS: Cmd + F Find next F3 Find previous Shift + F3 Replace Windows / Linux: Ctrl + R OS X / macOS: Cmd + R Find in path Windows / Linux: Ctrl + Shift + F OS X / macOS: Cmd + Shift + F Replace in path Windows / Lin...
Copy F5 Move F6 Safe delete Windows / Linux: Alt + Delete OS X / macOS: Cmd + Delete Note that the Delete key on OS X / macOS is the equivalent of the Backspace key on other operating systems. Rename Shift+ F6 Extract Method Windows / Linux: Ctrl + Alt + M OS X / macOS: Cmd + Option + M ...
module SomeMixin def foo puts "foo!" end end class Bar include SomeMixin def baz puts "baz!" end end b = Bar.new b.baz # => "baz!" b.foo # => "foo!" # works thanks to the mixin Now Bar is a mix of it...
Using credentials from your local computer: Enter-PSSession 192.168.1.1 Prompting for credentials on the remote computer Enter-PSSession 192.168.1.1 -Credential $(Get-Credential)
static void Main(string[] args) { string url = "www.stackoverflow.com"; var pingTask = PingUrlAsync(url); Console.WriteLine($"Waiting for response from {url}"); Task.WaitAll(pingTask); Console.WriteLine(pingTask.Re...
A basic AppComponent that depends on a single AppModule to provide application-wide singleton objects. @Singleton @Component(modules = AppModule.class) public interface AppComponent { void inject(App app); Context provideContext(); Gson provideGson(); } A module to use to...
@Scope @Documented @Retention(RUNTIME) public @interface ActivityScope { } Scopes are just annotations and you can create your own ones where needed.
2.3 The CoordinatorLayout is a container somewhat similar to FrameLayout but with extra capabilities, it is called super-powered FrameLayout in the official documentation. By attaching a CoordinatorLayout.Behavior to a direct child of CoordinatorLayout, you’ll be able to intercept touch events, wi...
java.util.Date to java.sql.Date conversion is usually necessary when a Date object needs to be written in a database. java.sql.Date is a wrapper around millisecond value and is used by JDBC to identify an SQL DATE type In the below example, we use the java.util.Date() constructor, that creates a D...
This code compiles: Integer arg = null; int x = arg; But it will crash at runtime with a java.lang.NullPointerException on the second line. The problem is that a primitive int cannot have a null value. This is a minimalistic example, but in practice it often manifests in more sophisticated f...
When adding content from sources outside your domain, or from the local file system the canvas is marked as tainted. Attempt to access the pixel data, or convert to a dataURL will throw a security error. vr image = new Image(); image.src = "file://myLocalImage.png"; image.onload = funct...
Cons-cells, structures, vectors, lists and such can be matched with constructor patterns. (loop for i from 1 to 30 do (format t "~5<~a~;~>" (match (cons (mod i 3) (mod i 5)) ((cons 0 0) "Fizzbuzz")...
CL-PPCRE:REGISTER-GROUPS-BIND will match a string against a regular expression, and if it matches, bind register groups in the regex to variables. If the string does not match, NIL is returned. (defun parse-date-string (date-string) (cl-ppcre:register-groups-bind (year month day) (...
A pointer to base class can be converted to a pointer to derived class using static_cast. static_cast does not do any run-time checking and can lead to undefined behaviour when the pointer does not actually point to the desired type. struct Base {}; struct Derived : Base {}; Derived d; Base* p1 ...
Simple Single Port RAM with one address for read/write operations. module ram_single #( parameter DATA_WIDTH=8, //width of data bus parameter ADDR_WIDTH=8 //width of addresses buses )( input [(DATA_WIDTH-1):0] data, //data to be written input [(ADDR_WIDTH-1):0] ad...
Say you want to print variables in a 3 character column. Note: doubling { and } escapes them. s = """ pad {{:3}} :{a:3}: truncate {{:.3}} :{e:.3}: combined {{:>3.3}} :{a:>3.3}: {{:3.3}} :{a:3.3}: {{:3.3}} :{c:3...

Page 246 of 826