Skip to content

Instantly share code, notes, and snippets.

View fpillet's full-sized avatar

Florent Pillet fpillet

View GitHub Profile
@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 / MeasurePerf.swift
Last active June 26, 2019 12:51
A tool to measure code performance in Swift
//
// Created by Florent Pillet on 14/11/16.
// Copyright (c) 2016 Florent Pillet. All rights reserved.
//
import Foundation
/*
* A utility struct that helps mesure the performance of sections of code. Only uses Foundation
* (we could also use QuartzCore's CACurrentMediaTime() for similar precision)
@fpillet
fpillet / Results+Rx.swift
Created February 13, 2016 17:23
turn Realm auto-updating Results into an RxSwift Observable sequence
//
// Results+Rx.swift
//
// Make Realm auto-updating Results observable. Works with Realm 0.98 and later, RxSwift 2.1.0 and later.
//
// Created by Florent Pillet on 12/02/16.
// Copyright (c) 2016 Florent Pillet. All rights reserved.
//
import Foundation
@fpillet
fpillet / PageFlipMonitor.js
Created May 7, 2013 13:46
Experimental Page Flip Monitor module for CommandFusion iViewer
/* PageFlipMonitor v1.0
* Copyright 2013 CommandFusion, public domain
*
* Utility object that monitors entering and exiting pages,
* and can call any number of callbacks specifically registered to observe
* when entering or exiting a page
*
* You callback functions should be of the form:
*
function callback(fromPage, toPage) {
@fpillet
fpillet / MainViewController.m
Created October 29, 2015 19:19
Example of encapsulating a gesture recognizer's behavior within a signal's callbacks
- (void)setupDraggableHeaderGestureRecognizer {
// setup a gesture recognizer so we can drag the "I need some daytime hours" header up and down
@weakify(self);
UIPanGestureRecognizer *recognizer = [[UIPanGestureRecognizer alloc] init];
_draggableHeaderView.userInteractionEnabled = YES;
[_draggableHeaderView addGestureRecognizer:recognizer];
RACDisposable *disposable = [[[recognizer
rac_gestureSignal]
scanWithStart:RACTuplePack(@(_mapViewHeightConstraint.constant), @0)
@fpillet
fpillet / gist:1779575
Created February 9, 2012 12:12
Detect whether the Android Soft Keyboard is up
containerView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener()
{
public void onGlobalLayout()
{
final Activity app = getActivity();
if (app == null)
return;
Rect r = new Rect();
containerView.getWindowVisibleDisplayFrame(r);
boolean visible = (Math.abs(r.height() - containerView.getHeight()) > 128);
@fpillet
fpillet / RequestQueue.js
Created January 24, 2012 18:42
Cancellable processing of iViewer CF.request calls
/* Use RequestQueue.request() instead of CF.request()
* At any point, to cancel all pending callbacks, call RequestQueue.clear()
*
*/
var RequestQueue = (function(){
var self = {
q: [],
next: 0
};
@fpillet
fpillet / OrderedRequestQueue.js
Created January 24, 2012 18:19
Ordered processing of CF.request() results for CommandFusion iViewer
/* OrderedRequestQueue.js
*
* Push CF.request calls using this object instead of directly using CF.request, and
* you'll be guaranteed to receive results in the order you pushed them. Note that this
* implies that the queue will BLOCK until each result is received in sequence, which may
* cause large delays if one site in the list is long to respond.
*
* Use at your own risk
*/
var OrderedRequestQueue = (function(){
@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]);