Skip to content

Instantly share code, notes, and snippets.

View keefo's full-sized avatar
📺

Xu Lian keefo

📺
View GitHub Profile
@keefo
keefo / gist:98c1664f385dcb7db459
Created February 27, 2012 06:10
CoreAnimation Group
CAAnimationGroup *animationGroup = [CAAnimationGroup animation];
[animationGroup setAnimations:[NSArray arrayWithObjects:simpleAnimationOne, simpleAnimationTwo, nil]];
[animationGroup setDuration:1.0f];
[animationGroup setAutoreverses:YES];
[[moveMe layer] addAnimation:animationGroup forKey:@"group action"];
@keefo
keefo / NSNotificationCenter+ObserverAdditions.h
Created August 21, 2012 15:19
Simplifying NSNotificationCenter block
#import <Foundation/Foundation.h>
@interface NSNotificationCenter (ObserverAdditions)
- (void)registerObserver:(id)observer
forName:(NSString *)name
object:(id)obj
queue:(NSOperationQueue *)queue
usingBlock:(void (^)(NSNotification *))block;
@keefo
keefo / gist:3483501
Created August 26, 2012 20:47
willPositionSheet
- (NSRect)window:(NSWindow *)window willPositionSheet:(NSWindow *)sheet
usingRect:(NSRect)rect
{
rect.origin.y -= 14; // or as much as we need
return rect;
}
@keefo
keefo / gist:5149929
Created March 13, 2013 07:14
get router MACAddress
- (NSString *)routerMACAddress {
NSMutableString *MACAddress = [NSMutableString string];
SCDynamicStoreRef theDynamicStore = SCDynamicStoreCreate(nil, CFSTR("FindCurrentInterfaceAndIP"), nil, nil);
CFDictionaryRef returnedPList = SCDynamicStoreCopyValue(theDynamicStore, CFSTR("State:/Network/Global/IPv4"));
CFRelease(theDynamicStore);
if ([(__bridge NSDictionary *)returnedPList valueForKey:@"Router"] != nil) {
NSTask *arpTask = [[NSTask alloc] init];
NSPipe *newPipe = [NSPipe pipe];
NSFileHandle *readHandle = [newPipe fileHandleForReading];
@interface NSImage (GIF)
- (BOOL)isGifImage;
- (BOOL)saveAnimatedGIFToFile:(NSString*)filepath;
@end
@implementation NSImage (GIF)
- (BOOL)isGifImage
{
- (NSImage *)resizeTo:(NSSize)newsize
{
NSImage *resizedImage = [[NSImage alloc] initWithSize:newsize];
NSSize originalSize = [self size];
[resizedImage lockFocus];
[self drawInRect: NSMakeRect(0, 0, newsize.width, newsize.height) fromRect: NSMakeRect(0, 0, originalSize.width, originalSize.height) operation: NSCompositeSourceOver fraction: 1.0];
[resizedImage unlockFocus];
#if __has_feature(objc_arc)
return resizedImage;
#else
@interface NSWindow (FullScreen)
- (BOOL)isFullScreen;
@end
@implementation NSWindow (FullScreen)
- (BOOL)isFullScreen
{
#import <Cocoa/Cocoa.h>
@interface AsyncCopyController : NSObject
-(OSStatus)copySource : (NSString *)aSource ToDestination: (NSString *)aDestDir setDelegate : (id)object;
//delegate method
-(void)didReceiveCurrentPath : (NSString *)curremtItemPath bytesCompleted : (unsigned long long)floatBytesCompleted currentStageOfFileOperation : (unsigned long)stage;
-(void)didCopyOperationComplete : (BOOL)boolean;
-(void)didReceiveCopyError : (NSString *)Error;
-(void)cancelAllAsyncCopyOperation;
@end
@keefo
keefo / postweiboviamiao.m
Last active December 20, 2015 14:49
Post Weibo via Miao
if ([[NSWorkspace sharedWorkspace] absolutePathForAppBundleWithIdentifier:@"com.beyondcow.Miao"]) {
//if find Miao on this Mac then post text via Miao system service port
NSString *text = @"Hello world!";
[[NSPasteboard generalPasteboard] clearContents];
[[NSPasteboard generalPasteboard] setString:text forType:NSStringPboardType];
NSPerformService(@"Miao Post Weibo", [NSPasteboard generalPasteboard]);
}
#import "AppDelegate.h"
@interface NSStatusBar(Private)
- (id)_statusItemWithLength:(double)length withPriority:(int)priority;
@end
@interface AppDelegate()
{
NSStatusItem *item;
}