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
View GitHub Profile
export default () => {
let docElem = document.documentElement
let active = false
let hasDeactivated = false
let eventsBound = false
let mouseWheelHandler
let scrollHandler
const scrollCallback = (offset, event, callback) => {
@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)
@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 / 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 / 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 / axios.js
Created November 6, 2019 19:57 — forked from wooooodward/axios.js
Axios plugin example with request interceptor that adds JWT token to the auth header and 401 response interceptor to refresh token
import Vue from 'vue'
import axios from 'axios'
import store from '../store'
import { TokenService } from '../services/storage.service'
// Full config: https://github.com/axios/axios#request-config
let config = {
baseURL:
process.env.baseURL ||
@laphilosophia
laphilosophia / js-turkish-to-english.js
Created February 25, 2019 11:36 — forked from enginkartal/js-turkish-to-english.js
Javascript Turkish character to english characters change
String.prototype.turkishtoEnglish = function () {
return this.replace('Ğ','g')
.replace('Ü','u')
.replace('Ş','s')
.replace('I','i')
.replace('İ','i')
.replace('Ö','o')
.replace('Ç','c')
.replace('ğ','g')
.replace('ü','u')
@laphilosophia
laphilosophia / closure-example.js
Created February 21, 2019 13:39
javascript closure example
function apiConnect(apiKey) {
function get(route) {
return fetch(`${route}?key=${apiKey}`)
}
function post(route, params) {
return fetch(route, {
method: 'POST',
body: JSON.stringify(params),
headers: {
@laphilosophia
laphilosophia / modal.html
Created February 21, 2019 12:39
simple-modal for once run
<style type="text/css">
.gaye-modal--modal {
width: 100%;
height: 100%;
position: fixed;
top: 0; left: 0;
z-index: 9999;
background-color: rgba(0, 0, 0, 0.5);
@laphilosophia
laphilosophia / what-forces-layout.md
Created February 15, 2019 07:20 — forked from paulirish/what-forces-layout.md
What forces layout/reflow. The comprehensive list.

What forces layout / reflow

All of the below properties or methods, when requested/called in JavaScript, will trigger the browser to synchronously calculate the style and layout*. This is also called reflow or layout thrashing, and is common performance bottleneck.

Element

Box metrics
  • elem.offsetLeft, elem.offsetTop, elem.offsetWidth, elem.offsetHeight, elem.offsetParent
  • elem.clientLeft, elem.clientTop, elem.clientWidth, elem.clientHeight
  • elem.getClientRects(), elem.getBoundingClientRect()