Skip to content

Instantly share code, notes, and snippets.

View liufsd's full-sized avatar
🎯
Focusing

liupeng liufsd

🎯
Focusing
View GitHub Profile
//
// DirectoryUtils.h
// PhotoCloud
//
// Created by liupeng on 14/11/2016.
// Copyright © 2016 liupeng. All rights reserved.
//
#import <Foundation/Foundation.h>
@liufsd
liufsd / splitBy.swift
Created July 13, 2017 06:05 — forked from ericdke/splitBy.swift
Swift: split array by chunks of given size
let arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
extension Array {
func splitBy(subSize: Int) -> [[Element]] {
return 0.stride(to: self.count, by: subSize).map { startIndex in
let endIndex = startIndex.advancedBy(subSize, limit: self.count)
return Array(self[startIndex ..< endIndex])
}
}
}
import android.app.Activity
import android.support.annotation.IdRes
import android.view.View
fun <T : View> Activity.bind(@IdRes idRes: Int): Lazy<T> {
@Suppress("UNCHECKED_CAST")
return unsafeLazy { findViewById(idRes) as T }
}
fun <T : View> View.bind(@IdRes idRes: Int): Lazy<T> {
@liufsd
liufsd / KotlinActivity
Created July 27, 2017 05:20 — forked from stepango/KotlinActivity
Android kotlin lazy view injector
class KotlinActivity : Activity() {
val btn: Button? by find(R.id.button)
override fun onCreate(savedInstanceState: Bundle?) {
super<Activity>.onCreate(savedInstanceState)
setContentView(R.layout.main)
btn?.setText("Hello from kotlin")
}
@liufsd
liufsd / UIImage+Pixel.swift
Created September 19, 2018 15:57
UIImage Pixel
extension UIImage {
func maxArea() -> CGRect{
let provider = self.cgImage!.dataProvider
let providerData = provider!.data
let data = CFDataGetBytePtr(providerData)
var minX = 0