Skip to content

Instantly share code, notes, and snippets.

Juan G. Jordán jguix

View GitHub Profile
@jguix
jguix / recursive-observable.ts
Last active Mar 5, 2018
How to create a recursive observable pipe. Source: http://jsbin.com/finisab/edit?js,console
View recursive-observable.ts
// A recursive function returning Observable<number>
function recurseToZero(n) {
console.log('B. Entering recursive function for [' + n + '].');
// Once we hit zero, bail out of the recursion. The key to recursion is that
// it stops at some point, and the callstack can be "rolled" back up.
if (n === 0) {
return Rx.Observable.of(0);
}
// Start a NEW PROMISE CHAIN that will become the continuation of the parent
// promise chain. This new promise chain now becomes a completely tangential
@jguix
jguix / recursive-promise.ts
Last active Nov 5, 2018
How to create a recursive promise chain. Source http://jsbin.com/qotabib/edit?js,console
View recursive-promise.ts
// A recursive function returning Promise<number>
function recurseToZero(n) {
console.log('B. Entering recursive function for [' + n + '].');
// Once we hit zero, bail out of the recursion. The key to recursion is that
// it stops at some point, and the callstack can be "rolled" back up.
if (n === 0) {
// We could just return 0 but we do return Promise.resolve to have a consistent return type
return Promise.resolve(0);
}
// Start a NEW PROMISE CHAIN that will become the continuation of the parent
@jguix
jguix / capture-photo.js
Last active Mar 5, 2018
Capture photo in an Ionic app and move the photo to permanent storage
View capture-photo.js
// From: http://www.joshmorony.com/store-camera-photos-permanently-using-phonegap-ionic-ngcordova/
$cordovaCamera.getPicture(options).then(function(imagePath){
//Grab the file name of the photo in the temporary directory
var currentName = imagePath.replace(/^.*[\\\/]/, '');
//Create a new name for the photo
var d = new Date(),
n = d.getTime(),
newFileName = n + ".jpg";
You can’t perform that action at this time.