Skip to content

Instantly share code, notes, and snippets.

Falsehoods programmers believe about prices

  1. You can store a price in a floating point variable.
  2. All currencies are subdivided in 1/100th units (like US dollar/cents, euro/eurocents etc.).
  3. All currencies are subdivided in decimal units (like dinar/fils)
  4. All currencies currently in circulation are subdivided in decimal units. (to exclude shillings, pennies) (counter-example: MGA)
  5. All currencies are subdivided. (counter-examples: KRW, COP, JPY... Or subdivisions can be deprecated.)
  6. Prices can't have more precision than the smaller sub-unit of the currency. (e.g. gas prices)
  7. For any currency you can have a price of 1. (ZWL)
  8. Every country has its own currency. (EUR is the best example, but also Franc CFA, etc.)
@gspiers
gspiers / gist:89a2ab01ff64cabc6db8f448f8231c1c
Created August 27, 2020 16:50 — forked from steipete/ios-xcode-device-support.sh
Using iOS 14 devices with Xcode 11.5 (instead of Xcode 12)
// The trick is to link the DeviceSupport folder from the beta to the stable version.
// sudo needed if you run the Mac App Store version. Always download the dmg instead... you'll thank me later :)
// Support iOS 14 devices (Xcode 12.0) with Xcode 11.5:
sudo ln -s /Applications/Xcode-beta.app/Contents/Developer/Platforms/iPhoneOS.platform/DeviceSupport/14.0 /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/DeviceSupport
// Then restart Xcode and reconnect your devices. You will need to do that for every beta of future iOS versions
@gspiers
gspiers / InteractiveTransitionCollectionViewDeselection.m
Created July 4, 2020 20:20 — forked from smileyborg/InteractiveTransitionCollectionViewDeselection.m
Animate table & collection view deselection alongside interactive transition (for iOS 11 and later)
// UICollectionView Objective-C example
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
NSIndexPath *selectedIndexPath = [[self.collectionView indexPathsForSelectedItems] firstObject];
if (selectedIndexPath != nil) {
id<UIViewControllerTransitionCoordinator> coordinator = self.transitionCoordinator;
if (coordinator != nil) {
[coordinator animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> context) {
// Stringly typed 💩
// This throws an Obj-C exception and crashes if you get the name wrong. It would be better if it returned an optional.
let bootstrapRootStoryboard = UIStoryboard(name: "BootstrapRoot", bundle: Bundle.main)
guard let appKilledViewController = bootstrapRootStoryboard.instantiateViewController(withIdentifier: "appKilledViewController") as? AppKilledViewController else {
fatalError("Unexpected viewcontroller for identifier 'appKilledViewController'")
}
// Strongly typed using SwiftGen 😀
let appKilledViewController = StoryboardScene.BootstrapRoot.instantiateAppKilledViewController()
@gspiers
gspiers / gist:c14c3f8f23a92f4ac2366fb1842b7a70
Last active May 10, 2017 12:23
Swift throwing methods in protocols
//: Playground - noun: a place where people can play

class MyError: Error {}

protocol P {
    func throwingFunc() throws -> Int
    func nonThrowingFunc() -> Int
}
@gspiers
gspiers / keybase.md
Created June 18, 2014 14:56
Keybase username proof

Keybase proof

I hereby claim:

  • I am gspiers on github.
  • I am gspiers (https://keybase.io/gspiers) on keybase.
  • I have a public key whose fingerprint is 6BAB DBDF E67D 3449 FD78 2184 7F33 A838 EE52 6CA4

To claim this, I am signing this object: