Skip to content

Instantly share code, notes, and snippets.

View szotp's full-sized avatar
:octocat:

Paweł Szot szotp

:octocat:
  • Poland
View GitHub Profile
@szotp
szotp / main.dart
Last active July 16, 2019 12:06
OverflowFallback
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
typedef OverflowCallback = void Function(double minimalHeight);
class RenderOverflowFallback extends RenderMetaData {
bool shouldClip = false;
@override
void performLayout() {
@szotp
szotp / swagger.swift
Last active January 6, 2021 02:26
Extremely generic swagger client
import Foundation
typealias ApiCallback<Output> = Optional<(Result<Output, Error>) -> Void>
protocol EndpointClient {
func execute<Output>(endpoint: Endpoint<Output>, onResult: ApiCallback<Output>)
}
struct RequestBuilder {
var path: String = ""
@szotp
szotp / main.swift
Last active June 30, 2019 11:39
Handling result with less completion calls
//
// main.swift
// Completions
//
// Created by szotp on 30/06/2019.
// Copyright © 2019 szotp. All rights reserved.
//
import Foundation
@szotp
szotp / main.swift
Created June 27, 2019 15:52
Parsing weird jsons in swift with Codable
import Foundation
struct StringCodingKey: CodingKey {
let stringValue: String
init?(stringValue: String) {
self.stringValue = stringValue
}
import 'dart:async';
import 'dart:ui';
import 'package:flutter/widgets.dart';
// Usage:
Future<void> main() async {
await precacheImageCustom(SplashPage.image);
await precacheImageCustom(LoginPage.backgroundImage);
runApp(App());
@szotp
szotp / main.dart
Created February 17, 2019 13:55
simple state management
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
@szotp
szotp / SafeAccess.swift
Last active February 18, 2020 13:52
Demonstration of struct usage with threading
import Foundation
/// If T is a struct, then this class provides thread safety, because all reads and writes happen inside queue.
/// But, if T is very big, copying it may decrease performance.
class SafeAccess<T> {
private let queue = DispatchQueue(label: "Safe")
private var _value: T
init(_ value: T) {
_value = value
@szotp
szotp / SectionsExample.swift
Last active February 8, 2018 13:55
Example of simple UITableViewDataSource with configurable sections
import UIKit
protocol ModelProtocol {
}
class ModelA: ModelProtocol {
}
class BaseViewController : UIViewController {
@available(*, deprecated, message: "Use coordinator.")
override var navigationController: UINavigationController? {
return super.navigationController
}
@available(*, deprecated, message: "Use coordinator.")
override var presentedViewController: UIViewController? {
return super.presentedViewController
}