#requires -version 4
After trying to run this script in lower version, you will see this error message
.\script.ps1 : The script 'script.ps1' cannot be run because it contained a "#requires" statement at line 1 for Windows PowerShell version 5.0. The version required by the script do...
4.0
#requires -RunAsAdministrator
After trying to run this script without admin privileges, you will see this error message
.\script.ps1 : The script 'script.ps1' cannot be run because it contains a "#requires" statement for running as Administrator. The current Windows PowerShell s...
The Java programming language (and its runtime) has undergone numerous changes since its release since its initial public release. These changes include:
Changes in the Java programming language syntax and semantics
Changes in the APIs provided by the Java standard class libraries.
Changes in ...
Consider these two pieces of code:
int a = 1000;
int b = a + 1;
and
Integer a = 1000;
Integer b = a + 1;
Question: Which version is more efficient?
Answer: The two versions look almost the identical, but the first version is a lot more efficient than the second one.
The second version is...
d3.js doesn't have a .off() method to detatch existent event listeners. In order to remove an event handler, you have to set it to null:
d3.select('span').on('click', null)
If the web page a contains phone number you can make a call using your phone's dialer. This code checks for the url which starts with tel: then make an intent to open dialer and you can make a call to the clicked phone number:
public boolean shouldOverrideUrlLoading(WebView view, String url) {
...
when can be used to match enum values:
enum class Day {
Sunday,
Monday,
Tuesday,
Wednesday,
Thursday,
Friday,
Saturday
}
fun doOnDay(day: Day) {
when(day) {
Day.Sunday -> // Do something
Day.Monday, Day.Tuesday -> // Do oth...
Cassandra will not require users to login using the default configuration. Instead password-less, anonymous logins are permitted for anyone able to connect to the native_transport_port. This behaviour can be changed by editing the cassandra.yaml config to use a different authenticator:
# Allow anon...
To save a reference to a cell in a variable, you must use the Set syntax, for example:
Dim R as Range
Set R = ActiveSheet.Cells(3, 1)
later...
R.Font.Color = RGB(255, 0, 0)
Why is the Set keyword required? Set tells Visual Basic that the value on the right hand side of the = is meant to be ...
NSDictionary can be enumerated using fast enumeration, just like other collection types:
NSDictionary stockSymbolsDictionary = @{
@"AAPL": @"Apple",
@"GOOGL": @"Alphabet",
...
You can re-throw error that you catch in CATCH block using TRHOW statement:
DECLARE @msg nvarchar(50) = 'Here is a problem! Area: ''%s'' Line:''%i'''
BEGIN TRY
print 'First statement';
RAISERROR(@msg, 11, 1, 'TRY BLOCK', 2);
print 'Second statement';
END TRY
BEGIN CATCH
print...
The following example code is slower than it needs to be :
Map<String, String> map = new HashMap<>();
for (String key : map.keySet()) {
String value = map.get(key);
// Do something with key and value
}
That is because it requires a map lookup (the get() method) for each ...
The Java Collections Framework provides two related methods for all Collection objects:
size() returns the number of entries in a Collection, and
isEmpty() method returns true if (and only if) the Collection is empty.
Both methods can be used to test for collection emptiness. For example:
C...
Let's say you have a library that returns callbacks, for example the fs module in NodeJS:
const fs = require("fs");
fs.readFile("/foo.txt", (err, data) => {
if(err) throw err;
console.log(data);
});
We want to convert it to a promise returning API, with bluebird - ...
You can convert a single function with a callback argument to a Promise-returning version with Promise.promisify, so this:
const fs = require("fs");
fs.readFile("foo.txt", (err, data) => {
if(err) throw err;
console.log(data);
});
becomes:
const promisify = requ...
var firstItem = fetch("/api1").then(x => x.json());
var secondItem = fetch("/api2").then(x => x.json());
Promise.all([firstItem, secondItem]).spread((first, second) => {
// access both results here, both requests completed at this point
});
The PHP community has a lot of developers creating lots of code. This means that one library’s PHP code may use the same class name as another library. When both libraries are used in the same namespace, they collide and cause trouble.
Namespaces solve this problem. As described in the PHP referenc...
realloc is conceptually equivalent to malloc + memcpy + free on the other pointer.
If the size of the space requested is zero, the behavior of realloc is implementation-defined. This is similar for all memory allocation functions that receive a size parameter of value 0. Such functions may in fact ...
Several 'insert' functions can "burn" ids. Here is an example, using InnoDB (other Engines may work differently):
CREATE TABLE Burn (
id SMALLINT UNSIGNED AUTO_INCREMENT NOT NULL,
name VARCHAR(99) NOT NULL,
PRIMARY KEY(id),
UNIQUE(name)
) ENGINE=InnoDB;
IN...