Skip to content

Instantly share code, notes, and snippets.

View kino6052's full-sized avatar
🏠
Working from home

Kirill Novik kino6052

🏠
Working from home
View GitHub Profile
@kino6052
kino6052 / array-remove-value-by-index.js
Last active August 31, 2018 11:24
Elegant way to remove value from an array by index
let array = [1, 2, 3];
let index = 1; // Any index
let filteredArray = array.filter((el, i) => i !== index); // [1, 3]
@kino6052
kino6052 / alert-on-scroll-to-bottom.js
Last active September 10, 2018 08:06
Determine if user scrolled all the way to the bottom
// https://stackoverflow.com/questions/9439725/javascript-how-to-detect-if-browser-window-is-scrolled-to-bottom
window.onscroll = function(ev) {
if ((window.innerHeight + window.pageYOffset) >= document.body.offsetHeight) {
alert("you're at the bottom of the page");
}
};
@kino6052
kino6052 / webpack.config.js
Created October 27, 2018 19:27
webpack-configuration-example
const path = require( 'path' );
const webpack = require( 'webpack' );
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
module.exports = ( env, options ) => {
return {
entry: './src/block.js',
output: {
path: path.resolve( __dirname, 'build' ),
const getRandomNumbers = (length: number) => {
const value = Array.from(Math.round(Math.random()*(Math.pow(10, length))).toString()).reverse();
return new Array(length).fill('0').map((v, i) => value[i] || v).reverse().join('');
}
const generateId = (amount: number, length: number) => new Array(amount).fill(0).map((a, i, b) => `${i && '-'}${getRandomNumbers(length)}`).join('')
Admit That Lake Should be Protected Deny That Lake Should be Protected
No Danger to the Lake Exists Lake Lives Lake Lives
Danger to the Lake Exists Lake Lives Lake Dies
I Wear Mask I Don't Wear Mask
Mask Helps Spread is Lowered Spread is Increased
Mask Doesn't Help Spread is Same Spread is Same
export class Client {
private id = generateId(4, 4);
// Channels
private dataChannels: { [id: string]: RTCDataChannel } = {};
private streams: { [id: string]: MediaStream[] } = {};
// Agents
private BroadcastingAgent = new BroadcastingAgent(
this.id,
export class BroadcastingAgent {
// Participants
public participants: string[] = [];
// Subjects
public addParticipantSubject = new Subject<string>();
public removeParticipantSubject = new Subject<string>();
private commSubject: Subject<IMessage<unknown>>;
constructor(
export class RTCMessagingAgent {
// Subjects
public OnAddParticipantSubject = new Subject<string>();
public OnRemoveParticipantSubject = new Subject<string>();
public OnSetLocalDescription = new Subject<
[string, RTCSessionDescriptionInit]
>();
public OnSetRemoteDescription = new Subject<
[string, RTCSessionDescriptionInit]
import { Subject } from "rxjs";
import { RTCMessagingAgent } from "./rtc-messaging-agent";
const configuration = {
iceServers: [
{
urls: [
"stun:stun.l.google.com:19302",
"stun:stun1.l.google.com:19302",
"stun:stun2.l.google.com:19302",