Chat Rooms and a mini Data Science project


Leibel Hecht
Jun 9, 2017 · 5 min read
Time to build a chat room with sockets in node.js

Chat rooms are cool. They are even more incredible when you see how they work under the hood! How can a server simultaneously handle and serve multiple clients and their requests, all in real time? Sockets!

Click here for the data analysis project.

So you’re on Slack, and that annoying smarty pants co-worker of yours keeps beating you to that perfect response to your team leaders comments. You’re fingers just can’t keep up, and your messages always post just behind theirs. Whatever, maybe just send them some sad emoji or something. Ain’t nobody got time for that now. The question we should be asking, is HOW IS THIS ALL HAPPENING? All of these messages are showing up simultaneously, from many users and we can even see when they’re typing?? This is all crazy! I was hoping that it was all just magic, but it’s not, (Sad face), it’s even better!

The texhnology is called sockets, and we’ll be handling them with in node.js.

A module to handle sockets in node

What are sockets? In short, they are a way to set up a continuous connection between the client and server. Yes, that means no request/response cycle. Goodbye HTTP, at least for this post.

Sockets are event driven. This means that the both the client and server are set up to be in a constant state of listening for events. For this to work, there will be 2 events for every action, one to receive the request and one to respond to that request.

Always connected!!

Without getting into too much detail, (because I’m quite the expert after one day, and I wouldn’t want to bore you with the technical jargon 😱) sockets allow us to make things like multi person chat rooms and multi player games. So I definitely look forward to learning more.

Tomorrow we’ll be on to MongoDB and learning my database is a bit more crucial for now. Until next time, goodbye sockets.

Today’s algorithms focused on flattening nested arrays using functions and recursion. It was today that it hit me just how cool recursion (and I guess functional programming in general) can be. To flatten a nested array using a for loop would probably 10–20 times the amount of code. Recursion is just so elegant.

I mentioned that I started a mini Data Science project, so here it is.

We recently had a lunchtime workshop by Susan, our incredible career advisor. One of the points she stressed, was to look back at our past jobs and remind ourselves of accomplishments and skills that might not at first glance seem like they would matter in a tech job. She then proceeded to show how all of these skills actually have application in the technology sector.

Before getting into tech, I worked in video production. I had done some freelance work, but I also worked as a video producer (film, edit, produce) for a non-profit organization. Without tooting my own horn too much 🎺🎺🎺, my videos were quite successful. They were getting a lot of views and were driving up page likes. I had a feeling that the videos that I produced were giving the page an extra boost compared to the regular flow of content, but I couldn’t be sure without some data. (If I could prove that my videos gave extra value to the Facebook page, I would love to share that information with a potential employer.)

So my data science journey began. I needed data on all of the videos from the organizations Facebook page. My cohort-mate Armando suggested I take a look at the Facebook API. I tinkered with it for about an hour. It is really cool! Ultimately though, I was having trouble accessing video views for all videos on the page, so I decided to go 1990’s.

First, I loaded all of the videos on their videos page. Yes, I clicked “load more videos” until they were all loaded. Next I copied the whole page into a document. (I know this is not the prettiest way to do it, but It was the quickest way I could think of.)

This is what is looked like. Substituted the names and views out for this image

Next, I need to parse out the views amount data from the rest. So I used some Regex and after some work, finally got a spreadsheet of all the view numbers.

Eventually I cleaned it up further and was left with just the number of views

I now had the amount of views for every video on their page, which means I could easily get an average of all the videos views.

I then wanted to focus on a specific category of videos where I thought I had seen the most success, fast paced cooking videos. So I built out a spreadsheet for all of the cooking videos data and then one for the cooking video that I produced.

Here are my findings, in short. (Perhaps I will expound on them with graphs when I have a chance). Disclaimer: I am not a “Data Scientist” and my methods might not be completely scientific, but I think the numbers are large enough to show a trend.

  • 509 videos (from the start of their page until today) got roughly 15.7 Million views, giving each video an average of roughly 31k views.
  • The cooking videos did exceptionally well, compared to other content videos, with 62 videos fetching roughly 7.4 million views, giving an average of roughly 119k per video.
  • Finally, the 14 cooking videos that I produced fetched roughly 3.74 million views giving them an average of 267.5k views.

Here is the spreadsheet (it needs a cleanup, but the data is there) of the data.

My reason for doing this “case study”, is not to make myself feel good, (although it definitely did have that side effect), I am entering into a new field of work, but I am confident that the skills that I used to produce results in another field, (namely, high quality video, which resulted directly to upticks in page likes and views) will be able to translate into tech as well.

Anyway, this was basically a note to my potential employers. Thank you all for reading. You guys are the best audience!

Happy Coding and I hope to be back here tomorrow.

Good night.

My Coding Journey

Follow my coding journey and my experience at Coding Dojo in Chicago

Leibel Hecht

Written by

I’m Leibel. I’m transitioning from Talmud to Tech. Maybe someday I’ll be the Rabbi on Rails :)

My Coding Journey

Follow my coding journey and my experience at Coding Dojo in Chicago

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade