Skip to content

Instantly share code, notes, and snippets.

// 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 / music.m3u
Last active June 16, 2016 16:51 — forked from yandod/music.m3u
Format for Radiotunnes channels
# Format for Radiotunnes channels
# Standard quality
# http://pub[1 -10].radiotunes.com:80/radiotunes_[channel name]
# example
http://pub6.radiotunes.com:80/radiotunes_tophits
# Low quality
# http://pub[1 -10].radiotunes.com:80/radiotunes_[channel name]_aac
@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);
@rraallvv
rraallvv / objc_class_from_bundle.m
Last active August 29, 2015 14:20
[ObjC] Get class/instance from bundle
NSString *frameworksPath = @"/System/Library/Frameworks";
NSBundle *bundle = [NSBundle bundleWithPath:[frameworksPath stringByAppendingPathComponent:@"AVKit.framework"]];
void* handle = dlopen(bundle.executablePath.UTF8String, RTLD_NOW);
dlclose(handle);
Class class = NSClassFromString(@"AVPlayerView");
id instance = [[class alloc] init];
NSLog(@"%@ %@", class, instance);
@rraallvv
rraallvv / Lua_multiple_global_contexts.txt
Created April 30, 2015 11:10
Lua multiple global contexts example
-- Using lua_replace(L, LUA_GLOBALSINDEX);
-- to change the globals for a thread.
#include "lua.h"
#include "lauxlib.h"
#include "lualib.h"
static int report (lua_State *L, int status) {
const char *msg;
if (status) {