Skip to content

Instantly share code, notes, and snippets.

View Salakar's full-sized avatar
🎯
Darting around the place 24/7

Mike Diarmid Salakar

🎯
Darting around the place 24/7
View GitHub Profile
@Salakar
Salakar / firebase_firestore.md
Last active January 28, 2022 21:59
Changes preview of the current FlutterFirebase Firestore plugin rework.

Description

⚠️ NOTE: These changes may not reflect the final plugin changes/API as it's still going through review.

Along with the below changes, the plugin has undergone a quality of life update to better support exceptions thrown. Any Firestore specific errors now return a FirebaseException, allowing you to directly access the code (e.g. permission-denied) and message.

Firestore:

  • BREAKING: settings() is now a synchronous setter that accepts a Settings instance.
    • NEW: This change allows us to support changing Firestore settings (such as using the Firestore emulator) without having to quit the application, e.g. Hot Restarts.
  • DEPRECATED: Calling document() is deprecated in favor of doc().
@Salakar
Salakar / foreground-service.ts
Created June 23, 2020 15:59
Testing foreground service notifications in Notifee with progress indicators.
Notifee.registerForegroundService(notification => {
console.warn('Foreground service started.');
return new Promise(resolve => {
/**
* Cancel the notification and resolve the service promise so the Headless task quits.
*/
async function stopService(): Promise<void> {
console.warn('Stopping service.');
if (notification?.id) {
await Notifee.cancelNotification(notification?.id);
@Salakar
Salakar / PushNotificationiOS.md
Last active May 10, 2019 01:23 — forked from indexzero/PushNotificationiOS.md
Draft proposal for Push Notifications and PushNotificationiOS

Proposal for Push Notifications and PushNotificationiOS

@salakar, @ashoat, @indexzero, @swaagie, @3rdeden, and @msluther met today to discuss this. This is the draft proposal written up during that meeting. We plan to iterate on this over the next week and then post it into a new proposal in react-native-community.

Prior art

  • Push Notification packages
    • react-native-push-notification
    • react-native-notifications
  • Fork of iOS work used in react-native-fire
@Salakar
Salakar / PushNotificationiOS.md
Created May 10, 2019 01:20 — forked from indexzero/PushNotificationiOS.md
Draft proposal for Push Notifications and PushNotificationiOS

Proposal for Push Notifications and PushNotificationiOS

@salakar, @ashoat, @indexzero, @swaagie, @3rdeden, and @msluther met today to discuss this. This is the draft proposal written up during that meeting. We plan to iterate on this over the next week and then post it into a new proposal in react-native-community.

A recording of that meeting can be found below in MP4 format.

Prior art

  • Push Notification packages
  • react-native-push-notification
@Salakar
Salakar / firebase-perf-axios.js
Last active May 29, 2024 12:26
Add Firebase Performance Monitoring HTTP Metrics to all Axios requests (RNFB v5). This is taken from a guide on the new React Native Firebase website (not yet ready for public use).
import axios from 'axios';
import firebase from 'react-native-firebase';
axios.interceptors.request.use(async function (config) {
const httpMetric = firebase.perf().newHttpMetric(config.url, config.method);
config.metadata = { httpMetric };
// add any extra metric attributes if needed
// await httpMetric.putAttribute('userId', '12345678');
@Salakar
Salakar / settings.gradle
Created January 12, 2019 03:53
Example applying a plugin to settings.gradle.
// REMOTE MAVEN
buildscript {
repositories { mavenCentral() }
dependencies { classpath 'io.invertase.gradle:react-native:+' }
}
apply plugin: "io.invertase.gradle.settings"
// OR ---------------
@Salakar
Salakar / MainApplication.java
Last active January 20, 2019 04:36
Example injecting React Native module ReactPackages.
package com.testing;
import android.app.Application;
import com.facebook.react.ReactApplication;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage;
import com.facebook.react.shell.MainReactPackage;
import com.facebook.soloader.SoLoader;
@Salakar
Salakar / slotCalc.js
Last active July 9, 2019 15:26
Shard Firebase RTDB by `userId` or any arbitrary string/identifier. Uses a 16 bit cyclic redundancy check to calculate the users shard number based on their user id string. This negates the need for a master instance that maps where users data is stored. See comment below code block for more details.
const lookup = [
0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50a5, 0x60c6, 0x70e7,
0x8108, 0x9129, 0xa14a, 0xb16b, 0xc18c, 0xd1ad, 0xe1ce, 0xf1ef,
0x1231, 0x0210, 0x3273, 0x2252, 0x52b5, 0x4294, 0x72f7, 0x62d6,
0x9339, 0x8318, 0xb37b, 0xa35a, 0xd3bd, 0xc39c, 0xf3ff, 0xe3de,
0x2462, 0x3443, 0x0420, 0x1401, 0x64e6, 0x74c7, 0x44a4, 0x5485,
0xa56a, 0xb54b, 0x8528, 0x9509, 0xe5ee, 0xf5cf, 0xc5ac, 0xd58d,
0x3653, 0x2672, 0x1611, 0x0630, 0x76d7, 0x66f6, 0x5695, 0x46b4,
0xb75b, 0xa77a, 0x9719, 0x8738, 0xf7df, 0xe7fe, 0xd79d, 0xc7bc,
0x48c4, 0x58e5, 0x6886, 0x78a7, 0x0840, 0x1861, 0x2802, 0x3823,
@Salakar
Salakar / proxy-async.js
Created November 18, 2018 14:50 — forked from KiaraGrouwstra/proxy-async.js
using ES6 Proxy to let Promises/Observables pretend like they're regular values
// using ES6 Proxy to let Promises/Observables pretend like they're regular values.
// get the mapping function used for async objects
let getMapper = (target) => target instanceof Promise ? 'then' :
target instanceof Observable ? 'switchMap' : null;
// ^ fails if the Observable is in a local namespace e.g. Rx.Observable
// bind a value to its object if it's a function
let bindFn = (val, obj) => typeof val == 'function' ? val.bind(obj) : val;
@Salakar
Salakar / process1.js
Created November 16, 2018 11:15 — forked from ndelangen/process1.js
If you have 2 independent NodeJS processes running and want them to communicate, this can be done reliably using a npm package: node-ipc
const ipc = require('node-ipc');
ipc.config.id = 'a-unique-process-name1';
ipc.config.retry = 1500;
ipc.config.silent = true;
ipc.serve(() => ipc.server.on('a-unique-message-name', message => {
console.log(message);
}));
ipc.server.start();