Skip to content

Instantly share code, notes, and snippets.

View fluidsonic's full-sized avatar

Marc Knaup fluidsonic

View GitHub Profile
@fluidsonic
fluidsonic / StringBuilder.kt
Created May 20, 2019 13:48
StringBuilder.replace
actual fun StringBuilder.replace(start: Int, end: Int, replacement: String) = apply {
check(start in 0 .. length) { "start must be in 0 .. $length: $start" }
check(end in start .. length) { "end must be in $start .. $length: $end" }
when {
start == end -> Unit
start == 0 ->
when (end) {
length -> {
@fluidsonic
fluidsonic / QueryConsideringContentNegotiation.kt
Created November 9, 2018 11:30
ContentNegotiation feature for ktor which passing the entity as query parameter for requests where clients can't pass an entity in the body
import io.ktor.application.ApplicationCallPipeline
import io.ktor.application.ApplicationFeature
import io.ktor.application.call
import io.ktor.features.ContentNegotiation
import io.ktor.features.UnsupportedMediaTypeException
import io.ktor.http.HttpMethod
import io.ktor.http.HttpStatusCode
import io.ktor.http.content.HttpStatusCodeContent
import io.ktor.http.content.OutgoingContent
import io.ktor.http.content.transformDefaultContent
@fluidsonic
fluidsonic / example.js
Created September 20, 2018 12:13
Move cursor in contenteditable HTML element to the end
const contenteditableElement = …
const selection = window.getSelection()
selection.selectAllChildren(contenteditableElement)
selection.collapseToEnd()
@fluidsonic
fluidsonic / NestedScrollView.kt
Last active October 21, 2023 09:32
A RecyclerView subclass for Android which makes descendent NestedScrollViews scrollable
package com.github.fluidsonic.nestedrecyclerview
import android.content.Context
import android.support.v4.view.NestedScrollingParent
import android.support.v7.widget.RecyclerView
import android.util.AttributeSet
import android.view.MotionEvent
import android.view.View
@fluidsonic
fluidsonic / FlatOptional.swift
Last active January 30, 2017 20:58
Fully unwraps nested Optionals hidden behind "Any"
protocol _TypeerasedOptional {
var typeerasedSelf: Any? { get }
}
extension Optional: _TypeerasedOptional {
var typeerasedSelf: Any? {
guard let value = self else {
@fluidsonic
fluidsonic / Podfile.rb
Last active May 12, 2016 11:30
Migrating to CocoaPods 1.0 will be so much fun!
workspace 'OurApp'
xcodeproj 'App'
platform :ios, '8.2'
use_frameworks!
link_with 'App Store', 'Beta', 'Development', 'Testing'
# a lot of pods here
pre_install do |installer|
# workaround for https://github.com/CocoaPods/CocoaPods/issues/3957
@fluidsonic
fluidsonic / Recursive Struct.swift
Last active December 11, 2015 15:58
Recursive Struct through Indirect Enum
struct Path: CustomStringConvertible {
private var hasParent = HasParent.No
var key: String
init(forKey key: String, inParent parent: Path? = nil) {
self.key = key
self.parent = parent
@fluidsonic
fluidsonic / foo.m
Created December 4, 2015 15:28
UISplitViewController sucks!
(lldb) po 0x7c953600 // UISplitViewController
<UISplitViewController: 0x7c953600>
(lldb) po [0x7c953600 childViewControllers] // UISplitViewController's children
NSArray(
<UIViewController: 0x7be5a6e0>,
<UIViewController: 0x7be9b130>
)
(lldb) po [0x7be5a6e0 parentViewController] // master child's parent
@fluidsonic
fluidsonic / gist:3f3c93376d9af3d8ab41
Created December 1, 2015 23:31
iOS View Controller Lifecycle Validation
VIEW CONTROLLER LIFECYCLE BROKEN!
MFMailComposeInternalViewController (indirectly) called super.viewDidAppear() multiple times.
Possible causes:
- MFMailComposeInternalViewController or one of its superclasses called super.viewDidAppear() multiple times
- it was called manually (it should never be called manually)
- the controller containment implementation of MFMailComposeViewController or one if its parents is broken
@fluidsonic
fluidsonic / gist:981e0b86661abb30a0ed
Created November 19, 2015 21:58
UIPageControl madness
(lldb) po 0x12fbada50
<UIPageControl: 0x12fbada50; frame = (134.5 46.5; 7 37); autoresize = W; userInteractionEnabled = NO; layer = <WLayer: 0x12fbabe80>>
(lldb) p (NSInteger)[0x12fbada50 numberOfPages]
(NSInteger) $2 = 1
(lldb) p (NSInteger)[0x12fbada50 currentPage]
(NSInteger) $3 = 0
(lldb) p (void)[0x12fbada50 setCurrentPage:1]