hash

A Scala method to create an MD5 hash of a string

If you happen to need Scala method to perform an MD5 hash on a string, here you go:

def md5HashString(s: String): String = {
    import java.security.MessageDigest
    import java.math.BigInteger
    val md = MessageDigest.getInstance("MD5")
    val digest = md.digest(s.getBytes)
    val bigInt = new BigInteger(1,digest)
    val hashedString = bigInt.toString(16)
    hashedString
}

“Your password is too similar to a previous one”

I don’t know too much about salting, hashing, and encryption, but it always upsets me when I see a “Your password is too similar to a previous one” message like this, because I assumed that whoever was showing this message was storing my passwords as plain text somewhere. This thread on Twitter, started by Anna Filina, addresses this topic.

The Perl exists function - test to see if a hash key exists

Perl "hash key exists" FAQ: How can I test to see if a key exists in a Perl hash?

Many times when working with a Perl hash, you need to know if a certain key already exists in the hash. The Perl exists function lets you easily determine if a key already exists in the hash.

My Perl hash tutorials

Perl hash tutorials FAQ: Can you share some Perl hash tutorials, or Perl hash examples?

I've recently written a number of articles about the Perl hash construct (or "Perl array hash"). In an effort to try to organize the Perl hash tutorials I've written, I've created this article to help link them all together.

Perl hash size - How to get the size of a hash in Perl

Perl hash size FAQ: How do I get the size of a hash in Perl?

Short answer: To get the size of a Perl hash (the Perl hash size), use the Perl "keys" function, and assign it to a scalar value, like this:

Perl hash - delete example

Perl hash delete FAQ: How do I delete an element (a key/value pair) from a Perl hash? Also, how do I delete multiple Perl hash elements at one time?

A Perl hash delete example - Delete an element by hash key

To delete a Perl hash element, use the Perl "delete" function. The general syntax of the Perl delete function looks like this:

Perl hash add element - How to add an element to a Perl hash

Perl hash "add" FAQ: How do I add a new element to a Perl hash? (Or, How do I push a new element onto a Perl hash?)

The Perl hash is a cool programming construct, and was very unique when I was learning programming languages in the late 1980s. A Perl hash is basically an array, but the keys of the array are strings instead of numbers.

Basic Perl hash "add element" syntax

To add a new element to a Perl hash, you use the following general syntax:

Perl hash introduction tutorial

Perl hash FAQ: Can you share some simple Perl hash examples?

Sure. If you're not familiar with them, a Perl hash is simply a Perl array that is indexed by a string instead of a number. A Perl hash is like a Map in the Java programming language, or an array in PHP.

Perl hash - Background information

To get started looking at a hash in Perl, let's look at a simple example. First, let's assume that Perl hashes don't exist. Next, lets assume that we need to store the prices of various food items you'll find in a restaurant.

Perl: How to access shell environment variables through Perl associative arrays

Perl shell environment variables FAQ: How can I access Unix shell environment variables from a Perl script?

One of the great features of the Perl language is it's support of associative arrays. Unlike normal arrays, whose subscripts can only be integers, the subscripts of associative arrays are text strings. This may not sound like much yet, but with associative arrays (or hashes as they're now called) we can create fairly complex data structures with Perl.