Skip to content

Instantly share code, notes, and snippets.

View valexa's full-sized avatar
๐ŸŒ—
๐Ÿ”๏ธ๐Ÿ„๐Ÿชต๐ŸŒฟ๐Ÿ“๐Ÿ“š๐Ÿ–ฅ๏ธ๐Ÿ–ฑ๏ธ๐Ÿ“ฑ

Vlad Alexa valexa

๐ŸŒ—
๐Ÿ”๏ธ๐Ÿ„๐Ÿชต๐ŸŒฟ๐Ÿ“๐Ÿ“š๐Ÿ–ฅ๏ธ๐Ÿ–ฑ๏ธ๐Ÿ“ฑ
View GitHub Profile
@valexa
valexa / gist:1940170
Created February 29, 2012 11:21
conformsToProtocol
int class_count = objc_getClassList(nil, 0);
Class *buffer = calloc(class_count, sizeof(Class));
if (buffer) {
//NSLog(@"allocated a %d bytes buffer",malloc_size(buffer));
objc_getClassList(buffer,class_count);
//NSLog(@"total %i classes",class_count);
for (int i = 0; i < class_count; ++i) {
Class currClass = buffer[i];
if ( class_respondsToSelector(currClass, @selector(conformsToProtocol:)) ) {
if ([currClass conformsToProtocol:@protocol(NSMutableCopying)]) {
* thread #1: tid = 0x1c07, 0x0000000100040767 Memory Magic`-[TestString dealloc] + 23 at TestString.m:29, stop reason = breakpoint 1.1
frame #0: 0x0000000100040767 Memory Magic`-[TestString dealloc] + 23 at TestString.m:29
frame #1: 0x0000000100002a3c Memory Magic`-[MenuBar theEvent:] + 1116 at MenuBar.m:58
frame #2: 0x00007fff85b5547a CoreFoundation`_CFXNotificationPost + 2554
frame #3: 0x00007fff8ad0c846 Foundation`-[NSNotificationCenter postNotificationName:object:userInfo:] + 64
frame #4: 0x00000001000038d8 Memory Magic`-[MenuBarIcon memoryLoop] + 984 at MenuBarIcon.m:53
frame #5: 0x0000000100003a22 Memory Magic`-[MenuBarIcon initWithFrame:] + 210 at MenuBarIcon.m:65
frame #6: 0x00007fff82767148 AppKit`-[NSView init] + 62
frame #7: 0x000000010000255e Memory Magic`-[MenuBar init] + 366 at MenuBar.m:25
frame #8: 0x00007fff826abeca AppKit`-[NSCustomObject nibInstantiate] + 382
-(NSString*)execTask:(NSString*)launch args:(NSArray*)args
{
if ([[NSFileManager defaultManager] isExecutableFileAtPath:launch] != YES){
[bottomLeftLabel setStringValue:[NSString stringWithFormat:@"%@ not found",launch]];
return nil;
}
NSPipe *stdout_pipe = [[NSPipe alloc] init];
[image setWantsLayer:YES];
CALayer *flayer = [image layer];
[flayer removeAllAnimations];
[backImage setWantsLayer:YES];
CALayer *blayer = [backImage layer];
[blayer removeAllAnimations];
NSView *superView = [image superview];
[superView setWantsLayer:YES];
NSView *parent = [[NSView alloc] initWithFrame:NSZeroRect];
NSView *child = [[NSView alloc] initWithFrame:NSZeroRect];
[parent addSubview:child];
[child setWantsLayer:YES];
CALayer *childLayer = [child layer];
CATransformLayer *transformLayer = [CATransformLayer layer];
[transformLayer addSublayer:childLayer];
[parent setWantsLayer:YES];
NSLog(@"%@",childLayer);
NSLog(@"%@",transformLayer.sublayers);
float lastTick = 0.0;
for (int i = 0; i <= 900; i++) {
float t = [self tickX:9 timesOfTotal:900 current:i lastTick:lastTick];
if (t > 0) {
NSLog(@"%f %i",t,i);
lastTick = t;
}
}
@implementation LaunchButton
- (id)initWithFrame:(NSRect)frame {
self = [super initWithFrame:frame];
if (self) {
// Initialization code here.
NSTrackingArea *area = [[NSTrackingArea alloc] initWithRect:NSZeroRect options:NSTrackingMouseEnteredAndExited | NSTrackingActiveAlways | NSTrackingInVisibleRect owner:self userInfo:nil];
[self addTrackingArea:area];
@valexa
valexa / gist:8621322
Created January 25, 2014 18:43
NSDraggingSession
- (void)mouseDown:(NSEvent*)event
{
//create a NSPasteboardItem
NSPasteboardItem *pbItem = [NSPasteboardItem new];
[pbItem setDataProvider:self forTypes:[NSArray arrayWithObjects:NSPasteboardTypeTIFF, nil]];
//create a new NSDraggingItem with our pasteboard item.
NSDraggingItem *dragItem = [[NSDraggingItem alloc] initWithPasteboardWriter:pbItem];
NSPoint dragPosition = [self convertPoint:[event locationInWindow] fromView:nil];
public func RegexValidationWithMessage(_ message:String, regex:String, allowingNull:Bool = true) -> Validation<String>? {
if let regex = try? NSRegularExpression(pattern: regex, options: .CaseInsensitive) {
return Validation<String>(message: message, validation: { (value) -> Bool in
let nullValidation = NonEmptyStringValidation("")
guard let stringValue = value else {
return false
}
//1 , cant be right as assigning instance variable does not make a copy
var fooBar = self.fooBar
fooBar.forEach({ foo in
if foo.id == bar.id {
fooBar.remove(at: fooBar.index(of: foo)!)
}
})
self.fooBar = fooBar
//2, seems right as enumerated makes a copy