Skip to content

Instantly share code, notes, and snippets.

View djtech42's full-sized avatar

Dan Turner djtech42

View GitHub Profile
@djtech42
djtech42 / RegexPattern.swift
Created August 25, 2017 01:52
Swift Regular Expression Checks Using Pattern Matching RegexPattern
struct RegexPattern {
let pattern: String
let options: NSRegularExpression.Options
init(_ pattern: String, options: NSRegularExpression.Options) {
self.pattern = pattern
self.options = options
}
}
@djtech42
djtech42 / PatternMatchOperator.swift
Last active August 25, 2017 02:07
Swift Regular Expression Checks Using Pattern Matching PatternMatchOperator
/* *** implementation for using the RegexPattern struct that can specify both a
regex pattern and options in pattern matching *** */
func ~=(lhs: RegexPattern, rhs: String) -> Bool {
return
try! NSRegularExpression(
pattern: lhs.pattern,
options: lhs.options
)
.numberOfMatches(
in: rhs,
@djtech42
djtech42 / examples.swift
Last active August 25, 2017 02:11
Swift Regular Expression Checks Using Pattern Matching Examples
// *** different ways a string can match using our pattern matching operator ***
enum StringMatchType {
case literal
case escapedRegularExpression
case regularExpression(withOptions: NSRegularExpression.Options)
}
/* *** example function that returns how the string matches against
a literal string and a regex pattern in default and case insensitive modes *** */
func typeOfMatch(for string: String) -> StringMatchType? {
@djtech42
djtech42 / example.swift
Created June 26, 2017 19:57
Swift Safe Unwrap Operators
var value: String? = "test"
value <*> { print($0) } <> { print("value is nil") } // OUTPUT: test
value = nil
value <*> { print($0) } <> { print("value is nil") } // OUTPUT: value is nil
@djtech42
djtech42 / example.swift
Last active June 26, 2017 20:02
Ternary Function for Swift for more readability
var value = 1005
print(ternary(if: value > 1000, then: "big", else: "small")) // OUTPUT: big
value = 5
print(ternary(if: value > 1000, then: "big", else: "small")) // OUTPUT: small
@djtech42
djtech42 / when.swift
Created June 9, 2017 15:08
When/Else { } block from Kotlin in Swift
func when<T, U>(_ value: T, _ cases: [T:U], else elseCaseValue: U) -> U {
if let existingCaseValue = cases[value] {
return existingCaseValue
}
else {
return elseCaseValue
}
}
@djtech42
djtech42 / updateDroplet.sh
Created February 20, 2017 05:41
Keep DigitalOcean Dropout Updated
apt-get update && aptitude dist-upgrade -y && apt-get autoremove -y
@djtech42
djtech42 / .gitignore_global
Created January 6, 2017 00:38
Global Git Ignore
*~
# Python
#
*.pyc
*.pyo
# macOS
#
@djtech42
djtech42 / changeShellToFish.sh
Created December 13, 2016 14:39
Change User Shell to Fish
chsh -s `which fish`
@djtech42
djtech42 / audio_extensions
Last active April 6, 2020 01:00 — forked from egel/audio_extensions
Big group of extensions (audio, text)
.2sf Nintendo DS Sound File
.2sflib Nintendo DS Audio Library File
.3ga 3GPP Audio File
.4mp 4-MP3 Database File
.5xb Line 6 POD HD500X Edit Bundle
.5xe Line 6 POD HD500X Edit Preset File
.5xs Line 6 POD HD500X Edit Setlist File
.669 UNIS Composer 669 Module
.6cm Six Channel Module
.8cm Eight Channel Module