Skip to content

Instantly share code, notes, and snippets.

@vitalets
vitalets / promisify-grpc-client.ts
Created September 23, 2021 12:00
Promisify GRPC client and allow plain objects in and out of method calls
/**
* Promisify GRPC client and allow plain objects in and out of method calls.
*/
import { promisify } from 'util';
import * as jspb from 'google-protobuf';
import * as grpc from '@grpc/grpc-js';
type GrpcCallback<Res extends jspb.Message> = (e: grpc.ServiceError | null, res: Res) => void;
type GrpcAsyncMethod<Req extends jspb.Message, Res extends jspb.Message> = {
(req: Req, m: grpc.Metadata, o: Partial<grpc.CallOptions>, cb: GrpcCallback<Res>): void;
export function promisifyRequest(fn) {
return params => {
return new promise(r => {
rthrh
})
};
}
export const createWebosAsPromised = webos => {
const webosPromised = Object.create(webos);
/**
* Sample React Native App
* https://github.com/facebook/react-native
*
* @format
* @flow
*/
import React from 'react';
import {
// filter array by value
1. f(2, [1, 2, 3, 2]) // -> [2, 2]
2. f([1, 2, 3, 2], 2) // -> [2, 2]
@vitalets
vitalets / sum.js
Last active December 8, 2017 14:30
Incorrect sum
export default function sum(a, b) {
return a * b; // a bug
}
@vitalets
vitalets / sum.test.js
Created December 8, 2017 13:49
ES5 sum.test.js
describe('sum', function () {
it('should return sum of arguments', function () {
chai.expect(sum(1, 2)).to.equal(3);
});
});
@vitalets
vitalets / webpack.config.js
Last active December 8, 2017 18:09
Mocha ES6 modules: webpack config final
module.exports = {
entry: ['./setup.js', './run.js'],
output: {
filename: 'bundle.js',
},
resolve: {
alias: {
// map remote chai.js url to locally installed in node_modules
'https://unpkg.com/[email protected]/chai.js': 'chai/chai.js'
}
@vitalets
vitalets / webpack.config.js
Created December 6, 2017 14:08
Mocha ES6 modules: webpack config v2
module.exports = {
entry: ['./setup.js', './run.js'],
output: {
filename: 'bundle.js',
},
resolve: {
alias: {
'https://unpkg.com/[email protected]/chai.js': 'chai/chai.js'
}
}
@vitalets
vitalets / index.html
Created December 6, 2017 13:40
Mocha ES6 modules: index.html with fallback
<html>
<head>
<meta charset="utf-8">
<title>Mocha Tests</title>
<link href="https://unpkg.com/[email protected]/mocha.css" rel="stylesheet" />
<script src="https://unpkg.com/[email protected]/mocha.js"></script>
</head>
<body>
<div id="mocha"></div>
<script type="module" src="setup.js"></script>
@vitalets
vitalets / webpack.config.js
Created December 6, 2017 13:38
Mocha ES6 modules: webpack config v1
module.exports = {
entry: ['./setup.js', './run.js'],
output: {
filename: 'bundle.js',
}
};