Skip to content

Instantly share code, notes, and snippets.

View cxa's full-sized avatar
🦥

realazy cxa

🦥
View GitHub Profile
@smileyborg
smileyborg / InteractiveTransitionCollectionViewDeselection.m
Last active January 15, 2023 13:03
Animate table & collection view deselection alongside interactive transition (for iOS 11 and later)
// UICollectionView Objective-C example
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
NSIndexPath *selectedIndexPath = [[self.collectionView indexPathsForSelectedItems] firstObject];
if (selectedIndexPath != nil) {
id<UIViewControllerTransitionCoordinator> coordinator = self.transitionCoordinator;
if (coordinator != nil) {
[coordinator animateAlongsideTransition:^(id<UIViewControllerTransitionCoordinatorContext> context) {
@0xced
0xced / Emoji.json
Last active November 22, 2023 15:53
Extract emoji by category using the EmojiFoundation framework
{
"People" : [
"😀",
"😃",
"😄",
"😁",
"😆",
"😅",
"😂",
"🤣",
@andymatuschak
andymatuschak / States-v3.md
Last active May 1, 2024 12:32
A composable pattern for pure state machines with effects (draft v3)

A composable pattern for pure state machines with effects

State machines are everywhere in interactive systems, but they're rarely defined clearly and explicitly. Given some big blob of code including implicit state machines, which transitions are possible and under what conditions? What effects take place on what transitions?

There are existing design patterns for state machines, but all the patterns I've seen complect side effects with the structure of the state machine itself. Instances of these patterns are difficult to test without mocking, and they end up with more dependencies. Worse, the classic patterns compose poorly: hierarchical state machines are typically not straightforward extensions. The functional programming world has solutions, but they don't transpose neatly enough to be broadly usable in mainstream languages.

Here I present a composable pattern for pure state machiness with effects,

@bparadie
bparadie / react-native.d.ts
Last active January 5, 2017 09:11
Incomplete react-native.d.ts, requires react.d.ts from DefinitelyTyped
declare module "react-native" {
import * as React from 'react';
import {ComponentClass, ReactType, ReactNode, ReactElement} from 'react';
export * from 'react';
/**
* Represents the completion of an asynchronous operation
* @see lib.es6.d.ts
@rnapier
rnapier / digest.swift
Last active August 29, 2015 14:26
Associated types and type erasure for crypto digests http://stackoverflow.com/a/31748616/97337
// Just showing how to hide the underlying functions if you wanted to.
// Also makes some pieces a little less noisy
public struct DigestFunctions<Context> {
private var digester: (UnsafePointer<Void>, CC_LONG, UnsafeMutablePointer<UInt8>) -> UnsafeMutablePointer<UInt8>
private var updater: (UnsafeMutablePointer<Context>, UnsafePointer<Void>, CC_LONG) -> Int32
private var finalizer: (UnsafeMutablePointer<UInt8>, UnsafeMutablePointer<Context>) -> Int32
}
// Digests are reference types because they are stateful. Copying them may lead to confusing results.
public protocol Digest: class {
@steipete
steipete / NSData+PSPDFFoundation.m
Created July 16, 2015 08:08
After playing around with dispatch_io (https://gist.github.com/steipete/b22babbf3014e29c19f0), I ended up with this. Upside: Uses way less memory, controllable caching, similar performance, simpler code and supports priority donation implicitly since everything's sync.
static NSData *PSPDFCalculateSHA256FromFileURL(NSURL *fileURL, CC_LONG dataLength, NSError **error) {
NSCParameterAssert(fileURL);
NSData *shaData;
int fd = open(fileURL.path.UTF8String, O_RDONLY);
if (fd < 0) {
if (error) *error = [NSError pspdf_errorWithCode:PSPDFErrorCodeUnableToOpenPDF description:@"Failed to open file for calculating SHA256."];
return nil;
}

This, is actually the wrong conclusion. The entire purpose of the “inner class” is to provide value semantics while maintaining effeciency of implementation.

Is that an opinion? Or was there a meeting when the "entire purpose" of inner classes was established and I wasn't invited? Sure, they can be used for efficiency, but they can also be used for other purposes, including inner mutation.

Just for starters, Mike Ash seems to have uncovered that inner classes are used inside the standard library to provide destructors:

Destruction can be solved by using a class, which provides deinit. The pointer can be destroyed there. class doesn't have value semantics, but we can solve this by using class for the implementation of the struct, and exposing the struct as the external interface to the array.

So to say that the "entire purpose" of inner classes is efficiency is I think plainly false; they are used for many reasons. E

anonymous
anonymous / blockerList.json
Created June 25, 2015 00:05
Testing Safari Content Blocker on iMore.com
[
{
"action": {
"type": "block"
},
"trigger": {
"url-filter": ".*",
"resource-type": ["script"],
"load-type": ["third-party"],
"if-domain": ["imore.com"]
@rbobbins
rbobbins / ui_testing_in_xcode.md
Last active February 23, 2018 08:28
UI Testing in Xcode

Wil Turner, Brook Callhan: Speakers

##3 Main components/concepts that enable UI Testing:##

  • UITesting
    • Find and interact w/ UI elements
    • Validate UI properties and state
  • UIrecording
    • Updated test reports to include UI testing data
    • UI testing is enabled by XCTest and UI Accesibility
@ohanhi
ohanhi / frp.md
Last active December 23, 2022 13:06
Learning FP the hard way: Experiences on the Elm language

Learning FP the hard way: Experiences on the Elm language

by Ossi Hanhinen, @ohanhi

with the support of Futurice 💚.

Licensed under CC BY 4.0.

Editorial note