Skip to content

Instantly share code, notes, and snippets.

View UsamaAshraf's full-sized avatar

Usama Ashraf UsamaAshraf

View GitHub Profile
// service-worker.js
// Path is relative to the origin.
const OFFLINE_PAGE_URL = 'offline/offline.html';
// We’ll add more URIs to this array later.
const ASSETS_TO_BE_CACHED = [OFFLINE_PAGE_URL];
self.addEventListener('install', event => {
 event.waitUntil(
  // The Cache API is domain specific and allows an app to create & name 
public class RandomDigitSpout extends BaseRichSpout 
{
// To output tuples from spout to the next stage bolt
  SpoutOutputCollector collector;
public void nextTuple() 
  {
  int randomDigit = ThreadLocalRandom.current().nextInt(0, 10);
// Emit the digit to the next stage bolt
  collector.emit(new Values(randomDigit));
public class EvenDigitBolt extends BaseRichBolt 
{
  // To output tuples from this bolt to the next bolt.
OutputCollector collector;
public void execute(Tuple tuple) 
  {
  // Get the 1st column 'random-digit' from the tuple
  int randomDigit = tuple.getInt(0);
if (randomDigit % 2 == 0) {
public class MultiplyByTenBolt extends BaseRichBolt 
{
  OutputCollector collector;
public void execute(Tuple tuple) 
  {
  // Get 'even-digit' from the tuple.
  int evenDigit = tuple.getInt(0);
collector.emit(new Values(evenDigit * 10));
  }
package packagename
// …
public class OurSimpleTopology { 
 
public static void main(String[] args) throws Exception
  {
  // Create the topology
  TopologyBuilder builder = new TopologyBuilder();
version: '3.2'
services:
zookeeper:
build: ./zookeeper
# Keep it running.
tty: true
storm-nimbus:
build: ./storm-nimbus
# The Nimbus needs to know where the Zookeeper is. This specifies the list of the
# hosts in the Zookeeper cluster. We're using just one node, of course.
# 'zookeeper' is the Docker Compose network reference.
storm.zookeeper.servers:
- "zookeeper"
# Telling the Supervisor where the Zookeeper is.
storm.zookeeper.servers:
- "zookeeper"
# The worker nodes need to know which machine(s) are the candidate of master
# in order to download the topology jars.
nimbus.seeds : ["storm-nimbus"]
# For each Supervisor, we configure how many workers run on that machine.
# Each worker uses a single port for receiving messages, and this setting
public static void main(String[] args) throws Exception
{
TopologyBuilder builder = new TopologyBuilder();
builder.setSpout("word", new TestWordSpout(), 10);
builder.setBolt("exclaim1", new ExclamationBolt(), 3).shuffleGrouping("word");
builder.setBolt("exclaim2", new ExclamationBolt(), 2).shuffleGrouping("exclaim1");
const EventEmitter = require('events');
const myEmitter = new EventEmitter();
module.exports = myEmitter;