Skip to content

Instantly share code, notes, and snippets.

View papayaah's full-sized avatar

David Ang papayaah

View GitHub Profile
@alenstarx
alenstarx / websocket.js
Created May 27, 2017 08:59
websocket client for javascript (ES6)
const WsStateDisconnected = 0;
const WsStateDisconnecting = 1;
const WsStateConnected = 2;
const WsStateConnecting = 3;
class SimpleWSocket {
constructor(url) {
this.wsState = WsStateDisconnected;
this.timer = null;
this.url = url;
this.ws = null;
@ivoputzer
ivoputzer / scrolledIntoView.js
Last active September 8, 2019 22:16
scrolledIntoView.js
function scrolledIntoView(element) {
var rect = element.getBoundingClientRect()
, h = (window.innerHeight || document.documentElement.clientHeight)
, w = (window.innerWidth || document.documentElement.clientWidth)
, verticalVisibility = (rect.top <= h) && ((rect.top + rect.height) >= 0)
, horizontalVisibility = (rect.left <= w) && ((rect.left + rect.width) >= 0)
return verticalVisibility && horizontalVisibility
}