Skip to content

Instantly share code, notes, and snippets.

@BrandonSmith
BrandonSmith / main.js
Created August 4, 2017 19:47
Electron `call` interface between main and renderer processes
import { ipcMain } from 'electron'
import uuid from 'uuid'
/**
* Makes a data request over IPC to renderer process
* @param {string} request Request type known to main handler
* @param {object} Optional `options` object used as parameters for request
* @return {Promise} Promise of data
*/
export function call(window, request, options={}) {
@BrandonSmith
BrandonSmith / main.js
Created August 4, 2017 19:47
Electron `call` interface between main and renderer processes
import { ipcMain } from 'electron'
import uuid from 'uuid'
/**
* Makes a data request over IPC to renderer process
* @param {string} request Request type known to main handler
* @param {object} Optional `options` object used as parameters for request
* @return {Promise} Promise of data
*/
export function call(window, request, options={}) {
@BrandonSmith
BrandonSmith / index.js
Last active September 1, 2017 21:51
Reply sometimes does not work
const {app,Notification} = require('electron')
app.on('ready', () => {
showNextNotification()
})
let i = 0
showNextNotification = () => {
const notification = new Notification({
@BrandonSmith
BrandonSmith / apns.sh
Created June 22, 2018 13:44
fcm-apns-debugging
#!/bin/bash
curl=/usr/local/opt/curl/bin/curl
openssl=/usr/local/opt/openssl/bin/openssl
deviceToken=TOKEN
authKey="./AuthKey_##########.p8"
authKeyId=##########
teamId=##########
@BrandonSmith
BrandonSmith / index.jsx
Created March 10, 2023 02:07
useGetState
import { useMemo, useReducer, useRef } from "react";
const useGetState = (initialState) => {
const state = useRef(initialState);
const [, update] = useReducer(num => ((num + 1) % 1_000_000), 0);
return useMemo(() => ([
() => state.current,
(newState) => {
state.current = newState;