C++11 introduced core language and standard library support for moving an object. The idea is that when an object o is a temporary and one wants a logical copy, then its safe to just pilfer o's resources, such as a dynamically allocated buffer, leaving o logically empty but still destructible and co...
It is possible to create custom routing constraint which can be used inside routes to constraint a parameter to specific values or pattern.
This constrain will match a typical culture/locale pattern, like en-US, de-DE, zh-CHT, zh-Hant.
public class LocaleConstraint : IRouteConstraint
{
pri...
This multimap allows duplicate key-value pairs. JDK analogs are HashMap<K, List>, HashMap<K, Set> and so on.
Key's orderValue's orderDuplicateAnalog keyAnalog valueGuavaApacheEclipse (GS) CollectionsJDKnot definedInsertion-orderyesHashMapArrayListArrayListMultimapMultiValueMapFastListMu...
Compare operation with collections - Create collections
1. Create List
DescriptionJDKguavags-collectionsCreate empty listnew ArrayList<>()Lists.newArrayList()FastList.newList()Create list from valuesArrays.asList("1", "2", "3")Lists.newArrayList("1", &...
Types of columns can be checked by .dtypes atrribute of DataFrames.
In [1]: df = pd.DataFrame({'A': [1, 2, 3], 'B': [1.0, 2.0, 3.0], 'C': [True, False, True]})
In [2]: df
Out[2]:
A B C
0 1 1.0 True
1 2 2.0 False
2 3 3.0 True
In [3]: df.dtypes
Out[3]:
A int64
...
select_dtypes method can be used to select columns based on dtype.
In [1]: df = pd.DataFrame({'A': [1, 2, 3], 'B': [1.0, 2.0, 3.0], 'C': ['a', 'b', 'c'],
'D': [True, False, True]})
In [2]: df
Out[2]:
A B C D
0 1 1.0 a True
1 2 2.0 b False
2...
To connect to MySQL you need to use the MySQL Connector/J driver. You can download it from http://dev.mysql.com/downloads/connector/j/ or you can use Maven:
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version...
Dart has a robust async library, with Future, Stream, and more. However, sometimes you might run into an asynchronous API that uses callbacks instead of Futures. To bridge the gap between callbacks and Futures, Dart offers the Completer class. You can use a Completer to convert a callback into a Fut...
This program copies a file using readable and a writable stream with the pipe() function provided by the stream class
// require the file system module
var fs = require('fs');
/*
Create readable stream to file in current directory named 'node.txt'
Use utf8 encoding
Read the data...
Example. It will be replacing the word email to a name in a text file index.txt with simple RegExp replace(/email/gim, 'name')
var fs = require('fs');
fs.readFile('index.txt', 'utf-8', function(err, data) {
if (err) throw err;
var newValue = data.replace(/email/gim, 'name');
...
The following example shows how to merge two arrays into one associative array, where the key values will be the items of the first array, and the values will be from the second:
$array_one = ['key1', 'key2', 'key3'];
$array_two = ['value1', 'value2', 'value3'];
$array_three = array_combine($ar...
In many environments, you have access to a global console object that contains some basic methods for communicating with standard output devices. Most commonly, this will be the browser's JavaScript console (see Chrome, Firefox, Safari, and Edge for more information).
// At its simplest, you can 'l...
Hstore columns can be useful to store settings. They are available in PostgreSQL databases after you enabled the extension.
class CreatePages < ActiveRecord::Migration[5.0]
def change
create_table :pages do |t|
enable_extension 'hstore' unless extension_enabled?('hstore')
t...
[<Measure>] type m // meters
[<Measure>] type cm // centimeters
// Conversion factor
let cmInM = 100<cm/m>
let distanceInM = 1<m>
let distanceInCM = distanceInM * cmInM // 100<cm>
// Conversion function
let cmToM (x : int<cm>) = x / 100<cm/m>
l...
A component is some sort of user interface element, such as a button or a text field.
Creating a Component
Creating components is near identical to creating a window. Instead of creating a JFrame however, you create that component. For example, to create a JButton, you do the following.
JButton b...
Components have various parameters that can be set for them. They vary from component to component, so a good way to see what parameters can be set for components is to start typing componentName.set, and let your IDE's autocomplete (If you use an IDE) suggest methods. The default shortcut in many I...
DescriptionClassButtonJButtonCheckboxJCheckBoxDrop down menu / Combo boxJComboBoxLabelJLabelListJListMenu barJMenuBarMenu in a menu barJMenuItem in a menuJMenuItemPanelJPanelProgress barJProgressBarRadio buttonJRadioButtonScroll barJScrollBarSliderJSliderSpinner / Number pickerJSpinnerTableJTableTre...
options = {
"x": ["a", "b"],
"y": [10, 20, 30]
}
Given a dictionary such as the one shown above, where there is a list
representing a set of values to explore for the corresponding key. Suppose
you want to explore "x"="a" w...