Skip to content

Instantly share code, notes, and snippets.

@dheerajsuthar
dheerajsuthar / index.js
Created December 6, 2018 21:13
WebSocket Server
const WebSocketServer = require('ws').Server;
const express = require('express');
const path = require('path');
const server = require('http').createServer();
const PubSubManager = require('./pubsub');
const app = express();
const pubSubManager = new PubSubManager();
app.use(express.static(path.join(__dirname, '/public')));
@dheerajsuthar
dheerajsuthar / pubsub.js
Created December 6, 2018 21:17
Publisher Subscriber Manager
class PubSubManager {
constructor() {
this.channels = {
weather: {
message: '',
subscribers: []
},
sports: {
message: '',
subscribers: []
@dheerajsuthar
dheerajsuthar / pub.html
Created December 6, 2018 21:19
Simple Publisher using Client WebSockets API
<!DOCTYPE html>
<html>
<head>
<style>
body {
font-family: Tahoma, Geneva, sans-serif;
}
div {
@dheerajsuthar
dheerajsuthar / sub.html
Created December 6, 2018 21:24
Simple Subscriber using WebSockets client API
<!DOCTYPE html>
<html>
<head>
<style>
body {
font-family: Tahoma, Geneva, sans-serif;
}
div {
@dheerajsuthar
dheerajsuthar / babel-node-setup.txt
Last active December 12, 2018 21:38
Babe-Node Setup 2018
npm init
npm install --save-dev @babel/core @babel/node @babel/preset-env
npx babel-node index.js --presets=@babel/preset-env
let users = [
{
name: {
first: 'John',
last: 'Galt'
},
email: '[email protected]',
age: 30
},
{
let users = [
{
name: {
first: 'John',
last: 'Galt'
},
email: '[email protected]',
age: 30
},
{
@dheerajsuthar
dheerajsuthar / stats.c
Created December 23, 2018 09:21
Stats : Print histogram to show frequencies of letters and digits on terminal
#include <stdio.h>
#include <unistd.h>
#include <sys/ioctl.h>
#define DIGITS 10
#define LETTERS 26
void nullify(int arr[], int size);
void histogram(int arr[], int size, int start, int terminalWidth);
int getTermWidth();
import React, { Component } from 'react';
import PropTypes from 'prop-types';
const propTypes = {
text: PropTypes.string.isRequired,
customClass: PropTypes.string,
selectionHandler: PropTypes.func
};
/**