Skip to content

Instantly share code, notes, and snippets.

View mcichecki's full-sized avatar
🏀

Michał Cichecki mcichecki

🏀
View GitHub Profile
@mcichecki
mcichecki / convert_to_caf.sh
Created July 26, 2021 07:16
Shell script which converts all files in the folder to the caf format
#!/bin/bash
mkdir -p caf
for file in $1*; do
file_basename=$(basename -- "$file")
filename="${file_basename%.*}"
echo converting $filename
afconvert -f caff -d LEI16@44100 -c 1 $file caf/$filename.caf
@mcichecki
mcichecki / Reactive+UISearchController.swift
Created August 17, 2018 16:22
UISearchResultsUpdating proxy for UISearchController with RxSwift and RxCocoa
import RxCocoa
import RxSwift
public extension Reactive where Base: UISearchController {
var delegate: DelegateProxy<UISearchController, UISearchResultsUpdating> {
return RxSearchResultsUpdatingProxy.proxy(for: base)
}
var searchPhrase: Observable<String> {
@mcichecki
mcichecki / Reactive+isSecureTextEntry.swift
Last active July 25, 2018 07:16
UITextField's extension to support isSecureTextEntry with RxCocoa
import RxCocoa
import RxSwift
extension Reactive where Base: UITextField {
var isSecureTextEntry: Binder<()> {
return Binder(base, binding: { (textField, _) in
textField.isSecureTextEntry = !textField.isSecureTextEntry
})
}
@mcichecki
mcichecki / CGFloat+normalization.swift
Last active June 16, 2023 08:58
Normalized value of CGFloat between two values
extension BinaryFloatingPoint {
/// Returns normalized value for the range between `a` and `b`
/// - Parameters:
/// - min: minimum of the range of the measurement
/// - max: maximum of the range of the measurement
/// - a: minimum of the range of the scale
/// - b: minimum of the range of the scale
func normalize(min: Self, max: Self, from a: Self = 0, to b: Self = 1) -> Self {
(b - a) * ((self - min) / (max - min)) + a
}
@mcichecki
mcichecki / modInverse.swift
Created June 23, 2018 11:03
Modular multiplicative inverse - Swift implementation
/*
given a and m, function finds x for a * x = 1 (mod m)
24 * x = 1 (mod 5)
24 = x*exp(-1) (mod 5)
x = 4
modInverse(a: 24, m: 5) returns optional(4)
*/
@mcichecki
mcichecki / gcd.swift
Created June 23, 2018 10:50
GCD, Swift implementation
private func gcd(_ p: Int, _ q: Int) -> Int {
if q == 0 {
return p
}
return gcd(q, p % q);
}