Skip to content

Instantly share code, notes, and snippets.

View liufsd's full-sized avatar
🎯
Focusing

liupeng liufsd

🎯
Focusing
View GitHub Profile
@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
@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")
}
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 / 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])
}
}
}
//
// DirectoryUtils.h
// PhotoCloud
//
// Created by liupeng on 14/11/2016.
// Copyright © 2016 liupeng. All rights reserved.
//
#import <Foundation/Foundation.h>
on run
set myVar to do shell script "defaults read com.apple.finder AppleShowAllFiles 2>/dev/null"
if myVar is "1" then
#display dialog "cuttent is show. will hide it"
do shell script "defaults write com.apple.finder AppleShowAllFiles 0"
do shell script "killall Finder"
else
#display dialog "current hidden. will show it"
do shell script "defaults write com.apple.finder AppleShowAllFiles 1"
STATUS=`defaults read com.apple.finder AppleShowAllFiles 2>/dev/null`
if [ "$STATUS" == TRUE ]; then
STATUS=`osascript -e 'tell app "Finder" to display alert "Finder is showing hidden files." buttons {"Cancel", "Hide"}'`
else
STATUS=`osascript -e 'tell app "Finder" to display alert "Finder is not showing hidden files." buttons {"Cancel", "Show"}'`
fi
if [ "$STATUS" == "button returned:Show" ]; then
defaults write com.apple.finder AppleShowAllFiles TRUE
killall Finder
elif [ "$STATUS" == "button returned:Hide" ]; then
@implementation LogProvider
+(void)writeLogFile:(NSString* )message {
NSString *applicationCacheDirectory = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) lastObject];
NSDateFormatter* formate = [[NSDateFormatter alloc] init];
[formate setDateFormat:@"yyyy-MM-dd"];
NSString* logFolder = [applicationCacheDirectory stringByAppendingPathComponent:@"SKPhotoCloudUploadLog"];
NSString* finalPath = [logFolder stringByAppendingPathComponent: [NSString stringWithFormat:@"%@.log",[formate stringFromDate:[NSDate new]]]];
NSFileHandle *output = [NSFileHandle fileHandleForWritingAtPath:finalPath];
if(output == nil) {
if (![[NSFileManager defaultManager] fileExistsAtPath:logFolder]) {
@liufsd
liufsd / ij.sh
Created December 10, 2015 06:04 — forked from suya55/ij.sh
Open a project in IntelliJ IDEA from your command line! Raw
#!/bin/sh
# check for where the latest version of IDEA is installed
IDEA=`ls -1d /Applications/IntelliJ\ * | tail -n1`
wd=`pwd`
# Setup your working directory. Edit 'work' to your working directory.
working_dir=`ls -1d ~/work/$1 | head -n1`
# were we given a directory?
if [ -d "$1" ]; then
@liufsd
liufsd / idea
Created December 10, 2015 06:04 — forked from chrisdarroch/idea
Open a project in IntelliJ IDEA from your command line!
#!/bin/sh
# check for where the latest version of IDEA is installed
IDEA=`ls -1d /Applications/IntelliJ\ * | tail -n1`
wd=`pwd`
# were we given a directory?
if [ -d "$1" ]; then
# echo "checking for things in the working dir given"
wd=`ls -1d "$1" | head -n1`