Skip to content

Instantly share code, notes, and snippets.

View qnoid's full-sized avatar
💭
I have been raised by women. My single mother, my grandma, my godmother.

Markos Zoulias Charatzas qnoid

💭
I have been raised by women. My single mother, my grandma, my godmother.
View GitHub Profile
@qnoid
qnoid / gist:5264139
Created March 28, 2013 15:36
A simple macro for marking objective-c class and method as deprecated
#define DEPRECATED(since, replaced) __attribute__((deprecated("since '" #since "' use '" #replaced "'")))
@qnoid
qnoid / gist:5269777
Last active December 15, 2015 13:49
How to use [diagnostic pragmas][1] to annotate a class/method so as to show a message on compile. [1]: http://gcc.gnu.org/onlinedocs/gcc/Diagnostic-Pragmas.html PS. Tested on XCode 4.6.1 http://i.minus.com/iepXiFcByxuKt.png
#define DO_PRAGMA(x) _Pragma (#x)
#define MESSAGE(x) DO_PRAGMA(message (x))
@interface TBFoo : NSObject
@end
@implementation TBFoo
-(void)bar MESSAGE("Hello World!"){}
@qnoid
qnoid / ApplicationScopeTest.java
Last active December 18, 2015 15:39
Related gists: ApplicationScope.java https://gist.github.com/qnoid/5805659
import org.junit.Test;
import org.junit.Assert;
import java.util.function.Consumer;
public class ApplicationScopeTest
{
@Test(expected=RuntimeException.class)
public void testApplicationScope() throws Exception
{
ApplicationScope applicationScope = new ApplicationScope();
import java.util.function.Consumer;
import java.util.function.Supplier;
public class ApplicationScope
{
private volatile String value;
private final Supplier<String> supplier;
public class Main
{
static class Number
{
final int value;
public Number(int value) {
this.value = value;
}
}
@qnoid
qnoid / gist:6140282
Created August 2, 2013 14:29
Animate an UIBarButtonItem that has been assigned a UIButton as its customview. The UIButton uses an image that is mirrored on the X axis hence appear as if it's rotating.
-(IBAction)tap:(id)sender
{
UIBarButtonItem *refresh = self.navigationItem.rightBarButtonItem;
CALayer *layer = ((UIButton*)refresh.customView).imageView.layer;
CABasicAnimation *rotate = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
rotate.timingFunction = [CAMediaTimingFunction functionWithName: kCAMediaTimingFunctionLinear];
rotate.fromValue = @(0);
rotate.toValue = @(2 * M_PI);
@qnoid
qnoid / QNDUnit.m
Last active December 26, 2015 18:38
An example that shows the do's and don't's on a method contract. Summary, DON'T code defensively DO add precondition checks DO add runtime checks DON'T be paranoid
@implementation QNDUnit
- (id)initWithCalculator:(QNDCalculator*) calculator
{
self = [super init];
if (self) {
_calculator = calculator;
}
@qnoid
qnoid / main.m
Created November 12, 2013 14:53
To quickly try a snippet of code in objective-c using clang from the command line. 1. Create a "main.m" file (see example below) 2. Compile using "clang -o main main.m -lobjc -framework Foundation" 3. Run "./main"
#import <Foundation/Foundation.h>
int main(int argc, char *argv[])
{
NSArray *array = @[ @"a", @"b", @"c" ];
for (NSUInteger i = 0; i < array.count; i++)
{
NSLog(@"%@", array[i]);
}
class FooViewController: UIViewController
{
}
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
let fooViewController = FooViewController()
let view = self.window!.snapshotViewAfterScreenUpdates(false)
let viewController = UIViewController()
@qnoid
qnoid / ViewController.swift
Created January 22, 2016 12:31
In a capture list, there is no need to capture a reference to "self" if you need a reference to an instance self holds. https://twitter.com/qnoid/status/690507191057551360
class ViewController : UIViewController
{
var foo = "foo"
func hello()
{
let closure = { [foo = self.foo] in
print("Hello \(foo)!")
}
}