Tutorial by Examples

std::function can cause significant overhead. Because std::function has [value semantics][1], it must copy or move the given callable into itself. But since it can take callables of an arbitrary type, it will frequently have to allocate memory dynamically to do this. Some function implementations h...
A variable can be downcasted to a subtype using the type cast operators as?, and as!. The as? operator attempts to cast to a subtype. It can fail, therefore it returns an optional. let value: Any = "John" let name = value as? String print(name) // prints Optional("John") ...
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 ...
Surround with Surrounds a code block with an if, for, <editor-fold ...> and more. Windows / Linux: Ctrl + Alt + T OS X / macOS: Cmd + Option + T
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...
PowerShell remoting must first be enabled on the server to which you wish to remotely connect. Enable-PSRemoting -Force This command does the following: Runs the Set-WSManQuickConfig cmdlet, which performs the following tasks: Starts the WinRM service. Sets the startup type on the WinRM ser...
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)
You can read an a binary file using this piece of code in all recent versions of Java: Java SE 1.4 File file = new File("path_to_the_file"); byte[] data = new byte[(int) file.length()]; DataInputStream stream = new DataInputStream(new FileInputStream(file)); stream.readFully(data); s...
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...
Code in an else block will only be run if no exceptions were raised by the code in the try block. This is useful if you have some code you don’t want to run if an exception is thrown, but you don’t want exceptions thrown by that code to be caught. For example: try: data = {1: 'one', 2: 'two'}...
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...
A String can be read from an InputStream using the byte array constructor. import java.io.*; public String readString(InputStream input) throws IOException { byte[] bytes = new byte[50]; // supply the length of the string in bytes here input.read(bytes); return new String(bytes); ...
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...

Page 400 of 1336