Const baseString As String = "Foo Bar"
Dim containsBar As Boolean
'Find the position of the last "B"
Dim posX As Long
'Note the different number and order of the paramters for InStrRev
posX = InStrRev(baseString, "X", -1, vbBinaryCompare)
'posX = 0
Const baseString As String = "Foo Bar"
'Get the string starting at character 2 and ending at character 6
Dim midText As String
midText = Mid$(baseString, 2, 5)
'midText = "oo Ba"
'Trim the leading and trailing spaces in a string
Const paddedText As String = " Foo Bar "
Dim trimmedText As String
trimmedText = Trim$(paddedText)
'trimmedText = "Foo Bar"
Used by awk to separate fields output by the print statement. For example:
echo "a b c
d e f" | awk 'BEGIN {OFS="-"} {print $2, $3}'
produces:
b-c
e-f
The default value is , a string consisting of a single space.
Used by awk to separate records and is output at the end of every print statement. For example:
echo "a b c
d e f" | awk 'BEGIN {ORS="|"} {print $2, $3}'
produces:
b c|e f
The default value is \n (newline character).
Command line arguments passed to awk are stored in the internal array ARGV of ARGC elements. The first element of the array is the program name. For example:
awk 'BEGIN {
for (i = 0; i < ARGC; ++i) {
printf "ARGV[%d]=\"%s\"\n", i, ARGV[i]
}
}' arg1 arg2 arg3
...
Build.VERSION_CODES is an enumeration of the currently known SDK version codes.
In order to conditionally run code based on the device's Android version, use the TargetApi annotation to avoid Lint errors, and check the build version before running the code specific to the API level.
Here is an exa...
public final class DrawerLayoutTest {
@Test public void Open_Close_Drawer_Layout() {
onView(withId(R.id.drawer_layout)).perform(actionOpenDrawer());
onView(withId(R.id.drawer_layout)).perform(actionCloseDrawer());
}
public static ViewAction actionOpenDrawer() {
return ne...
Aside from destructuring objects into function arguments, you can use them inside variable declarations as follows:
const person = {
name: 'John Doe',
age: 45,
location: 'Paris, France',
};
let { name, age, location } = person;
console.log('I am ' + name + ', aged ' + age + ' and li...
First, install Mongoose with:
npm install mongoose
Then, add it to server.js as dependencies:
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
Next, create the database schema and the name of the collection:
var schemaName = new Schema({
request: String,
time: Nu...
Setup
First, install the necessary packages with:
npm install express cors mongoose
Code
Then, add dependencies to your server.js file, create the database schema and the name of the collection, create an Express.js server, and connect to MongoDB:
var express = require('express');
var cors =...
Setup
First, install the necessary packages with:
npm install express cors mongoose
Code
Then, add dependencies to server.js, create the database schema and the name of the collection, create an Express.js server, and connect to MongoDB:
var express = require('express');
var cors = require('...
Protocols enable polymorphism in Elixir. Define protocols with defprotocol:
defprotocol Log do
def log(value, opts)
end
Implement a protocol with defimpl:
require Logger
# User and Post are custom structs
defimpl Log, for: User do
def log(user, _opts) do
Logger.info "User: ...
We often encounter a situation where a property we're trying to extract doesn't exist in the object/array, resulting in a TypeError (while destructuring nested objects) or being set to undefined. While destructuring we can set a default value, which it will fallback to, in case of it not being found...
We are not limited to destructuring an object/array, we can destructure a nested object/array.
Nested Object Destructuring
var obj = {
a: {
c: 1,
d: 3
},
b: 2
};
var {
a: {
c: x,
d: y
},
b: z
} = obj;
console.log(x, y, z); // 1,3,2
Nested Array ...
round() tie breaking
In Python 2, using round() on a number equally close to two integers will return the one furthest from 0. For example:
Python 2.x2.7
round(1.5) # Out: 2.0
round(0.5) # Out: 1.0
round(-0.5) # Out: -1.0
round(-1.5) # Out: -2.0
In Python 3 however, round() will retur...
adduser command adds a user to the system. In order to add a new user type:
sudo adduser <user_name>
example:
sudo adduser tom
After typing the above command, you will be prompted to enter details about the new user, such as new password, user Full name, etc.
Below is the information ...