Skip to content

Instantly share code, notes, and snippets.

View drochgenius's full-sized avatar

Dominique Rochefort drochgenius

  • Houghton Mifflin Harcourt
  • Montreal, Canada
View GitHub Profile
@drochgenius
drochgenius / runOnAllPackagesInTopologicalOrderInParallel.js
Created November 23, 2020 16:24
Use lerna graph to build packages in topological order in parallel
/* eslint-disable @typescript-eslint/no-var-requires */
/**
* this script will list packages in topological order (dependencies before dependents)
* and execute the given command in sequence
* it will substitute any {package} found on the command by the actual package of the current cursor.
* We no longer trust lerna to build in topological order.
*/
const { exec, execSync } = require('child_process');
const colors = require('colors');
@drochgenius
drochgenius / runOnAllPackagesInTopologicalOrder.js
Created November 23, 2020 16:22
Use lerna graph to build packages in topological order
/* eslint-disable @typescript-eslint/no-var-requires */
/**
* this script will list packages in topological order (dependencies before dependents)
* and execute the given command in sequence
* it will substitute any {package} found on the command by the actual package of the current cursor.
* We no longer trust lerna to build in topological order.
*/
const {execSync} = require('child_process');
const colors = require('colors');
@drochgenius
drochgenius / frontend-contribution.ts
Last active October 21, 2021 07:13
Hide unused activity bar icons (view container icons)
import { injectable } from 'inversify';
import { FrontendApplicationContribution, FrontendApplication } from '@theia/core/lib/browser';
import { MaybePromise } from '@theia/core/lib/common/types';
import { Widget } from '@theia/core/lib/browser/widgets';
@injectable()
export class ExampleFrontendContribution implements FrontendApplicationContribution {
/**
* Called after the application shell has been attached in case there is no previous workbench layout state.
* Should return a promise if it runs asynchronously.
@drochgenius
drochgenius / package.json
Created June 29, 2019 19:20
ESLint configuration for TypeScript
"eslintConfig": {
"parser": "@typescript-eslint/parser",
"plugins": [
"@typescript-eslint"
],
"extends": [
"plugin:@typescript-eslint/recommended"
]
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Experimenting with Kafka</title>
<link rel="stylesheet" href="css/styles.css" />
<script type="module" src="dist/client/app.js"></script>
</head>
<body>
<h1>Experimenting with Kafka</h1>
import { css, CSSResult, LitElement, html, customElement, property, TemplateResult } from 'lit-element';
@customElement('kafka-consumer')
export class KafkaConsumer extends LitElement {
@property({ type: Array })
private message: string;
public static get styles(): CSSResult {
return css`
div {
@drochgenius
drochgenius / server.ts
Created April 23, 2019 20:37
Experimenting with Kafka : Simple Socket Server
import * as dotenv from 'dotenv';
import { Server, Message, WebSocketClient } from 'ws';
import * as express from 'express';
import { kafkaSubscribe } from './consumer';
dotenv.config();
const PORT: number = parseInt(process.env.PORT) || 3210;
const app = express();
@drochgenius
drochgenius / kafka-producer.ts
Created April 22, 2019 16:02
Kafka Producer CLI
#!/usr/bin/env node
/**
* CLI tool to publish messages to Kafka topics
*/
import * as program from 'commander';
import { publish } from './producer';
program
.version('0.0.1')
.usage('[options] <message>')
@drochgenius
drochgenius / consumer.ts
Created April 19, 2019 20:31
Kafka Consumer
import { KafkaClient as Client, Consumer, Message, Offset, OffsetFetchRequest, ConsumerOptions } from 'kafka-node';
const kafkaHost = 'localhost:9092';
export function kafkaSubscribe(topic: string): void {
const client = new Client({ kafkaHost });
const topics: OffsetFetchRequest[] = [{ topic: topic, partition: 0 }];
const options: ConsumerOptions = { autoCommit: false, fetchMaxWaitMs: 1000, fetchMaxBytes: 1024 * 1024 };
const consumer = new Consumer(client, topics, options);