Sometimes two arrays of the same length need to be iterated together, for example:
$people = ['Tim', 'Tony', 'Turanga'];
$foods = ['chicken', 'beef', 'slurm'];
array_map is the simplest way to accomplish this:
array_map(function($person, $food) {
return "$person likes $food\n";
...
The installer requires PHP 5.4 or higher. If you still use the legacy PHP 5.3 version, you cannot use the Symfony Installer. Read the Creating Symfony Applications without the Installer section to learn how to proceed. - source: http://symfony.com/doc/current/book/installation.html
Given any value of type Int or Long to render a human readable string:
fun Long.humanReadable(): String {
if (this <= 0) return "0"
val units = arrayOf("B", "KB", "MB", "GB", "TB", "EB")
val digitGroups = (Mat...
A common use case for extension methods is to improve an existing API. Here are examples of adding exist, notExists and deleteRecursively to the Java 7+ Path class:
fun Path.exists(): Boolean = Files.exists(this)
fun Path.notExists(): Boolean = !this.exists()
fun Path.deleteRecursively(): Bool...
With this declaration:
fun Temporal.toIsoString(): String = DateTimeFormatter.ISO_INSTANT.format(this)
You can now simply:
val dateAsString = someInstant.toIsoString()
In the simple example, we simply set the width of the rectangle to that of it's parent. Let's consider a more complicated example:
ApplicationWindow {
visible: true
width: 400
height: 640
Rectangle{
id: rect
anchors.centerIn: parent
height: 100
...
Sample Data:
CREATE TABLE table_name ( id, list ) AS
SELECT 1, 'a,b,c,d' FROM DUAL UNION ALL -- Multiple items in the list
SELECT 2, 'e' FROM DUAL UNION ALL -- Single item in the list
SELECT 3, NULL FROM DUAL UNION ALL -- NULL list
SELECT 4, 'f,,g' FROM DUAL; -- NULL item...
You can implement the swipe-to-dismiss and drag-and-drop features with the RecyclerView without using 3rd party libraries.
Just use the ItemTouchHelper class included in the RecyclerView support library.
Instantiate the ItemTouchHelper with the SimpleCallback callback and depending on which functi...
Common table expressions support extracting portions of larger queries. For example:
WITH sales AS (
SELECT
orders.ordered_at,
orders.user_id,
SUM(orders.amount) AS total
FROM orders
GROUP BY orders.ordered_at, orders.user_id
)
SELECT
sales.ordered_at,
sales.total,...
Two Random class created at the same time will have the same seed value.
Using System.Guid.NewGuid().GetHashCode() can get a different seed even in the same time.
Random rnd1 = new Random();
Random rnd2 = new Random();
Console.WriteLine("First 5 random number in rnd1");
for (int i = 0...
Average
The AVG() aggregate function will return the average of values selected.
SELECT AVG(Salary) FROM Employees
Aggregate functions can also be combined with the where clause.
SELECT AVG(Salary) FROM Employees where DepartmentId = 1
Aggregate functions can also be combined with group by ...
This query selects all employees not on the Supervisors table.
SELECT *
FROM Employees
WHERE EmployeeID not in (SELECT EmployeeID
FROM Supervisors)
The same results can be achieved using a LEFT JOIN.
SELECT *
FROM Employees AS e
LEFT JOIN Supervisors AS s ON s.E...
In addition to the standard makeLenses function for generating Lenses, Control.Lens.TH also offers the makeClassy function. makeClassy has the same type and works in essentially the same way as makeLenses, with one key difference. In addition to generating the standard lenses and traversals, if the ...
Double-quoted strings use interpolation and escaping – unlike single-quoted strings. To double-quote a string, use either double quotes " or the qq operator.
my $greeting = "Hello!\n";
print $greeting;
# => Hello! (followed by a linefeed)
my $bush = "They misunderestimat...
We have a sample Spring boot application which stores user data in MongoDB and we are using Rest services to retrieve data
First there is a domain class i.e. POJO
@Document
public class User{
@Id
private String id;
private String name;
}
A corresponding repository based on ...
Analog to get a collection for a Stream by collect() an array can be obtained by the Stream.toArray() method:
List<String> fruits = Arrays.asList("apple", "banana", "pear", "kiwi", "orange");
String[] filteredFruits = fruits.stream()
....