Skip to content

Instantly share code, notes, and snippets.

View baarde's full-sized avatar

Nicolas Bachschmidt baarde

View GitHub Profile
@baarde
baarde / automatic_unegation.rb
Last active January 30, 2021 01:41
Ruby Automatic Unegation
module AutomaticUnegation
def method_missing(name, *args, &block)
return super unless unegated = unegated_method_name(name)
!send(unegated, *args, &block)
end
def respond_to?(name, include_private = false)
super || unegated_method_name(name) != nil
end
@baarde
baarde / NSBundle+XYZCurrent.m
Created February 26, 2018 17:17
NSBundle (XYZCurrent)
#import <Foundation/Foundation.h>
#import <execinfo.h>
#import <dlfcn.h>
static NSBundle *XYZBundleForAddressPointer(const void *pointer);
static NSBundle *XYZBundleForExecutablePath(NSString *execPath);
static NSString *XYZBundlePathFromExecutablePath(NSString *execPath);
static NSString *XYZFrameworkPathFromLibraryPath(NSString *libraryPath);
@implementation NSBundle (XYZCurrent)

Keybase proof

I hereby claim:

  • I am baarde on github.
  • I am baarde (https://keybase.io/baarde) on keybase.
  • I have a public key ASDY_8OhUKieFpoZhcwVoDZVgHmYCAS5OCw1CZfneBSH4Qo

To claim this, I am signing this object:

class CircleView: UIView {
override func drawRect(rect: CGRect) {
// Draw this:
// https://twitter.com/baarde/status/696716466037657600
UIColor.blackColor().setFill()
UIRectFill(rect)
let center = CGPoint(x: bounds.midX, y: bounds.midY)
let radius = CGFloat(120)
@baarde
baarde / test1.swift
Created January 20, 2016 11:29
Mixing methods and properties in Swift
protocol Worker {
func work()
}
struct AnyWorker: Worker {
let work: () -> Void
func work() {
print("1")
#import <Foundation/Foundation.h>
@protocol OS_Foo <NSObject> @end
typedef NSObject<OS_Foo> * Foo;
@protocol OS_Bar <NSObject> @end
typedef NSObject<OS_Bar> *__attribute__((objc_independent_class)) Bar;
@interface Test : NSObject
@end
@baarde
baarde / fp-obj-c.m
Created February 9, 2015 14:47 — forked from n-b/fp-obj-c.m
//#!/usr/bin/env objc-run
#import <Foundation/Foundation.h>
#import <objc/runtime.h>
#import <objc/message.h>
///
/// Typedefs
typedef id (^TargetMethod)(id arg);
#import <CommonCrypto/CommonCrypto.h>
@baarde
baarde / SynchronousAFNetworking.m
Last active October 7, 2017 20:05
How to use AFNetworking synchronously
#import "AFNetworking.h"
int main(void)
{
NSURL *baseURL = [NSURL URLWithString:@"http://graph.facebook.com/"];
AFHTTPRequestOperationManager *operationManager = [[AFHTTPRequestOperationManager alloc] initWithBaseURL:baseURL];
AFHTTPRequestOperation *operation = [operationManager GET:@"Octiplex" parameters:nil success:nil failure:nil];
[operationManager.operationQueue waitUntilAllOperationsAreFinished];
[[NSRunLoop currentRunLoop] runUntilDate:[NSDate date]]; // Executes async notification blocks waiting in the main queue
NSLog(@"Response: %@", operation.responseObject);
@baarde
baarde / injection.js
Created December 10, 2013 13:20
Testing JavaScript injection
alert("Hello world!");