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
function sum(x, y) {
return x + y;
}
const a = 3;
const b = 4;
const c = sum(a, b);
console.log(`${a} + ${b} =`, c);
function sum(x: number, y: number) {
return x + y;
}
const a: number = 3;
const b: number = 4;
const c: number = sum(a, b);
console.log(`${a} + ${b} =`, c);
{
"compilerOptions": {
"target": "esnext",
"module": "commonjs",
"moduleResolution": "node",
"declaration": true,
"sourceMap": true,
"outDir": "../dist",
"rootDir": "./"
}
@drochgenius
drochgenius / index.ts
Created April 3, 2019 20:02
First Typescript File
export function sum(x: number, y: number): number {
return x + y;
}
@drochgenius
drochgenius / index.ts
Last active April 3, 2019 20:54
node-fetch dependency
import fetch from 'node-fetch';
@drochgenius
drochgenius / index.ts
Created April 3, 2019 20:58
Import globby
import fetch from 'node-fetch';
import { sync } from 'globby';
@drochgenius
drochgenius / docker.compose.yaml
Created April 19, 2019 19:35
Docker Setup: Kafka + Zookeeper
# Local Kafka development environment setup
# ref: https://github.com/simplesteph/kafka-stack-docker-compose/blob/master/full-stack.yml
version: '3'
services:
zoo1:
image: zookeeper:3.4.9
restart: unless-stopped
hostname: zoo1
ports:
@drochgenius
drochgenius / producer.ts
Last active April 19, 2019 20:13
Kafka Producer sample code
import { KafkaClient as Client, Producer, ProduceRequest } from 'kafka-node';
const kafkaHost = 'localhost:9092';
export function publish(topic: string, message: string): void {
// The client connects to a Kafka broker
const client = new Client({ kafkaHost });
// The producer handles publishing messages over a topic
const producer = new Producer(client);
@drochgenius
drochgenius / client.ts
Created April 19, 2019 19:57
Create Kafka Client
import { KafkaClient as Client } from 'kafka-node';
const kafkaHost = 'localhost:9092';
const client = new Client({ kafkaHost });
@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);