Fun with emoji

Posted on

Despite being somewhat late to the party 🎉, this week I’ve been having fun with emoji 😂. Emoji are just unicode characters, which means as well as being easy to send in text messages they can also turn up in places you might not expect.

For example, emoji are correctly displayed in the macOS Terminal app. They’re also valid in filenames provided that the file system supports unicode (which all modern filesystems do).

MacOS Terminal with emoji

The Homebrew package manager for macOS uses this “feature”, displaying the beer emoji when it “pours” a “bottle” (installs a binary package).

Homebrew emoji

Emoji are also valid in URLs, although there are restrictions in most TLDs about including them in hostnames (to prevent phishing attacks).

Someone has even gone to the effort of configuring some redirects on wikipedia, so that the 🐋 URL redirects to the page on whales: https://en.wikipedia.org/wiki/🐋

As an alternate to including the emoji UTF characters directly in a text file, there is a Python module which translates codes from the emoji cheat sheet into their corresponding character.

>>> import emoji
>>> print(emoji.emojize("Avast! There be a :whale:!"))
Avast! There be a 🐋!

The inverse is also possible:

>>> emoji.demojize("😀")
':grinning_face:'

Emoji are also valid in WiFi SSIDs. Not every client supports this, but it seems to work on my Mac and also my Android phone.

MacOS Terminal with emoji

I’ve been using the Arduino-compatible ESP8266 a lot recently. It’s a neat little chip which can behave as a 802.11b/g/n client, but also as an access point. The code below is what I used to create the 🐋 network.

#include <ESP8266WiFi.h>
#include <WiFiClient.h> 
#include <ESP8266WebServer.h>

const char *ssid = "\xf0\x9f\x90\x8b"; // whale emoji
const char *password = "whalefish"; // 8 chars min

ESP8266WebServer server(80);

// Once connected, go to http://192.168.4.1 in a web browser.
void handleRoot() {
    server.send(200, "text/html", "<p>Avast! There be a &#x1f40b;!</p>");
}

void setup() {
    WiFi.softAP(ssid, password);
    IPAddress myIP = WiFi.softAPIP();
    Serial.print("AP IP address: ");
    Serial.println(myIP);
    server.on("/", handleRoot);
    server.begin();
}

void loop() { server.handleClient(); }

I’m not the first person to write about this. See also: