Skip to content

Instantly share code, notes, and snippets.

View jlcampana's full-sized avatar
:octocat:
emu emu emu...

Jose Luis Campaña jlcampana

:octocat:
emu emu emu...
View GitHub Profile
@hboon
hboon / gist:278281
Created January 15, 2010 18:12
Script to Remove Core Data's SQLite Database File During Development Cycles
#!/bin/sh
# Adapted from http://furbo.org/2009/03/03/open-sesame/
if [ -z "$1" ]; then
echo "usage: $0 <app> [ Preferences | <document> ]"
else
app=`ls -1td ~/Library/Application\ Support/iPhone\ Simulator/User/Applications/*/$1.app | head -1`
dir=`dirname "$app"`
if [ "$2" = "Preferences" ]; then
@borzilleri
borzilleri / function.cast.php
Created May 7, 2011 00:02
PHP function to cast an object from one class to another.
<?php
/**
* Cast an object into a different class.
*
* Currently this only supports casting DOWN the inheritance chain,
* that is, an object may only be cast into a class if that class
* is a descendant of the object's current class.
*
* This is mostly to avoid potentially losing data by casting across
* incompatable classes.
@fwielstra
fwielstra / api.js
Created June 14, 2011 14:46
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');
@odrobnik
odrobnik / gist:1186394
Created September 1, 2011 15:17
NSString md5
// method to calculate a standard md5 checksum of this string, check against: http://www.adamek.biz/md5-generator.php
- (NSString * )md5
{
const char *cStr = [self UTF8String];
unsigned char result [CC_MD5_DIGEST_LENGTH];
CC_MD5( cStr, strlen(cStr), result );
return [NSString
stringWithFormat: @"%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X",
result[0], result[1],
@odrobnik
odrobnik / gist:1216647
Created September 14, 2011 14:05
Dropping a shadow
- (void)animationDidStop:(CABasicAnimation *)anim finished:(BOOL)flag
{
self.layer.shadowPath = (CGPathRef)anim.toValue;
}
- (void)updateShadowWithDuration:(NSTimeInterval)duration
{
CALayer *layer = self.layer;
if (_dropShadow)
@chrishulbert
chrishulbert / DictionaryTypesHelper.m
Created November 30, 2011 02:49
Dictionary Types Helper
// DictionaryTypesHelper.h
#import <Foundation/Foundation.h>
@interface NSDictionary (NSDictionary_DictionaryTypesHelper)
- (NSArray*)arrayForKey:(id)key;
- (NSDictionary*)dictionaryForKey:(id)key;
- (NSString*)stringForKey:(id)key;
- (NSNumber*)numberForKey:(id)key;
- (NSData*)dataForKey:(id)key;
@Coeur
Coeur / Get iOS MAC address.m
Created November 30, 2011 17:11
Get iOS MAC address #
/* Original source code courtesy John from iOSDeveloperTips.com */
#include <sys/socket.h>
#include <sys/sysctl.h>
#include <net/if.h>
#include <net/if_dl.h>
+ (NSString *)getMacAddress
{
int mgmtInfoBase[6];
@jlcampana
jlcampana / runtime_check_ios5
Created January 20, 2012 10:18
Runtime check for iOS5
+(BOOL)deviceIsRunningOS5
{
UIScreen *s = [UIScreen mainScreen];
return [s respondsToSelector:@selector(brightness)];
}
@vibrazy
vibrazy / NSPredicateWithBlock
Created February 8, 2012 09:29
NSPredicate With Block
BOOL proVersion = YES;
if (proVersion) {
return;
}
//create predicate and filter the results
NSPredicate *freePredicate = [NSPredicate predicateWithBlock:^BOOL(id evaluatedObject, NSDictionary *binding) {
InAppGame *game = (InAppGame *)evaluatedObject;
return game.isFree;
}];
@odrobnik
odrobnik / gist:1845108
Created February 16, 2012 14:10
ImageIO versus UIImageJPEGRepresentation
// UIImageJPEGRepresentation
NSData *data = UIImageJPEGRepresentation(tileImage, 0.71);
[data writeToURL:cacheURL atomically:YES];
// ImageIO
#import <ImageIO/ImageIO.h>
#import <MobileCoreServices/UTCoreTypes.h>