comparison

How to write “If string starts with” in Drupal 8 Twig templates

If you ever need to write a “string starts with” comparison in Drupal 8 Twig templates, I just used this approach in a node.html.twig template file and I can confirm that it works:

{% if uri starts with '/foo' %}

More accurately, what I did was to first get the URI for the current Drupal node, and then I perform that test:

How to compare floating-point numbers in Scala alvin July 10, 2017 - 2:00pm

This is an excerpt from the Scala Cookbook (partially modified for the internet). This is Recipe 2.5, “Comparing Floating-Point Numbers in Scala.”

Problem

You need to compare two floating-point numbers in Scala, but as in some other programming languages, two floating-point numbers that should be equivalent may not be.

How to test String equality in Scala alvin July 9, 2017 - 5:50pm

This is an excerpt from the Scala Cookbook (partially modified for the internet). This is Recipe 1.1, “Testing String Equality in Scala.”

Problem

When using Scala, you want to compare two strings to see if they’re equal, i.e., whether they contain the exact same sequence of characters.

Solution

In Scala you compare two String instances with the == operator. Given these strings:

How to compare floating-point numbers in Scala

Scala FAQ: I need to compare two floating-point numbers in Scala, but as in some other programming languages, two floating-point numbers that should be equivalent may not be; how do I comparison floating-point numbers?

Solution

As in Java and many other languages, you solve this problem by creating a method that lets you specify the precision for your comparison. The following Scala “approximately equals” method demonstrates the approach:

How to compare String equality in Java

Java String comparison FAQ: Can you share some examples of how to compare strings in Java?

If you’re like me, when I first started using Java, I wanted to use the == operator to test whether two String instances were equal, but that’s not the correct way to do it in Java.

A Java “instanceof null” example

You might think that when the Java instanceof operator is used to test a null reference, such as a null reference to a String, instanceof would realize that even though the reference is currently null, it is a reference to a String, so you might expect instanceof to return true ... but it doesn't.

A comparison of WordPress and Drupal (May, 2009)

Summary: A comparison of Wordpress and Drupal, circa 2009. (2011 Update: Drupal 7 is much easier to use than Drupal 6, which was described in this article.)

Perl if, else, elsif ("else if") syntax

Summary: This tutorial shows a collection of Perl if, else, and else if examples.

Here are some examples of the Perl if/else syntax, including the “else if” syntax, which is really elsif. (I wrote this because after working with many different languages I can never remember the “else if” syntax for most languages, and elsif is pretty rare.)

The Perl if/else syntax

The Perl if/else syntax is standard, I don’t have any problems here:

My first problem with Windows

In light of those recent Microsoft ads that show that Windows PCs are cheaper than Macs (without ever using the word "Windows"), here's my first problem with Microsoft Windows:

Three minutes and two seconds, how long it took to log into my Windows PC