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 / deepMerge.md
Last active November 22, 2023 09:02
ES6/ES2015 Object deep merge

Deep Merge

Quick function to deep merge using Object.assign(). Thoughts?

    /**
     * Simple is object check.
     * @param item
     * @returns {boolean}
     */
@Salakar
Salakar / varlet.js
Last active October 17, 2016 18:43
var vs let performance comparison in v8 - 'let' with --trace-deopt logs 'Unsupported let compound assignment'
/**
Platform info:
Darwin 15.6.0 x64
Node.JS 6.6.0
V8 5.1.281.83
Intel(R) Core(TM) i7-4870HQ CPU @ 2.50GHz × 8
var vs let
922,009,444 op/s » with var
19,823,034 op/s » with let
@Salakar
Salakar / messaging.js
Created March 16, 2017 18:08
new fcm implementation RNFirebase - WIP
import { NativeModules, DeviceEventEmitter, Platform } from 'react-native';
import { Base } from './../base';
const FirebaseMessaging = NativeModules.RNFirebaseMessaging;
export const EVENT_TYPE = {
RefreshToken: 'FCMTokenRefreshed',
Notification: 'FCMNotificationReceived',
};
const sampleData = {
somePostId1: {
title: 'today now',
timestamp: Date.now(),
startOfDay: 1502838000,
},
somePostId3: {
title: 'today but older',
timestamp: Date.now() - 10000000,
@Salakar
Salakar / RNTimeWatcher.java
Last active October 11, 2017 07:39
A rough untested device time watching react native android module.
package io.invertase.firebase;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.BroadcastReceiver;
import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.LifecycleEventListener;
@Salakar
Salakar / example-model-override-hook.js
Created January 12, 2018 09:42
An example sails hook that allows overriding the bootstrapped sails models
/**
* Modify sails blueprint parse result
* @param req
* @return {*}
*/
function parseBlueprintOptions(req) {
const queryOptions = sails.hooks.blueprints.parseBlueprintOptions(req);
// do blueprint overrides if needed...
@Salakar
Salakar / rnfirebase-playservices.js
Created February 16, 2018 15:28
Examples of dealing with play services versions
import firebase from 'react-native-firebase';
// disable default behaviour so we can control the flow ourselves
// this mus be called module scope (outside any classes etc)
// preferably before any other usages of RNFirebase so that
// it's disabled before internal RNFirebase logic takes over
firebase.utils().errorOnMissingPlayServices = false;
firebase.utils().promptOnMissingPlayServices = false;
/**
@Salakar
Salakar / bridge.spec.js
Created March 24, 2018 19:31
Bridge Spec Tests
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();
@Salakar
Salakar / cloudSettings
Last active October 3, 2019 01:08
Visual Studio Code Settings Sync Gist
{"lastUpload":"2019-09-11T00:17:27.387Z","extensionVersion":"v3.4.2"}
@Salakar
Salakar / example.js
Created June 8, 2018 13:34
Logout app after version change pseudo code
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