Skip to content

Instantly share code, notes, and snippets.

@MarkusKramer
MarkusKramer / Base64.kt
Last active November 21, 2023 21:30
Kotlin Multiplatform Base64 - no extra dependencies. Based on Java's implementation.
/*
* Copyright (c) 2012, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
precedencegroup ForwardPipe {
associativity: left
}
infix operator |> : ForwardPipe
func |> <T, U>(value: T, function: ((T) -> U)) -> U {
return function(value)
}
@OleksandrKucherenko
OleksandrKucherenko / dumpviewshierarchy.java
Created February 1, 2018 08:18
Dump Android View hierarchy (very good for unit tests)
package your.name;
import android.annotation.TargetApi;
import android.app.Activity;
import android.app.Application;
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Build;
import android.os.Bundle;
@valvoline
valvoline / String+HTML.swift
Created November 8, 2017 18:31
A swift string extension to deal with HTML
//
// String+HTML.swift
// AttributedString
//
// Created by Costantino Pistagna on 08/11/2017.
// Copyright © 2017 sofapps.it All rights reserved.
//
import UIKit
import Foundation
import Foundation
import PlaygroundSupport
/// A thread-safe array.
public class SynchronizedArray<Element> {
private let queue = DispatchQueue(label: "io.zamzam.ZamzamKit.SynchronizedArray", attributes: .concurrent)
private var array = [Element]()
public init() { }
@dfrib
dfrib / DictionaryKeyPath.swift
Last active April 14, 2023 12:45
Swift: Reading and writing to (possible) nested dictionaries for a given key path, using a recursive approach
// For details, see
// http://stackoverflow.com/questions/40261857/remove-nested-key-from-dictionary
import Foundation
extension Dictionary {
subscript(keyPath keyPath: String) -> Any? {
get {
guard let keyPath = Dictionary.keyPathKeys(forKeyPath: keyPath)
else { return nil }
return getValue(forKeyPath: keyPath)
@bulwinkel
bulwinkel / mapToBundle.kt
Created January 7, 2017 13:35
Partial implementation of converting a `Map<String, V>` to a Bundle.
package com.bulwinkel.android
import android.os.Bundle
import android.os.IBinder
import android.os.Parcelable
import java.io.Serializable
fun <V> Map<String, V>.toBundle(bundle: Bundle = Bundle()): Bundle = bundle.apply {
forEach {
val k = it.key
@scottopell
scottopell / fix_exfat_drive.md
Last active March 9, 2024 12:08
Fix corrupted exFAT disk macOS/OSX

exFAT support on macOS seems to have some bugs because my external drives with exFAT formatting will randomly get corrupted.

Disk Utility is unable to repair this at first, but the fix is this:

  1. Use diskutil list to find the right drive id.
  2. You want the id under the IDENTIFIER column, it should look like disk1s1
  3. Run sudo fsck_exfat -d <id from above>. eg sudo fsck_exfat -d disk1s3
  4. -d is debug so you'll see all your files output as they're processed.
  5. Answer YES if it gives you the prompt Main boot region needs to be updated. Yes/No?
@mbunyard
mbunyard / MockResponseInterceptor.java
Created November 18, 2016 21:11
OkHttp3 interceptor which provides a mock response from local resource file.
package com.rogerthat.network.util;
import android.content.Context;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URLConnection;
import okhttp3.Interceptor;
@paulz
paulz / remove-boilerplate-comments-from-xcode-templates.sh
Created December 13, 2015 08:06
Remove Useless Header comments from Xcode Templates
#!/bin/bash
# Usage:
# $ cd /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/Templates
# $ bash ~/remove-boilerplate-comments-from-xcode-templates.sh
# Repeat for /Applications/Xcode.app/Contents/Developer/Library/Xcode/Templates
find -E . -type f \
\( -regex '.*\.[chm]' -or -regex '.*\.swift' \) \
-exec sed -i '' '1,/^$/d' '{}' ';'