Skip to content

Instantly share code, notes, and snippets.

View laphilosophia's full-sized avatar
🖖
Live long and prosper

Erdem Arslan laphilosophia

🖖
Live long and prosper
  • World
  • 14:59 (UTC +03:00)
View GitHub Profile
@laphilosophia
laphilosophia / http2.js
Created November 26, 2019 21:06 — forked from davidgilbertson/http2.js
HTTP2 server with compression and caching
const http2 = require('http2');
const fs = require('fs');
const path = require('path');
const zlib = require('zlib');
const brotli = require('brotli'); // npm package
const PORT = 3032;
const BROTLI_QUALITY = 11; // slow, but we're caching so who cares
const STATIC_DIRECTORY = path.resolve(__dirname, '../dist/');
const cache = {};
@laphilosophia
laphilosophia / array-methods.js
Created December 11, 2019 21:51
Array Methods
let array = []
// Joins two or more arrays, and returns a copy of the joined arrays
array.concat(otherArray)
// Copies array elements within the array, to and from specified positions
array.copyWithin(target, start, end)
// Returns a key/value pair Array Iteration Object
array.entries()
@laphilosophia
laphilosophia / js-tricks.js
Created December 11, 2019 22:08
javascript tricks - array and objects
[...Array(10).keys()]
// [1, 2, 3, 4, 5, 6, 7, 8, 9]
[...Array({ one:'1' }, { two: '2' }, { three: '3' }).keys()]
// [1, 2, 3]
let arr1 = [1, 2, 3]
let arr2 = [2, 3, 4]
@laphilosophia
laphilosophia / onChange.js
Created December 11, 2019 22:12
Proxy / Reflect based object watcher
const obj = {
name: 'Erdem',
surname: 'Arslan'
}
const onChange = (watch, callback) => {
const handler = {
get (target, prop, receiver) {
callback(target, prop, receiver)
export default () => {
let docElem = document.documentElement
let active = false
let hasDeactivated = false
let eventsBound = false
let mouseWheelHandler
let scrollHandler
const scrollCallback = (offset, event, callback) => {
const scrollDistance = (callback, refresh) => {
if (!callback || typeof callback !== 'function') return
let isScrolling, start, end, distance
window.addEventListener('scroll', event => {
if (!start) {
start = window.pageYOffset
}
// Long Polling
let ID = 1
const foo = document.createElement('p')
async function timeout (callback, delay) {
return await setTimeout(callback, delay)
}
function polling () {
return timeout(() => {
/**
* @param {number} range
*/
function* generator (range) {
let i = 0
while (i < range) {
i += 1
yield i
}
@laphilosophia
laphilosophia / spinner.ts
Created December 9, 2020 15:03
Typescript spinner sample
export default class Spinner {
#elements: NodeListOf<HTMLElement> = document.querySelectorAll('[data-zm-spinner]')
#config: {
title: string,
max: number,
min: number,
} = {
title: 'ADET',
max: 10,
min: 1,
@laphilosophia
laphilosophia / fpsMeter.js
Created December 21, 2020 18:21 — forked from capfsb/fpsMeter.js
JavaScript FPS meter - Calculating frames per second
fpsMeter() {
let prevTime = Date.now(),
frames = 0;
requestAnimationFrame(function loop() {
const time = Date.now();
frames++;
if (time > prevTime + 1000) {
let fps = Math.round( ( frames * 1000 ) / ( time - prevTime ) );
prevTime = time;