Skip to content

Instantly share code, notes, and snippets.

🌝
Codings

Mike Diarmid Salakar

🌝
Codings
Block or report user

Report or block Salakar

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@Salakar
Salakar / PushNotificationiOS.md
Last active May 10, 2019 — forked from indexzero/PushNotificationiOS.md
Draft proposal for Push Notifications and PushNotificationiOS
View PushNotificationiOS.md

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 — forked from indexzero/PushNotificationiOS.md
Draft proposal for Push Notifications and PushNotificationiOS
View PushNotificationiOS.md

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 Mar 14, 2019
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).
View firebase-perf-axios.js
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 Jan 12, 2019
Example applying a plugin to settings.gradle.
View 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 Jan 20, 2019
Example injecting React Native module ReactPackages.
View MainApplication.java
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 Jul 9, 2019
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.
View slotCalc.js
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 Nov 18, 2018 — forked from tycho01/proxy-async.js
using ES6 Proxy to let Promises/Observables pretend like they're regular values
View proxy-async.js
// 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 Nov 16, 2018 — 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
View process1.js
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();
@Salakar
Salakar / example.js
Created Jun 8, 2018
Logout app after version change pseudo code
View example.js
const { version } = require('./package.json');
// ... inside your app startup logic
try {
const storedVersion = await AsyncStorage.getItem('@MyStore:appVersion');
if (storedVersion !== version){
// do logout logic here
// then update the stored version to be the newest version so next
// restart of app won't trigget this again
@Salakar
Salakar / bridge.spec.js
Created Mar 24, 2018
Bridge Spec Tests
View bridge.spec.js
const should = require('should');
describe('bridge', () => {
beforeEach(async function beforeEach() {
await device.reloadReactNative();
bridge.root.setState({ message: this.currentTest.title });
});
it('should provide -> global.bridge', () => {
should(bridge).not.be.undefined();
You can’t perform that action at this time.