This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type TEvent = 'player-icu'; | |
type EventCallback<T> = (data: T) => void; | |
class EventPublisher { | |
// Subscription Record<EventName, Record<SubscriberId, callback>> | |
private subscriptions: Record< | |
string, | |
Record<string, EventCallback<unknown>> | |
> = {}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface IKeyEventsListeners { | |
keyup: { [componentId: string]: (event: KeyboardEvent) => void }; | |
keydown: { [componentId: string]: (event: KeyboardEvent) => void }; | |
} | |
export interface IKeySubscription { | |
unsubscribe: () => void; | |
} | |
const keyListener = (<T extends keyof IKeyEventsListeners>() => { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const initDevToolCode = () => { | |
const devToolSignalName = 'DEVTOOL_ASYNC_MONITOR__ASYNC_STATUS_CHANGE'; | |
const getNameId = (customName) => customName || `${(Math.random() + 1).toString(36).substring(7)}-${+ new Date()}`; | |
// PubSub outside our app | |
var eventPool = (function() { | |
var topics = {}; | |
var hOp = topics.hasOwnProperty; | |
return { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function () { | |
'use strict'; | |
/** | |
* Displays logging information on the screen and in the console. | |
* @param {string} msg - Message to log. | |
*/ | |
function log(msg) { | |
var logsEl = document.getElementById('logs'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import AWS from 'aws-sdk'; | |
import multer, { FileFilterCallback } from "multer" | |
import multerS3 from "multer-s3"; | |
import {Request} from 'express'; | |
import { v4 as uuidv4 } from 'uuid'; | |
AWS.config.update({ | |
accessKeyId: process.env.AWS_ACCESS_KEY_ID, | |
secretAccessKey: process.env.AWS_SECRET_KEY, | |
signatureVersion: 'v4' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const getDeviceTypeInfo = () => { | |
const { width, height } = getWindowDimension() | |
const buildDeviceDetails = { | |
deviceType: '', | |
deviceTypeVariant: '', | |
orientation: 'Portrait', | |
width, | |
height, | |
isFallback: false | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
console.time("execution"); | |
var posts = [{ | |
"id": 1, | |
"name": "Earth", | |
"children": [2, 3] | |
}, { | |
"id": 2, | |
"name": "Asia", | |
"children": [] | |
}, { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fs = require('fs'); | |
const jwt = require('jsonwebtoken'); | |
// http://travistidwell.com/blog/2013/09/06/an-online-rsa-public-and-private-key-generator/ | |
// use 'utf8' to get string instead of byte array (1024 bit key) | |
var privateKEY = fs.readFileSync('./private.key', 'utf8'); // to sign JWT | |
var publicKEY = fs.readFileSync('./public.key', 'utf8'); // to verify JWT | |
module.exports = { | |
sign: (payload, $Options) => { | |
/* |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = { | |
onlyNumber: function(sample){ | |
// returns false if input is not a number | |
return /^([0-9]+)$/.test(sample); | |
}, | |
onlyAlphabets: function(sample){ | |
// returns false if input is not a string of alphabets | |
return /^([a-z]+)$/.test(sample); | |
}, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = { | |
uniqueID: function(){ | |
const length = 38; | |
const unixTstamp = Math.round(new Date().getTime()/1000); | |
const chars = Math.random().toString(36).slice(2) | |
var result = ''; | |
for (var i = length; i > 0; --i) result += chars[Math.round(Math.random() * (chars.length - 1))]; | |
return result; | |
}, | |
randomString: function(){ // returns 128 bit string |
NewerOlder