Skip to content

Instantly share code, notes, and snippets.

View stigi's full-sized avatar
✌️
Casual coding

Ullrich Schäfer stigi

✌️
Casual coding
View GitHub Profile
@stigi
stigi / persisted-hooks.js
Created October 27, 2018 08:15
A small experiment on how a persisted state hook good be implemented
import React, { useState } from "react";
import ReactDOM from "react-dom";
const usePersistedState = (initialState, key) => {
// Check if we have a value stored
let value = localStorage.getItem(key);
if (!value) {
value = initialState;
} else {
value = JSON.parse(value);
@stigi
stigi / fix-rn-xcode10-build.sh
Created October 24, 2018 11:57
Fixes Xcode 10 builds for older react native issues.
#!/bin/sh
# Make sure node packages are there
yarn
# 1st fix: glog config.h not found
# Manually trigger 3rd party installs
cd node_modules/react-native
./scripts/ios-install-third-party.sh
### Keybase proof
I hereby claim:
* I am stigi on github.
* I am ullrich (https://keybase.io/ullrich) on keybase.
* I have a public key ASBvBQm1Dl9T7YVshwg3uQq5P9VyAzlN4bQNQef1Z7rzYgo
To claim this, I am signing this object:
def fetchPassword(identifier) {
if (!Os.isFamily(Os.FAMILY_MAC)) {
println "Not on macOS, falling back to using keystore password from Environment"
return props.getProperty(identifier)
}
def keychainLabel = "${identifier}"
println "Fetching keychain password with label '${keychainLabel}"
def stdout = new ByteArrayOutputStream()
@stigi
stigi / doubleToInt.swift
Created March 12, 2018 20:08
Safely convert Double to Int and take care of overflows. Wont take care of precision for large values. Raw
func doubleToInt(_ input: Double) -> Int? {
guard (
input < Double(Int.max).nextDown &&
input > Double(Int.min).nextDown)
else {
// Int overflow
return nil
}
import Realm from 'realm'
const openAndCloseWithModel = async (schema) => {
let realm
try {
console.log("Opening realm")
realm = await Realm.open({schema})
.catch((e) => {
console.error("Cought rejection error")
@stigi
stigi / fake-realm.js
Created January 10, 2018 19:14
In memory realm mock with flow types
// @flow
// Adapted from https://gist.github.com/hyb175/beb9ceed4c34300ba7c77d3d6d44ae52
import type {ModelSchemaType} from '../schema'
type CallbackType = ()=>{}
type RealmObjectType = {
realmModelName: string
}
Exception Type: SIGSEGV
Exception Codes: SEGV_ACCERR at 0x21e4f30d
Crashed Thread: 0
Thread 0 Crashed:
0 libobjc.A.dylib 0x38f4f626 objc_msgSend + 5
1 UIKit 0x310b2fb1 -[UITableViewRowData(UITableViewRowDataPrivate) _updateNumSections] + 78
2 UIKit 0x310b2ef9 -[UITableViewRowData invalidateAllSections] + 72
3 UIKit 0x310b2c75 -[UITableView _updateRowData] + 208
Process: Xcode [99304]
Path: /Applications/Xcode.app/Contents/MacOS/Xcode
Identifier: com.apple.dt.Xcode
Version: 7.3 (10183.3)
Build Info: IDEFrameworks-10183003000000000~2
Code Type: X86-64 (Native)
Parent Process: ??? [1]
Responsible: Xcode [99304]
User ID: 1666714533
import Foundation
protocol ProtocolType {
func test() -> ()
}
struct StructOne: ProtocolType {
func test() -> () {}
}