Skip to content

Instantly share code, notes, and snippets.

@pixelrevision
pixelrevision / CCTMXMapCharacter.h
Created June 24, 2012 16:42
A very simple character class for use with cocos2D iphone. Will perform basic collision testing with a orthogonal CCTMXTiledMap. Very useful if wanting to get something up and running quickly without wrestling with box2d or chipmunk.
#import <Foundation/Foundation.h>
#import "cocos2d.h"
@interface CCTMXMapCharacter : CCNode {
CCTMXTiledMap *_map;
CCTMXLayer *_collidersLayer;
CGRect _collisionRect;
CGSize _mapSize;
CGSize _tileSize;
#import <Foundation/Foundation.h>
@interface NSURLRequestFileInfo : NSObject
@property NSData *data;
@property NSString *name;
@property NSString *key;
+ (NSURLRequestFileInfo *)fileInfoWithData:(NSData *)data key:(NSString *)key andName:(NSString *)name;
@end
@interface NSURLRequest (FileAdditions)
@pixelrevision
pixelrevision / retina_replacement_example.js
Created July 6, 2012 17:43
Simple js retina image replacement
$(document).ready(function(){
var dpr = 1;
if(window.devicePixelRatio !== undefined) dpr = window.devicePixelRatio;
if(dpr >= 2){
// convert image links to @2x images
$("img").each(function(){
var newSrc = $(this).attr("src").replace(".png", "@2x.png");
newSrc = $(this).attr("src").replace(".jpg", "@2x.jpg");
newSrc = $(this).attr("src").replace(".jpeg", "@2x.jpeg");
$(this).attr("src", newSrc);
@pixelrevision
pixelrevision / UniqueRandom.js
Last active October 11, 2015 17:48
Unique random numbers javascript
var UniqueRandom = function(min, max, increments){
this.min = min;
this.max = max;
if(increments === undefined){
this.increments = 1;
}else{
this.increments = increments;
}
this.reset();
};
@pixelrevision
pixelrevision / autoclear.js
Created November 19, 2012 22:24
jquery form autoclear
$(document).ready(function(){
$(document).find("[data-autoclear]").each(function(){
$(this).data("clearValue", $(this).val());
$(this).focus(function(){
var cv = $(this).data("clearValue");
if($(this).val() === cv){
$(this).val("");
}
});
$(this).focusout(function(){
@pixelrevision
pixelrevision / gist:4567181
Created January 18, 2013 18:46
Simple javascript delegate
var Delegate = function(){}
Delegate.create = function(object, method){
return (function() { return method.apply(object, arguments);});
}
@pixelrevision
pixelrevision / PXRImageSizeUtil.h
Created January 31, 2013 23:41
A class to easily resize images in ios.
#import <Foundation/Foundation.h>
typedef enum {
PXRImageSizeUtilVerticalAlignTop,
PXRImageSizeUtilVerticalAlignBottom,
PXRImageSizeUtilVerticalAlignMiddle
}PXRImageSizeUtilVerticalAlign;
typedef enum {
PXRImageSizeUtilHorizontalAlignLeft,
@pixelrevision
pixelrevision / gist:5069770
Created March 2, 2013 04:58
Print all font family names in ios
NSArray *familyNames = [UIFont familyNames];
for(NSString *family in familyNames){
NSLog(@"-%@", family);
NSArray *fontNames = [UIFont fontNamesForFamilyName:family];
for(NSString *font in fontNames){
NSLog(@"----%@", font);
}
}
@pixelrevision
pixelrevision / ISO 8601 date
Created March 19, 2013 21:42
Get a date from a ISO 8601 string in javascript.
var a = dateString.split(/[^0-9]/);
var date = new Date (a[0],a[1]-1,a[2],a[3],a[4],a[5]);
@pixelrevision
pixelrevision / PXRWebViewMessenger.js
Last active December 16, 2015 06:29
Call native iOS methods in javascript.
var PXRWebViewMessenger = function(){
this.prefixTrigger = "pxr";
this.queue = [];
this.timer = null;
};
PXRWebViewMessenger.prototype.callMethod = function(methodName, params){
var self = this;
var message = {};
message.method = methodName;