Skip to content

Instantly share code, notes, and snippets.

View buscarini's full-sized avatar

José Manuel Sánchez buscarini

View GitHub Profile
@JohnSundell
JohnSundell / ContentViewWithCollapsableHeader.swift
Last active April 25, 2024 06:41
A content view which renders a collapsable header that adapts to the current scroll position. Based on OffsetObservingScrollView from https://swiftbysundell.com/articles/observing-swiftui-scrollview-content-offset.
import SwiftUI
/// View that observes its position within a given coordinate space,
/// and assigns that position to the specified Binding.
struct PositionObservingView<Content: View>: View {
var coordinateSpace: CoordinateSpace
@Binding var position: CGPoint
@ViewBuilder var content: () -> Content
var body: some View {
import PlaygroundSupport
import SwiftUI
extension UIView {
var renderedImage: UIImage {
let image = UIGraphicsImageRenderer(size: self.bounds.size).image { context in
UIColor.lightGray.set(); UIRectFill(bounds)
context.cgContext.setAlpha(0.75)
self.layer.render(in: context.cgContext)
}
return image
@0xced
0xced / generate_storyboard_constants.py
Created January 25, 2018 09:59
Generate constants from storyboard identifiers
#!/usr/bin/env python
# Adapted from https://joris.kluivers.nl/blog/2014/02/10/storyboard-identifier-constants/ (https://github.com/kluivers/storyboard-constants)
# * Support for accessibility identifiers and accessibility labels
# * Easily extendable with xpath definitions
# * Valid identifiers
# * Namespaced constants, idea from https://www.mikeash.com/pyblog/friday-qa-2011-08-19-namespaced-constants-and-functions.html
PREFIX = ''
SPACING = '\t'
@shaps80
shaps80 / Color.swift
Last active December 25, 2019 04:06
A Swift color value-type. Includes hexadecimal values support, ExpressibleByString, Swift 4 Codable and other conveniences.
/*
Copyright © 01/10/2016 Shaps
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
@steipete
steipete / Warnings.xcconfig
Last active March 13, 2018 14:47
Did you knew that Clang Analyzer as alpha checkers? Early Christmas is here! (Ignore the rest... we run our PDF SDK https://pspdfkit.com with -Weverything because warnings are awesome to prevent bugs) - See https://gist.github.com/steipete/28849365e603dc2015c7107d85142e7b/revisions for a list of Xcode 8.3 changes
// clang -cc1 -analyzer-checker-help
// OVERVIEW: Clang Static Analyzer Checkers List
// USAGE: -analyzer-checker <CHECKER or PACKAGE,...>
//
// CHECKERS:
// alpha.core.BoolAssignment Warn about assigning non-{0,1} values to Boolean variables
// alpha.core.CallAndMessageUnInitRefArg
// Check for logical errors for function calls and Objective-C message expressions (e.g., uninitialized arguments, null function pointers, and pointer to undefined variables)
// alpha.core.CastSize Check when casting a malloc'ed type T, whether the size is a multiple of the size of T
// alpha.core.CastToStruct Check for cast from non-struct pointer to struct pointer
@jdegoes
jdegoes / IO.scala
Created August 9, 2016 22:26
A pedagogical implementation of the IO monad in Scala in 14 LOC
case class IO[A](unsafePerformIO: () => A) {
def map[B](ab: A => B): IO[B] = IO(() => ab(unsafePerformIO()))
def flatMap[B](afb: A => IO[B]): IO[B] =IO(() => afb(unsafePerformIO()).unsafePerformIO())
def tryIO(ta: Throwable => A): IO[A] =
IO(() => IO.tryIO(unsafePerformIO()).unsafePerformIO() match {
case Left(t) => ta(t)
case Right(a) => a
})
}
object IO {
I am not a fan of Xcode. Here are ~160~ 200 problems, the first hundred or so issues were filed mostly in
July and August 2016 in a fit of rage. Mostly on weekends working (slowly) on side-projects. I have also
taken days of my employer's time filing others of these - so the company was not getting value for my time.
I believe a paid intern could have found many of these - just start a screen recorder, and when you see something,
stop and cut a quick movie. Many have been around for several major versions.
I'm volunteering chunks of my life (15-30 minutes per) to one of the most valuable companies in the world, which seems
kind of messed up. Things get worse the more complex the project and the longer Xcode been's running.
Apple folks - check out rdar://22524679
@rnapier
rnapier / fp.swift
Last active February 3, 2018 23:06
FP examples in Swift
// Just spending Saturday afternoon rewriting FP examples from Backus in Swift.
// http://worrydream.com/refs/Backus-CanProgrammingBeLiberated.pdf
//
// Surprising fact: reasonably possible with only one major problem (tuples are not collections)
// Unsurprising fact: you shouldn't write Swift this way
// Other unsurprising fact: Rob should probably get out more
// Don't judge me
// For future research: is it possible to build this without arrayFormHack and the arity 2 ∘?
// Basically, can we do this entirely with tuples or entirely with arrays? Currently almost everything

Purescript Halogen: Past, Present, and Future

Talk by John De Goes

Halogen is a Purescript UI framework in the spirit of React (but doesn’t wrap React) with the goal of expressing UIs in a declarative and type-safe way.

FRP & React

FRP (in typed languages) typically needs “reactive” data types to be parameterized over the type of the things they “produce” so the FRP machinery can control how values of that type get passed around. In the more React-y style, events are supported somehow internally by the main UI data type (so don’t need to be parameterized in that way).

public protocol Selfie: CustomStringConvertible {}
extension Selfie {
var description: String {
let mirror = Mirror(reflecting: self)
return "\(mirror.subjectType)( \(mirror.children.map({ "\($0!): \($1) "}).joinWithSeparator(", ")))"
}
}