Skip to content

Instantly share code, notes, and snippets.

@tomersh
tomersh / joinPooledTasks.js
Last active April 20, 2018 17:10
A simple pooled promise implementation
Promise.joinPooledTasks = (worker, poolSize, onTaskFinished) => {
let didEnqueAllTasks = false;
let nextTaskIndex = -1;
const onTaskEnd = (index, status, result, resolve) => {
if (onTaskFinished) {
onTaskFinished(index, status, result);
}
@tomersh
tomersh / promiseWaitForAll.js
Last active April 19, 2018 23:59
Unlike Promise.all(), that will reject when the first promise rejects, the Promise.waitForAll() will never rejects. The method returns a single Promise that resolves when all of the promises in the iterable argument have either resolved or rejects. It returns an array of objects with either a results or error key.
Promise.waitForAll = promises => {
if (!promises || typeof promises[Symbol.iterator] !== 'function') {
return Promise.reject();
}
if (promises.length === 0) {
return Promise.resolve([]);
}
return Promise.all(
@tomersh
tomersh / Add run script build phase
Last active August 22, 2016 18:31
Pre-Cache pods
PODS_CHECKSUM=$( md5 -q ${PROJECT_DIR}/Podfile.lock )
CACHED_CHECKSUM=$( cat ${PROJECT_DIR}/fatCache/checksum )
if [ $PODS_CHECKSUM != $CACHED_CHECKSUM ]
then
echo error: pod files are stale. Please run make pod-install
exit 1
fi
@tomersh
tomersh / cp.m
Created July 24, 2016 23:18
continues press gesture recognizer
-(void) syncButtonViewDidPassedSyncTreshhold:(CPRSyncButtonView*) syncView {
self.didFinishSync = YES;
}
-(void) syncButtonViewDidShowSyncConfirmation:(CPRSyncButtonView*) syncView {
self.didFinishSync = NO;
self.desktopSyncView.hidden = YES;
self.accessoryView.hidden = NO;
}
@tomersh
tomersh / Makefile
Created March 23, 2013 21:00
A simple generic C++ makefile. Just add it to your project and you are ready to go.
############################################################################
# Copyright 2009 Tomer Shiri github@shiri.info #
# #
# Licensed under the Apache License, Version 2.0 (the "License"); #
# you may not use this file except in compliance with the License. #
# You may obtain a copy of the License at #
# #
# http://www.apache.org/licenses/LICENSE-2.0 #
# #
# Unless required by applicable law or agreed to in writing, software #