Skip to content

Instantly share code, notes, and snippets.

View junyixin's full-sized avatar
😋

linxin junyixin

😋
View GitHub Profile
@junyixin
junyixin / mergeSort.swift
Created October 13, 2017 15:32
归并排序(Swift)
extension Array where Element: Comparable {
mutating func mergeSort(_ begin: Index, _ end: Index) {
var tmp: [Element] = []
tmp.reserveCapacity(count)
//local function
func merge(_ begin: Index, _ mid: Index, _ end: Index) {
tmp.removeAll(keepingCapacity: true)
var i = begin
@junyixin
junyixin / snip.m
Created September 12, 2017 03:55
iOS截图并保存(Objective-C)
- (void)saveImageToPhotos:(UIImage *)image {
UIImageWriteToSavedPhotosAlbum(image, self, @selector(image:didFinishSavingWithError:contextInfo:),nil);
}
- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo {
if (error == nil) {
NSLog(@"保存成功");
} else {
NSLog(@"失败");
}
@junyixin
junyixin / bubleSort.py
Last active August 15, 2017 01:15
冒泡排序(Python)
# buble sort
def bubleSort(arrList):
for passnum in range(len(arrList)-1, 0, -1):
for i in range(passnum):
if arrList[i] > arrList[i+1]:
temp = arrList[i]
arrList[i] = arrList[i+1]
arrList[i+1] = temp
@junyixin
junyixin / lock.m
Last active October 13, 2023 10:12
iOS锁屏通知(Objective-C)
//回调
static void displayStatusChanged(CFNotificationCenterRef center, void *observer, CFStringRef name, const void *object, CFDictionaryRef userInfo) {
// "com.apple.springboard.lockcomplete" 通知总是接在 "com.apple.springboard.lockstate" 通知后面
CFStringRef nameCFString = (CFStringRef)name;
NSString *lockState = (__bridge NSString*)nameCFString;
NSLog(@"Darwin notification NAME = %@",name);
if([lockState isEqualToString:@"com.apple.springboard.lockcomplete"]) {
NSLog(@"锁屏");
} else {