Skip to content

Instantly share code, notes, and snippets.

View ksmandersen's full-sized avatar
🏠
Working from home

Kristian Andersen ksmandersen

🏠
Working from home
View GitHub Profile
@ksmandersen
ksmandersen / CreditCardFormatter.swift
Created October 11, 2022 08:53
How to format a credit card number with an (NS)Formatter
class CreditCardFormatter: Formatter {
override func string(for obj: Any?) -> String? {
guard let input = obj as? String else {
return nil
}
return formattedCardNumber(input: input)
}
override func getObjectValue(_ obj: AutoreleasingUnsafeMutablePointer<AnyObject?>?, for string: String, errorDescription error: AutoreleasingUnsafeMutablePointer<NSString?>?) -> Bool {
@ksmandersen
ksmandersen / duplicate_line_xcode.md
Last active September 27, 2021 07:49 — forked from Sidelobe/duplicate_line_xcode.md
Xcode - Duplicate Line key binding

Xcode line duplication (without overwriting your clipboard)

I find this shortcut extremely useful in Xcode: duplicate one or several lines without losing what you have on the clipboard.

Bind keys to duplicate lines in Xcode

  1. To add custom key bindings in Xcode, you have to edit this file (su privileges required): /Applications/Xcode.app/Contents/Frameworks/IDEKit.framework/Versions/Current/Resources/IDETextKeyBindingSet.plist

I add the following new key at the bottom:

@ksmandersen
ksmandersen / StripeSignatureChecker.swift
Created December 3, 2019 09:06
Stripe Signature Validation for Webhooks
/// https://stripe.com/docs/webhooks/signatures#verify-manually
final class StripeSignatureChecker {
// 3 days
static let tolerance: TimeInterval = 3 * 24 * 60 * 60
static func isValid(req: Request) throws -> Bool {
guard let header = req.http.headers["Stripe-Signature"].first else {
throw StripeWebhookError.missingSignatureHeader
}
@ksmandersen
ksmandersen / elasticsearch.sh
Last active November 12, 2019 09:44
Spin up an elastic search instance locally for development
docker run -d --restart always --name elasticsearch -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" elasticsearch:7.4.2
@ksmandersen
ksmandersen / redis.sh
Created November 6, 2019 13:09
Fire up a local redis server
docker run --restart always --name redis -p 6379:6379 -d redis
alias redis-cli="docker exec -it redis redis-cli"
@ksmandersen
ksmandersen / mysql.sh
Last active November 12, 2019 09:44
Set Up a MySQL docker instance
mkdir -p /usr/local/opt/mysql/8.0
chmod -R ug+w /usr/local/opt/mysql/
# Add /usr/local/opt to docker file sharing
docker run --restart always --name mysql8.0 -v /usr/local/opt/mysql/8.0:/var/lib/mysql -p 3306:3306 -d -e MYSQL_ROOT_PASSWORD=winteriscoming mysql:8.0
alias mysql8="mysql --host 0.0.0.0 --port 3306 --password=winteriscoming -u root"
@ksmandersen
ksmandersen / swift-pm-update.bash
Created October 8, 2019 12:07
Update Swift PM with proper dependency resolution
swift package --enable-pubgrub-resolver update
export const scrollToElement = (id, position) => {
const element = document.getElementById(id);
if (element) {
element.scrollIntoView({
behavior: 'smooth',
block: position,
});
}
};
struct ValidateErrors: ValidationError {
/// the errors thrown
var errors: [ValidationError]
/// See ValidationError.keyPath
var path: [String]
/// See ValidationError.reason
var reason: String {
return errors.map { error in
root@applypixels:~# dokku --trace mysql:backup applypixels applypixels-db-backup >> trace-backup.log
+ export DOKKU_HOST_ROOT=/home/dokku
+ DOKKU_HOST_ROOT=/home/dokku
+ export DOKKU_DISTRO
++ . /etc/os-release
++ echo ubuntu
+ DOKKU_DISTRO=ubuntu
+ export DOKKU_IMAGE=gliderlabs/herokuish
+ DOKKU_IMAGE=gliderlabs/herokuish
+ export DOKKU_LIB_ROOT=/var/lib/dokku