Skip to content

Instantly share code, notes, and snippets.

Avatar
🐈
Meow

Mike Diarmid Salakar

🐈
Meow
View GitHub Profile
@Salakar
Salakar / varlet.js
Last active Oct 17, 2016
var vs let performance comparison in v8 - 'let' with --trace-deopt logs 'Unsupported let compound assignment'
View varlet.js
/**
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 Mar 16, 2017
new fcm implementation RNFirebase - WIP
View messaging.js
import { NativeModules, DeviceEventEmitter, Platform } from 'react-native';
import { Base } from './../base';
const FirebaseMessaging = NativeModules.RNFirebaseMessaging;
export const EVENT_TYPE = {
RefreshToken: 'FCMTokenRefreshed',
Notification: 'FCMNotificationReceived',
};
View vetkamak.js
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 Oct 11, 2017
A rough untested device time watching react native android module.
View RNTimeWatcher.java
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 Jan 12, 2018
An example sails hook that allows overriding the bootstrapped sails models
View example-model-override-hook.js
/**
* 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 Feb 16, 2018
Examples of dealing with play services versions
View rnfirebase-playservices.js
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 / 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();
@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 / proxy-async.js
Created Nov 18, 2018 — forked from KiaraGrouwstra/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;