Skip to content

Instantly share code, notes, and snippets.

Avatar

Dan Turner djtech42

  • OnTrak Software
  • Mason, OH
  • Twitter @djtech42
View GitHub Profile
@djtech42
djtech42 / RegexPattern.swift
Created Aug 25, 2017
Swift Regular Expression Checks Using Pattern Matching RegexPattern
View RegexPattern.swift
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 Aug 25, 2017
Swift Regular Expression Checks Using Pattern Matching PatternMatchOperator
View PatternMatchOperator.swift
/* *** 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 Aug 25, 2017
Swift Regular Expression Checks Using Pattern Matching Examples
View examples.swift
// *** 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 Jun 26, 2017
Swift Safe Unwrap Operators
View example.swift
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 Jun 26, 2017
Ternary Function for Swift for more readability
View example.swift
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 Jun 9, 2017
When/Else { } block from Kotlin in Swift
View when.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 Feb 20, 2017
Keep DigitalOcean Dropout Updated
View updateDroplet.sh
apt-get update && aptitude dist-upgrade -y && apt-get autoremove -y
View .gitignore_global
*~
# Python
#
*.pyc
*.pyo
# macOS
#
@djtech42
djtech42 / changeShellToFish.sh
Created Dec 13, 2016
Change User Shell to Fish
View changeShellToFish.sh
chsh -s `which fish`
@djtech42
djtech42 / audio_extensions
Last active Apr 6, 2020 — forked from egel/audio_extensions
Big group of extensions (audio, text)
View audio_extensions
.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