Skip to content

Instantly share code, notes, and snippets.

@rraallvv
rraallvv / Cocos3d plane primitive
Last active August 29, 2015 13:57
Cocos3d plane
CC3MeshNode *node = [CC3MeshNode node];
[node populateAsCenteredRectangleWithSize:CGSizeMake(width, height)];
CC3Box bounds = { {-1, -1, -1}, {1, 1, 1} };
CC3MeshNode *cube = [CC3MeshNode node];
[cube populateAsSolidBox:bounds];
CC3MeshNode *sphere = [CC3MeshNode node];
[sphere populateAsSphereWithRadius:1 andTessellation:(CC3Tessellation){8,8}];
// sample of using POCO's ThreadPool
#include "Poco/Runnable.h"
#include "Poco/ThreadPool.h"
#include <iostream>
using namespace std;
class Worker:public Poco::Runnable{
public:
#!/bin/sh
# This script will install a Git pre-push hook that prevents force pushing the master branch.
# Install in current Git repo:
# curl -fL https://gist.githubusercontent.com/stefansundin/d465f1e331fc5c632088/raw/install-pre-push.sh | sh
# Uninstall:
# rm .git/hooks/pre-push
# in each repository that you've added this to.
GITROOT=`git rev-parse --show-toplevel 2> /dev/null`
@rraallvv
rraallvv / gist:ce2e20ef48cb61b9ee5a
Created February 16, 2015 19:19
Get viewController of a given view
#define UIViewParentController(__view) ({ \
UIResponder *__responder = __view; \
while ([__responder isKindOfClass:[UIView class]]) \
__responder = [__responder nextResponder]; \
(UIViewController *)__responder; \
})
@rraallvv
rraallvv / NSLog
Created March 11, 2015 20:59
NSLog w/o timestamp nor cached output
#define NSLog(FORMAT, ...) fprintf( stderr, "%s\n", [[NSString stringWithFormat:FORMAT, ##__VA_ARGS__] UTF8String]);
@rraallvv
rraallvv / Obj-C_introspection.m
Last active August 29, 2015 14:17
Obj-C introspection
static void printIvarsList(Class classType) {
printf("\n");
do {
unsigned int count = 0;
Ivar* ivars = class_copyIvarList(classType, &count);
for(unsigned int i = 0; i < count; ++i) {
printf("%s::%s %s\n", [classType description].UTF8String, ivar_getName(ivars[i]), ivar_getTypeEncoding(ivars[i]));
}
free(ivars);
@rraallvv
rraallvv / Obj-C adding methods at runtime
Created March 28, 2015 06:00
Obj-C adding methods at runtime
+ (void)initialize {
Class metaClass = objc_getMetaClass(class_getName(self));
SEL selector = @selector(description);
IMP implementation = imp_implementationWithBlock(^NSString *(){
return @">>>added";
});
Method method = class_getClassMethod(metaClass, selector);
@rraallvv
rraallvv / draw_path.m
Created April 9, 2015 21:31
draw path with points in cocoa
CGPoint points[num];
CGContextRef ctx = [[NSGraphicsContext currentContext] graphicsPort];
CGMutablePathRef path = CGPathCreateMutable();
CGPathAddLines(path, NULL, points, num);
if (closePath) CGPathCloseSubpath(path);
CGContextAddPath(ctx,path);
CGContextStrokePath(ctx);