View RegexPattern.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct RegexPattern { | |
let pattern: String | |
let options: NSRegularExpression.Options | |
init(_ pattern: String, options: NSRegularExpression.Options) { | |
self.pattern = pattern | |
self.options = options | |
} | |
} |
View PatternMatchOperator.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* *** 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, |
View examples.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// *** 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? { |
View example.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
View example.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
View when.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func when<T, U>(_ value: T, _ cases: [T:U], else elseCaseValue: U) -> U { | |
if let existingCaseValue = cases[value] { | |
return existingCaseValue | |
} | |
else { | |
return elseCaseValue | |
} | |
} |
View updateDroplet.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
apt-get update && aptitude dist-upgrade -y && apt-get autoremove -y |
View .gitignore_global
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
*~ | |
# Python | |
# | |
*.pyc | |
*.pyo | |
# macOS | |
# |
View changeShellToFish.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
chsh -s `which fish` |
View audio_extensions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.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 |
NewerOlder