Skip to content

Instantly share code, notes, and snippets.

View joelrfcosta's full-sized avatar
🔥

Joel Costa joelrfcosta

🔥
View GitHub Profile
@joelrfcosta
joelrfcosta / buildStaticObjCLib
Last active October 11, 2015 12:28 — forked from adamgit/gist:3705459
Automatically create cross-platform (simulator + device) static libraries for Objective C / iPhone / iPad
#
# c.f. StackOverflow question/answer here: http://stackoverflow.com/questions/3520977/build-fat-static-library-device-simulator-using-xcode-and-sdk-4
#
# Version 2.3
#
# Latest Change:
# - Apple's handling of "project files" is broken; added a workaround for Xcode 4.5
# - Added automatic FAIL BUILD if any of the internal commands fail
#
# Purpose:
@joelrfcosta
joelrfcosta / SingletonClass.m
Last active June 5, 2021 18:26 — forked from lukeredpath/ExampleClass.m
Singleton macro with blocks using GCD
#define SingletonWithBlock(block) static dispatch_once_t pred = 0; \
__strong static id _sharedObject = nil; \
dispatch_once(&pred, ^{ \
_sharedObject = block(); \
}); \
return _sharedObject; \
@implementation SingletonClass
+ (id)sharedInstance
@joelrfcosta
joelrfcosta / preloadFonts.m
Last active December 16, 2015 11:09 — forked from stuartcarnie/gist:945862
Preload fonts using CGD
#import <CoreText/CoreText.h>
...
// preload
dispatch_queue_t queue = dispatch_queue_create("com.company.worker", NULL);
dispatch_async(queue, ^(void) {
NSMutableDictionary *attributes = [NSMutableDictionary dictionary];
[attributes setObject:@"Helvetica" forKey:(id)kCTFontFamilyNameAttribute];
[attributes setObject:[NSNumber numberWithFloat:36.0f] forKey:(id)kCTFontSizeAttribute];
@joelrfcosta
joelrfcosta / api.js
Created April 20, 2013 09:53 — forked from fwielstra/api.js
An example NodeJS / Mongoose / Express application based on their respective tutorials
/* The API controller
Exports 3 methods:
* post - Creates a new thread
* list - Returns a list of threads
* show - Displays a thread and its posts
*/
var Thread = require('../models/thread.js');
var Post = require('../models/post.js');
@joelrfcosta
joelrfcosta / NormaliseCGRect.m
Last active December 17, 2015 05:39
Normalise CGRect The value will be between 0 and 1
CGAffineTransform t = CGAffineTransformMakeScale(1.0f / parentRect.size.width, 1.0f / parentRect.size.height);
CGRect unitRect = CGRectApplyAffineTransform(rect, t);
@joelrfcosta
joelrfcosta / BlurUIView.m
Last active December 17, 2015 05:39
Apply blur to UIView
//Get a UIImage from the UIView
UIGraphicsBeginImageContext(myView.bounds.size);
[myView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
//Blur the UIImage
CIImage *imageToBlur = [CIImage imageWithCGImage:viewImage.CGImage];
CIFilter *gaussianBlurFilter = [CIFilter filterWithName: @"CIGaussianBlur"];
[gaussianBlurFilter setValue:imageToBlur forKey: @"inputImage"];
@joelrfcosta
joelrfcosta / Util Macros
Last active December 17, 2015 05:39
Util macros to use on iOS projects
#define DLog(__FORMAT__, ...) \
NSLog((@"%s [Line %d] " __FORMAT__), __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__)
#define HexValueFromString(string) { \
unsigned int rgbHex; \
[[NSScanner scannerWithString:@""] scanHexInt:&rgbHex]; \
return rgbHex; \
}
#define UIColorFromRGB(rgbValue, alphaValue) \
@joelrfcosta
joelrfcosta / blockExample.m
Last active December 17, 2015 06:28
An block declaration and usage example
int multiplier = 7;
int (^myBlock)(int) = ^(int num) {
return num * multiplier;
};
printf("%d", myBlock(3));
// prints "21"
#!/bin/bash
## Nodejs custom version installer
##
## Ronaldo Barbachano April 2013
## Based on the openshift/nodejscustom-version-openshift repo
##
## Supply with path to existing openshift repo, or move script into
## repo root.
##
## Probably less headaches if this is run immediately after
@joelrfcosta
joelrfcosta / printFreeMemory.m
Created June 5, 2013 16:16
iOS avalilable memory
- (void)printFreeMemory
{
return;
mach_port_t host_port;
mach_msg_type_number_t host_size;
vm_size_t pagesize;
host_port = mach_host_self();
host_size = sizeof(vm_statistics_data_t) / sizeof(integer_t);