Skip to content

Instantly share code, notes, and snippets.

@mikezs
mikezs / totp.swift
Created April 23, 2024 14:56
totp.swift
import CryptoKit
import Foundation
extension Data {
init?(base32Encoded string: String) {
let alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"
var bytes: [UInt8] = []
var accum = 0
var bits = 0 // # of valid bits in `accum`
@mikezs
mikezs / generate_package.sh
Created January 12, 2021 09:38
Create a Package.swift from the Package.resolved in an Xcode Project
#!/bin/sh
cat MyProject.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved | python3 package_from_spm_xcodeproj.py > Package.swift && swiftlint --strict ./Package.swift
@mikezs
mikezs / Publisher+PromiseExtension.swift
Created October 22, 2020 09:46
Publisher+PromiseExtension.swift
extension Publisher {
func and<T: Publisher>(_ closure: @escaping (Output) -> T) -> AnyPublisher<(Output, T.Output), Failure> where T.Failure == Failure {
then { output in
Just(output)
.setFailureType(to: Failure.self)
.zip(closure(output))
.eraseToAnyPublisher()
}
}
@mikezs
mikezs / UIView.AnimationCurve+AnimationOptions.swift
Created February 18, 2019 16:40
UIView.AnimationCurve to UIView.AnimationOptions
extension UIView.AnimationCurve {
var animationOption: UIView.AnimationOptions {
switch self {
case .easeInOut:
return .curveEaseInOut
case .easeIn:
return .curveEaseIn
case .easeOut:
return .curveEaseOut
case .linear:
@mikezs
mikezs / day1.dart
Last active December 12, 2018 20:14
AdventOfCode 2015
//part1
void main() {
int floor = 0;
for (int i = 0; i < input.length; ++i) {
if (input[i] == ")") --floor;
else if (input[i] == "(") ++floor;
}
print(floor);
}
@mikezs
mikezs / day01part1.dart
Last active December 23, 2018 14:10
Advent Of Code 2018
main() async {
int frequency = 0;
List<String> numberArray = input.split("\n");
for (int i = 0; i < numberArray.length; ++i) {
int number = int.parse(numberArray[i]);
frequency += number;
}
print("Frequency: $frequency");
}
@mikezs
mikezs / UIView+AutoLayout.swift
Last active October 8, 2019 22:22
UIView+AutoLayoutAnchors.swift
import UIKit
protocol LayoutAttributeConvertible {
var layoutAttribute: NSLayoutAttribute { get }
}
enum Edge: LayoutAttributeConvertible {
case left
case right
case top
cd /Library/Preferences
sudo rm com.sophos.sav.plist

cd /Library/Application\ Support/Sophos/cloud/Installer.app/Contents/MacOS/tools/
sudo ./InstallationDeployer —force_remove
@mikezs
mikezs / BoyerMoore.swift
Created November 24, 2015 13:53
Proper Boyer-Moore string searching in Swift 2.0
/**
* Implemention from here: http://www-igm.univ-mlv.fr/~lecroq/string/node14.html#SECTION00140
*/
extension String {
private func preBmBc(forString x: String) -> [Character: Int] {
let m = x.characters.count
var bmBc = [Character: Int](/*count: alphabetSize, repeatedValue: m*/)
for i in 0...m - 2 {
@mikezs
mikezs / AbusiveClass.m
Created April 16, 2015 10:42
Use of trigraphs in Objective-C to create weird syntax
@interface AbusiveClass : NSObject
@end
@implementation AbusiveClass
??=define U_FUKIN_WOT_M8 self == nil
%:define ILL_CUT_U_BRUV ??(self handleError:>;
- (BOOL)handleError??<return YES;%>
- (instancetype)init<%if (self = <:super init??))??<
U_FUKIN_WOT_M8 ??!??! ILL_CUT_U_BRUV