Skip to content

Instantly share code, notes, and snippets.

🎯
Focusing

liupeng liufsd

🎯
Focusing
Block or report user

Report or block liufsd

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
View UIImage+Pixel.swift
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 Jul 27, 2017 — forked from stepango/KotlinActivity
Android kotlin lazy view injector
View KotlinActivity
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")
}
View BindExt.kt
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 Jul 13, 2017 — forked from ericdke/splitBy.swift
Swift: split array by chunks of given size
View splitBy.swift
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])
}
}
}
View DirectoryUtils.h
//
// DirectoryUtils.h
// PhotoCloud
//
// Created by liupeng on 14/11/2016.
// Copyright © 2016 liupeng. All rights reserved.
//
#import <Foundation/Foundation.h>
View toggleAppleShowAllFiles.scpt
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"
View toggleHiddenFiles.sh
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
View LogProvider.m
@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 Dec 10, 2015 — forked from suya55/ij.sh
Open a project in IntelliJ IDEA from your command line! Raw
View ij.sh
#!/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 Dec 10, 2015 — forked from chrisdarroch/idea
Open a project in IntelliJ IDEA from your command line!
View idea
#!/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`
You can’t perform that action at this time.