Skip to content

Instantly share code, notes, and snippets.

Avatar
🖖
live long and prosper

Erdem Arslan laphilosophia

🖖
live long and prosper
View GitHub Profile
@laphilosophia
laphilosophia / http2.js
Created Nov 26, 2019 — forked from davidgilbertson/http2.js
HTTP2 server with compression and caching
View http2.js
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 Nov 6, 2019 — 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
View axios.js
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 Feb 25, 2019 — forked from enginkartal/js-turkish-to-english.js
Javascript Turkish character to english characters change
View js-turkish-to-english.js
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 Feb 21, 2019
javascript closure example
View closure-example.js
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 Feb 21, 2019
simple-modal for once run
View modal.html
<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 Feb 15, 2019 — forked from paulirish/what-forces-layout.md
What forces layout/reflow. The comprehensive list.
View what-forces-layout.md

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()
@laphilosophia
laphilosophia / storage-listener.js
Last active Nov 12, 2018
storage api listener
View storage-listener.js
// Listener
window.addEventListener('storage', handlerEvent)
// Whenever we set a localStorage, window object will listen and invoke this handlerEvent function.
// We do all validation and stuff to act accordingly.
// Handler
const handlerEvent = event => {
if (event.originalEvent.key != 'message') return
@laphilosophia
laphilosophia / README.md
Created Nov 6, 2018 — forked from datchley/README.md
Micro templating library for javascript
View README.md

Micro-Template: README.md

Valid template expressions:

  • expressions can reference any property on the passed in context, including nested properties and indexed access to array properties.
     {{ name }}
     {{ obj.name }}
@laphilosophia
laphilosophia / polling.js
Created Nov 5, 2018
Javascript polling functions
View polling.js
// deferred
function poll(fn, timeout, interval) {
let endTime = Number(new Date()) + (timeout || 2000)
interval = interval || 100
let checkCondition = (resolve, reject) => {
// If the condition is met, we're done!
let result = fn()
if (result) {
View object-copy.js
// SHALLOW COPY
const obj1 = {
a: 1,
b: 2,
c: 'three',
d: new Date()
}
const obj2 = {