Skip to content

Instantly share code, notes, and snippets.

@ealize
ealize / osx-set-all-names.sh
Last active September 12, 2018 05:01 — forked from jacobsalmela/osx-set-all-names.sh
Set all four OS X computer names using a script.
#!/bin/bash
read -p "Enter new machine name: " MAC_NAME
# Bonjour name ending in .local
scutil --set LocalHostName "$MAC_NAME"
# Friendly name shown in System Preferences > Sharing
scutil --set ComputerName "$MAC_NAME"
# The name recognized by the hostname command
scutil --set HostName "$MAC_NAME"
# Save the computer's serial number in a variable so it can be used in the next command.
serialNum=$(ioreg -l | awk '/IOPlatformSerialNumber/ { split($0, line, "\""); printf("%s\n", line[4]); }')

When should you use DateTime and when should you use Time?

It's a common misconception that [William Shakespeare][1] and [Miguel de Cervantes][2] died on the same day in history - so much so that UNESCO named April 23 as [World Book Day because of this fact][3]. However because England hadn't yet adopted [Gregorian Calendar Reform][4] (and wouldn't until [1752][5]) their deaths are actually 10 days apart. Since Ruby's Time class implements a [proleptic Gregorian calendar][6] and has no concept of calendar reform then there's no way to express this. This is where DateTime steps in:

>> shakespeare = DateTime.iso8601('1616-04-23', Date::ENGLAND)
=> Tue, 23 Apr 1616 00:00:00 +0000
>> cervantes = DateTime.iso8601('1616-04-23', Date::ITALY)
=> Sat, 23 Apr 1616 00:00:00 +0000