Skip to content

Instantly share code, notes, and snippets.

View fpillet's full-sized avatar

Florent Pillet fpillet

View GitHub Profile
@fpillet
fpillet / MyBuffer.js
Created November 2, 2011 09:26 — forked from anonymous/MyBuffer.js
Array to String
var MyModule = {
var self = {
buffer : "",
defaultSize : 20,
carriageReturn : "99"
},
setup : function() {
// we could remove this function if there is nothing to do
},
@fpillet
fpillet / gist:1034444
Created June 19, 2011 16:22 — forked from anonymous/CIP.js
alljoins.js
//Setup join arrays for used joins monitoring and clearing
for (var join in gui.allJoins) {
joinType = gui.allJoins[join].charCodeAt(0);
joinNumber = parseInt(gui.allJoins[join].substr(1));
if ((joinType == 0x64) && (joinNumber >= self.DJoin_Low) && (joinNumber <= self.DJoin_High) && (joinNumber != self.DJoin_connectedFB) && (!self.PageJoins[gui.allJoins[join]])) { //digital
self.DJoins.push(gui.allJoins[join]);
self.ClearJoins.push({join:gui.allJoins[join], value:0});
} else if ((joinType == 0x61) && (joinNumber >= self.AJoin_Low) && (joinNumber <= self.AJoin_High)) { //analog
self.AJoins.push(gui.allJoins[join]);
@fpillet
fpillet / scale.js
Created May 26, 2011 12:07
Javascript value scaling between two ranges
/* Scale a value from one range to another
* Example of use:
*
* // Convert 33 from a 0-100 range to a 0-65535 range
* var n = scaleValue(33, [0,100], [0,65535]);
*
* // Ranges don't have to be positive
* var n = scaleValue(0, [-50,+50], [0,65535]);
*
* Ranges are defined as arrays of two values, inclusive
@fpillet
fpillet / NSManagedObjectContext+FP.m
Created December 20, 2010 11:30
Core data helpers to log errors and changes to a context (using NSLogger)
- (void)logDetailedError:(NSError *)error from:(id)caller selector:(SEL)selector
{
#if DEBUG
LogMessage(@"coredata", 0, @"*** CORE DATA ERROR: a data store operation failed");
LogMessage(@"coredata", 0, @"*** Caller was: %@ %p %@", [caller class], caller, NSStringFromSelector(selector));
LogMessage(@"coredata", 0, @"*** Error: %@", [error localizedDescription]);
NSArray* detailedErrors = [[error userInfo] objectForKey:NSDetailedErrorsKey];
if ([detailedErrors count] > 0)
{
for(NSError* detailedError in detailedErrors)
@fpillet
fpillet / NSLoggerMacros.h
Created December 2, 2010 16:50
NSLogger example macros
// Example macros that you can leave in production code, and turn on a flag to activate logging
#import "LoggerClient.h"
extern BOOL gLoggingEnabled;
#define LOG_APP(...) if (gLoggingEnabled) LogMessageF(__FILE__,__LINE__,__FUNCTION__,@"app", ##__VA_ARGS__); else do {} while(0)
#define LOG_CACHE(...) if (gLoggingEnabled) LogMessageF(__FILE__,__LINE__,__FUNCTION__,@"cache", ##__VA_ARGS__); else do {} while(0)
#define LOG_XML_PARSING(...) if (gLoggingEnabled) LogMessageF(__FILE__,__LINE__,__FUNCTION__,@"xml", ##__VA_ARGS__); else do {} while(0)
#define LOG_SOUNDS(...) if (gLoggingEnabled) LogMessageF(__FILE__,__LINE__,__FUNCTION__,@"sounds", ##__VA_ARGS__); else do {} while(0)
@fpillet
fpillet / gist:717759
Created November 27, 2010 10:01
@_Kolin: remove duplicates without using a set
// If you really want to do this without using a set, you can do it this way
NSUInteger count = [marray count];
for (NSUInteger i = 0; i < (count-1); i++) {
[marray removeObjectIdenticalTo:[marray objectAtIndex:i] inRange:NSMakeRange(i+1, count-i-1);
count = [marray count];
}
@fpillet
fpillet / gist:270266
Created January 6, 2010 13:18
A UIViewController subclass which automagically releases its UIView-derived instance variables upon -dealloc and -viewDidUnload
/* Base UIViewController subclass for your iPhone applications which automatically
* releases your instance variables pointing to UIView objects or UIView-subclassed objects,
* limiting the work you have to do in -dealloc and -viewDidUnload
*
* All you have to do is make your UIViewController subclasses inherit from BaseUIViewController
* instead of UIViewController
*
* The helper function that disposes of objects is generalized and can be used for other
* types of objects as well.
*