Skip to content

Instantly share code, notes, and snippets.

View chourobin's full-sized avatar

Robin Chou chourobin

View GitHub Profile
@barbietunnie
barbietunnie / modal-view.md
Last active November 3, 2022 10:04
Swift Modal View Controller with transparent background

You can do it like this:

In your main view controller:

func showModal() {
    let modalViewController = ModalViewController()
    modalViewController.modalPresentationStyle = .OverCurrentContext
    presentViewController(modalViewController, animated: true, completion: nil)
}
@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,

@knowbody
knowbody / RNfontWeights.js
Created July 14, 2016 13:42
React Native Font Weight Cheatsheet iOS
{ fontWeight: '100' }, // Thin
{ fontWeight: '200' }, // Ultra Light
{ fontWeight: '300' }, // Light
{ fontWeight: '400' }, // Regular
{ fontWeight: '500' }, // Medium
{ fontWeight: '600' }, // Semibold
{ fontWeight: '700' }, // Bold
{ fontWeight: '800' }, // Heavy
{ fontWeight: '900' }, // Black
@tejacques
tejacques / HOCBaseRender.tsx
Last active May 2, 2022 13:05
React Higher Order Components in TypeScript
import * as React from 'react';
import { Component } from 'react';
export default function HOCBaseRender<Props, State, ComponentState>(
Comp: new() => Component<Props & State, ComponentState>) {
return class HOCBase extends Component<Props, State> {
render() {
return <Comp {...this.props} {...this.state}/>;
}
}
@mrzmyr
mrzmyr / index.js
Created November 22, 2015 16:56
React Native - Detect Double Tap
var Index = React.createClass({
getInitialState: function () {
return {
lastPress: 0
}
},
onPress: function () {
var delta = new Date().getTime() - this.state.lastPress;
@jshier
jshier / ResponseSerializer.swift
Last active February 12, 2017 23:06
Custom ResponseSerializer for Alamofire 3
static func CloudFlareResponseSerializer<T: Decodable where T == T.DecodedType>() -> ResponseSerializer<T, CloudFlareError> {
return ResponseSerializer { (request, response, data, error) in
guard error == nil else {
return .Failure(CloudFlareError.NetworkError(error: error!))
}
let JSONResult = Request.JSONResponseSerializer().serializeResponse(request, response, data, nil)
guard case let .Success(responseJSON) = JSONResult else {
return .Failure(CloudFlareError.SerializationError(error: JSONResult.error!))
}
@17twenty
17twenty / GoWithC.go
Last active July 11, 2016 04:29
Cross Compiling and Language Interop oh my!
package main
import (
"./binding"
"fmt"
)
func main() {
binding.PrintHello()
binding.Seed(1)
fmt.Println(binding.Random())
@jshier
jshier / gist:b4858a4b417217fe8c73
Last active June 21, 2017 12:53
Generic Alamofire response serializer with Argo and a custom error type
static func CloudFlareResponseSerializer<T: Decodable where T == T.DecodedType>() -> GenericResponseSerializer<T> {
return GenericResponseSerializer { (request, response, data) -> Result<T> in
guard let validData = data else {
let failureReason = "Tried to decode response with nil data."
let error = Error.errorWithCode(.DataSerializationFailed, failureReason: failureReason)
return .Failure(data, CloudFlareError.SerializationError(error: error))
}
let JSONSerializer = Request.JSONResponseSerializer(options: .AllowFragments)
let JSONResult = JSONSerializer.serializeResponse(request, response, validData)
@gaearon
gaearon / ReduxMicroBoilerplate.js
Last active March 26, 2020 00:35
Super minimal React + Redux app
import React, { Component } from 'react';
import { createStore, combineReducers, applyMiddleware, bindActionCreators } from 'redux';
import { provide, connect } from 'react-redux';
import thunk from 'redux-thunk';
const AVAILABLE_SUBREDDITS = ['apple', 'pics'];
// ------------
// reducers
// ------------
@JaviLorbada
JaviLorbada / FRP iOS Learning resources.md
Last active May 29, 2024 07:33
The best FRP iOS resources.

Videos