Skip to content

Instantly share code, notes, and snippets.

Avatar

Roger Oba rogerluan

View GitHub Profile
View commit-message-guidelines.md

Commit Message Guidelines

These guidelines are based off of this guide. Some of the key takeaways, plus some other opinionated guidelines:

  1. Clarity is key: a commit should be clear even to a viewer who doesn’t have the full context in which it was made.
  2. Start your commit message with a verb, and use sentence case capitalization.
  3. Use the imperative verb when writing a commit message (see the link above if you don’t know what that means). Example: "Fixed" → "Fix"
  4. Commit things that make sense to be grouped in a single commit. Ask yourself "does it make sense for someone to cherry pick this single commit? Is there something missing in it, or something extra that the person wouldn't need?" - if you do that, you'll end up aiming for 1 commit per fix or feature, which makes the codebase cleaner.
  5. Test what you are fixing before committing. Only commit what you’ve tested and are sure that is good to go. This avoids unnecessary comm
@rogerluan
rogerluan / SceneDelegate.swift
Created Jul 23, 2021
SceneDelegate default implementation as of Xcode 12.5. Use this template to migrate apps from iOS versions prior to iOS 13, to iOS 13+
View SceneDelegate.swift
// Copyright © 2021 Roger Oba. All rights reserved.
import UIKit
class SceneDelegate: UIResponder, UIWindowSceneDelegate {
var window: UIWindow?
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
// Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`.
// If using a storyboard, the `window` property will automatically be initialized and attached to the scene.
@rogerluan
rogerluan / remove_all_targets_but_one.rb
Last active Sep 5, 2021
Xcode doesn’t gather code coverage from packages when set to “some targets”. This script fixes this. Also see https://forums.swift.org/t/xcode-doesnt-gather-code-coverage-from-packages-when-set-to-some-targets/37220
View remove_all_targets_but_one.rb
# 1. Configure your Swift Package scheme to collect code coverage for "all targets" - NOT "some targets"
# 2. Test your Swift Package using either `xcodebuild test`, which should generate a `.xcresult` file.
# 3. Convert that `.xcresult` file into a `.json` file using:
# ```sh
# $ xcrun xccov view --report --json #{path_to_xcresult_file} > #{xccov_json_report}
# ```
# 4. Lastly, strip out the targets that you're not interested using this method.
#
# Note 1: This code considers you only want to keep 1 of the targets.
# Note 2: The resulting json file will replace/override the existing one without any warning.
@rogerluan
rogerluan / hns-airdrop.md
Last active May 11, 2021
Github 15+ Followers HNS Airdrop
View hns-airdrop.md

Had 15 GitHub followers in Feb 2019? You can get about US$ 2,300.00 (rate of May 11th 2021) worth of crypto for minimal effort

Is this a scam?

Hah, I won't waste much time explaining this so: tl;dr: no, it's not a scam.

There's no such thing as free money, so the money being given out here is actually a function of:

  1. Time
  2. You being probably an active Open Source contributor (after all those years, you're finally being rewarded in cash! Or, sorta cash, haha)
@rogerluan
rogerluan / DefMode.java
Last active Mar 21, 2021
A simple yet extremely effective Robocode robot.
View DefMode.java
package a20;
import robocode.*;
import java.awt.Color;
/**
* DefMode - A Robocode robot
* @author: Roger Oba
* @date: September 2014
*
* This robot won 2nd place in an internal Robocode tournament. The 1st place had a complex algorithm with over 1k LOC, and most other participants had over 600 LOC ;)
@rogerluan
rogerluan / Optional+Utilities.swift
Created Jan 26, 2021
The Optional Value Setter operator assigns a value to the receiving subject, only if the receiver is nil. Analogous to Ruby's ||= operator.
View Optional+Utilities.swift
infix operator ??=
extension Swift.Optional {
/// This is the Optional Value Setter operator. It assigns a value to the receiving subject, only if
/// the receiver is `nil`.
/// When the receiver is not `nil`, the value on the right hand side won't be accessed or computed (as
/// it's an `@autoclosure`). If the receiver already has `.some` value, no value will be assigned to it,
/// thus `willSet` and `didSet` won't be called.
///
/// - SeeAlso: the rejected proposal of this feature in Swift Evolution: https://github.com/apple/swift-evolution/blob/master/proposals/0024-optional-value-setter.md
@rogerluan
rogerluan / CountryCodes.swift
Created Jan 19, 2021
Quick snippet to get all the Alpha-2 ISO country code as well as they localized display name, using native Swift lib (no imported external enums/manual entries).
View CountryCodes.swift
var countries: [String:String] = [:]
for code in NSLocale.isoCountryCodes {
let id: String = Locale.identifier(fromComponents: [
NSLocale.Key.countryCode.rawValue : code
])
guard let name = (Locale.current as NSLocale).displayName(forKey: .identifier, value: id) else { continue }
countries[code] = name
}
for (index, countryCode) in countries.keys.sorted(by: { countries[$0]! < countries[$1]! }).enumerated() {
@rogerluan
rogerluan / Flattenable.swift
Created Dec 17, 2020
Flattenable conforming entities define flattened, a function that flattens any arbitrary Optional, no matter how deeply nested, down to a single level of optionality.
View Flattenable.swift
import XCTest
protocol Flattenable {
func flattened() -> Any?
}
extension Swift.Optional : Flattenable {
/// Flattens any arbitrary Optional, no matter how deeply nested, down to a single level of optionality.
/// - SeeAlso: Really fun discussion going on here: https://forums.swift.org/t/challenge-flattening-nested-optionals/24083
/// - Returns: A single-level Optional.
@rogerluan
rogerluan / Regex+Utilities.swift
Last active Jul 27, 2020
A few regex utilities in Swift.
View Regex+Utilities.swift
extension NSRegularExpression {
convenience init(_ pattern: String) {
do {
try self.init(pattern: pattern)
} catch {
preconditionFailure("Illegal regular expression with pattern: \(pattern)")
}
}
func matches(_ string: String, options: NSRegularExpression.MatchingOptions = []) -> Bool {
@rogerluan
rogerluan / String+Regex.swift
Created Jul 27, 2020
Handy Regex utility to find and replace matching groups in Swift.
View String+Regex.swift
extension String {
/// Finds matching groups and replace them with a template using an intuitive API.
///
/// This example will go through an input string and replace all occurrences of "MyGreatBrand" with "**MyGreatBrand**".
///
/// let regex = try! NSRegularExpression(pattern: #"(MyGreatBrand)"#) // Matches all occurrences of MyGreatBrand
/// someMarkdownDocument.replaceGroups(matching: regex, with: #"**$1**"#) // Surround all matches with **, formatting as bold text in markdown.
/// print(someMarkdownDocument)
///
/// - Parameters: