Skip to content

Instantly share code, notes, and snippets.

Michael Schneider maicki

Block or report user

Report or block maicki

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@maicki
maicki / update-nested-objects.js
Last active Sep 20, 2017
Update nested objects via JS
View update-nested-objects.js
// Original discussion: https://github.com/facebook/react/issues/10708#issuecomment-329443706
// Object.assign: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign
const newInstrument = Object.assign({}, instrument, {
row: Object.assign({}, instrument.row, {
isSelected: true
})
});
// Spread syntax: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Spread_operator
@maicki
maicki / arrays.js
Created Sep 17, 2017
Arrays in JavaScript
View arrays.js
const iterateArray = (value, array) => {
console.log(array);
array.forEach(() => {
console.log(value);
});
}
const N = 10;
iterateArray('a', Array(N).fill());
iterateArray('b', Array.apply(null, {length: N}));
@maicki
maicki / dispatchBlockWait.m
Created May 7, 2017
Examples how to use dispatch_block_wait in Objective C and Swift
View dispatchBlockWait.m
int main(int argc, const char * argv[]) {
@autoreleasepool {
// Code with dispatch_block_wait
__auto_type a = dispatch_block_create(DISPATCH_BLOCK_INHERIT_QOS_CLASS, ^{
NSLog(@"Before Sleep 1");
sleep(4);
NSLog(@"After Sleep 2");
});
dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), a);
@maicki
maicki / MSAtomicFlag.h
Created May 6, 2017
Atomic Flag Helper
View MSAtomicFlag.h
#pragma once
// Automatic getter and setter
#define MISAtomicSetterDeclaration(type, name, flag)\
- (void)name:(type)value\
{\
MIS::Atomic::setFlag(self, flag, value);\
}\
#define MISAtomicGetterDeclaration(type, name, flag)\
@maicki
maicki / stackobjects.m
Created Apr 25, 2017
Stack objects in Objective-C
View stackobjects.m
#import <Foundation/Foundation.h>
#import <objc/runtime.h>
@interface SomeClass : NSObject
@property (nonatomic, assign) NSInteger someDefaultNumber;
@property (nonatomic, assign) NSInteger someCustomNumber;
- (void)method;
@end
@maicki
maicki / weakify_strongify.m
Last active Apr 30, 2019
Weakify / Strongify dance with multiple blocks
View weakify_strongify.m
//
// main.m
// WeakifyStrongify
//
// Created by Michael Schneider on 3/20/17.
// Copyright © 2017 mischneider. All rights reserved.
//
#import <Foundation/Foundation.h>
@maicki
maicki / MSContext.m
Created Feb 18, 2017
Thread safe KVC handling for undefined keys
View MSContext.m
#import <pthread.h>
@interface MSContext : NSObject
@end
@implementation MSContext {
pthread_mutex_t _mutex;
}
@maicki
maicki / ASViewControllerContainment.swift
Last active Nov 21, 2016
ASViewController Containment
View ASViewControllerContainment.swift
import UIKit
import AsyncDisplayKit
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
@maicki
maicki / ASDK-2.0-Layout-Convert-1.x-To-2.0.md
Last active Sep 13, 2016
ASDK 2.0 Layout Convert 1.x to 2.0
View ASDK-2.0-Layout-Convert-1.x-To-2.0.md

ASDK 2.0 Layout Convert 1.x To 2.0

With 2.0 one of the goals was to simplify the layout system in ASDK. There was a lot of additional functionality introduced that where not thought through to 100%. This guide should give you a good overview what changed from ASDK 1.x to 2.0 and what you have to do in your app to

All of the example projects are updated to the latest code changes so check them out in case you would like to see examples how to use the layout API changes we did.

Introduction of new sizing properties

With ASDK 2.0 we introduced a new type that is called ASSize. ASSize has the following declaration:

typedef struct {
@maicki
maicki / ASDK-Snapshot-Testing.md
Last active Sep 3, 2016
How to create snapshot tests for ASDK
View ASDK-Snapshot-Testing.md

How to create snapshot tests for ASDK

  • Create a subclass of ASLayoutSpecSnapshotTestCase in the AsyncDisplayKitTests/ folder and named with ...Tests.m at the end. E.g.: ASBackgroundLayoutSpecSnapshotTests.m
  • If Xcode asks you to which target it should be added, add it to the AsyncDisplayKitTests target
  • Move the header declaration from the header (.h) file in the implementation file (.m) and remove the header file
  • Import: #import "ASLayoutSpecSnapshotTestsHelper.h"
  • Setup tests: Tests always have start with the word -(void)test... e.g. - (void)testBackground {}. A test file could look like the following:
#import "ASLayoutSpecSnapshotTestsHelper.h"
You can’t perform that action at this time.