Skip to content

Instantly share code, notes, and snippets.

TSH code sharing tsh-code

Block or report user

Report or block tsh-code

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View Pub-Sub with websocket.js
const WebSocket = require("ws");
const redis = require("redis");
const subscriber = redis.createClient({
url: "redis://localhost:6379"
});
const publisher = subscriber.duplicate();
const WS_CHANNEL = "ws:messages";
const mockedUsers = [
View Channel subscription.js
const redis = require("redis");
const subscriber = redis.createClient({
url: "redis://localhost:6379"
});
const publisher = subscriber.duplicate();
const WS_CHANNEL = "ws:messages";
subscriber.on("message", (channel, message) => {
console.log(`Message from: ${channel}, ${message}`);
View WSS with broadcasting.ts
const WebSocket = require("ws");
const wss = new WebSocket.Server({ port: 8080 });
const mockedUsers = [
{
id: 1,
firstname: "John",
lastname: "Doe"
}
@tsh-code
tsh-code / Sticky Session HAProxy
Last active Jan 19, 2020
Sticky Session HAProxy
View Sticky Session HAProxy
backend backends
balance leastconn
cookie serverid insert
server srv1 127.0.0.1:8081 check cookie srv1
server srv2 127.0.0.1:8082 check cookie srv2
@tsh-code
tsh-code / Basic HAProxy config
Last active Jan 19, 2020
Basic HAProxy config
View Basic HAProxy config
defaults
mode http
option http-server-close
timeout connect 5s
timeout client 30s
timeout client-fin 30s
timeout server 30s
timeout tunnel 1h
default-server inter 1s rise 2 fall 1 on-marked-down shutdown-sessions
option forwardfor
@tsh-code
tsh-code / Simple WebSocket Api.js
Last active Jan 18, 2020
Simple WebSocket Api
View Simple WebSocket Api.js
const WebSocket = require("ws");
const wss = new WebSocket.Server({ port: 8080 });
const mockedUsers = [
{
id: 1,
firstname: "John",
lastname: "Doe"
}
View Simple REST api.js
const express = require("express");
const app = express();
const mockedUsers = [
{
id: 1,
firstname: "John",
lastname: "Doe"
}
View HSL Color palette
:root {
--primary-color-h: 156;
--primary-color-s: 50%;
--primary-color-l: 50%;
--primary-color: hsl(var(—primary-color-h), var(--primary-color-s), var(--primary-color-l));
/* lighten */
--primary-color--light: hsl(var(--primary-color-h), var(--primary-color-s), calc(var(--primary-color-l) + 15%));
/* darken */
View HSL Themes 3
const button = document.querySelector("#switcher");
const root = document.documentElement;
const body = document.querySelector("body");
button.addEventListener("click", () => {
body.classList.contains("dark-theme") ? setLightTheme() : setDarkTheme();
body.classList.toggle("dark-theme");
});
const setDarkTheme = () => {
View HSL Themes 2
:root {
--primary-color-h: 156;
--primary-color-s: 50%;
--primary-color-l: 50%;
--darken: 0%;
--primary-color: hsl(var(--primary-color-h), var( --primary-color-s), calc(var(--primary-color-l) + var(--darken)));
}
You can’t perform that action at this time.