Skip to content

Instantly share code, notes, and snippets.

View yiplee's full-sized avatar
🎯
Focusing

yiplee yiplee

🎯
Focusing
View GitHub Profile
//
// MyController.h
//
// Created by Ben Copsey on 20/07/2009.
// Copyright 2009 All-Seeing Interactive. All rights reserved.
//
#import <Foundation/Foundation.h>
#import <GHUnit/GHUnit.h>
@class ASINetworkQueue;
@yiplee
yiplee / layerRotation.m
Last active August 29, 2015 14:15
CALayer Rotation Animation
// get the current rotation value
NSNumber *rotationAtStart = [myLayer valueForKeyPath:@"transform.rotation"];
// create rotaion transform with given degree
CATransform3D myRotationTransform = CATransform3DRotate(myLayer.transform, myRotationAngle, 0.0, 0.0, 1.0);
// set layer's transform value to target value
myLayer.transform = myRotationTransform;
// create animation
#!/bin/sh
projectfile=`find -d . -name 'project.pbxproj'`
projectdir=`echo *.xcodeproj`
projectfile="${projectdir}/project.pbxproj"
tempfile="${projectdir}/project.pbxproj.out"
savefile="${projectdir}/project.pbxproj.mergesave"
cat $projectfile | grep -v "<<<<<<< HEAD" | grep -v "=======" | grep -v "^>>>>>>> " > $tempfile
cp $projectfile $savefile
@yiplee
yiplee / UINavigationBar+CustomHeight.h
Created October 27, 2015 05:40 — forked from maciekish/UINavigationBar+CustomHeight.h
Custom UINavigationBar height working in iOS 7 and 8. To use, find your navigation bar reference and just setHeight:200 etc.
//
// UINavigationBar+CustomHeight.h
//
// Copyright (c) 2014 Maciej Swic
//
// 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

Fast Enumeration in Objc

遍历一个容器内所有的元素,是在开发过程中很常见的操作。在 Objc 中常用的有 C style loop(据说在 swift 3 中已不再支持)、Block style enumerate、NSEnumerator 和 for in style。前两种比较简单这里不再赘述,先简单谈一下 NSEnumerator。 NSEnumerator 是一个抽象类,只有两个方法,-(NSArray*)allobjects-(id)nexObject。你必须继承 NSEnumerator 然后使用子类的实例,在内部实现中使用自定义的状态值来记住当前遍历的状态,以便实现 -(id)nextObject 方法,如果你得容器类存放的数据是有序的,这个状态值可以是当前遍历到的元素的序号;当-(id)nexObject 返回 nil的时候遍历结束。-(NSArray*)allObjects不是一定要实现的,NSEnumerator 提供了一个默认的实现,既循环执行 -(id)nexObject 把返回的 object 塞到一个 NSMutableArray 里面,为了效率考虑可以根据情况自己提供更快的实现。 如果不关心 index 的话,for in style 的遍历是一种更方便的写法,也是遍历速度“最快”的,毕竟只有遵循 NSFastEnumeration 协议的才能这样遍历。NSArray , NSDictionary , NSSet 都实现了这个协议。

for (NSNumber *number in array) {
	//do something
}
@yiplee
yiplee / NSArray+FlatEnumerator.h
Last active December 14, 2016 07:25
给你一个嵌套的 NSArray 数据,实现一个迭代器类,该类提供一个 next() 方法,可以依次的取出这个 NSArray 中的数据。 比如 NSArray 如果是 [1,[4,3],6,[5,[1,0]]], 则最终应该输出:1, 4, 3, 6, 5, 1, 0 。 另外,实现一个 allObjects 方法,可以一次性取出所有元素。
//
// NSArray+FlatEnumerator.h
// Flay Array
//
// Created by yiplee on 2016/12/13.
//
#import <Foundation/Foundation.h>
@class NSArrayFlatEnumerator;
@yiplee
yiplee / config.node1.yaml
Last active July 9, 2021 00:29
Pando deployment
db:
dialect: mysql
host: db
port: 3306
user: root
password: pando
database: pando_1
# node_1 dapp's keystore generated on mixin developer dashboard
dapp:
@yiplee
yiplee / permision_test.go
Last active January 3, 2022 05:36
install stringer: go get -u -a golang.org/x/tools/cmd/stringer
package core
import (
"testing"
)
func TestPermissionFromName(t *testing.T) {
for i := 0; i < len(_Permission_index)-1; i++ {
left, right := _Permission_index[i], _Permission_index[i+1]
name := _Permission_name[left:right]