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 / promise_map.js
Created May 4, 2021 — forked from tokland/promise_map.js
Execute promises sequentially (one at at a time) and return array with the results
View promise_map.js
function promiseMap(inputValues, mapper) {
const reducer = (acc$, inputValue) =>
acc$.then(acc => mapper(inputValue).then(result => acc.push(result) && acc));
return inputValues.reduce(reducer, Promise.resolve([]));
}
/* Example */
const axios = require('axios');
@laphilosophia
laphilosophia / fpsMeter.js
Created Dec 21, 2020 — forked from capfsb/fpsMeter.js
JavaScript FPS meter - Calculating frames per second
View fpsMeter.js
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;
@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 / 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 / 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 / cookies.js
Created Oct 4, 2018 — forked from arozwalak/cookies.js
Javascript: Cookies set/get/delete
View cookies.js
function getCookie(c_name) {
var c_value = document.cookie;
var c_start = c_value.indexOf(" " + c_name + "=");
if (c_start == -1) {
c_start = c_value.indexOf(c_name + "=");
}
if (c_start == -1) {
c_value = null;
}
else {
@laphilosophia
laphilosophia / IndexedDB101.js
Created Jul 24, 2018 — forked from JamesMessinger/IndexedDB101.js
Very Simple IndexedDB Example
View IndexedDB101.js
// This works on all devices/browsers, and uses IndexedDBShim as a final fallback
var indexedDB = window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB || window.shimIndexedDB;
// Open (or create) the database
var open = indexedDB.open("MyDatabase", 1);
// Create the schema
open.onupgradeneeded = function() {
var db = open.result;
var store = db.createObjectStore("MyObjectStore", {keyPath: "id"});
@laphilosophia
laphilosophia / MySQL_macOS_Sierra.md
Created Apr 2, 2018 — forked from nrollr/MySQL_macOS_Sierra.md
Install MySQL on Sierra using Homebrew
View MySQL_macOS_Sierra.md

Install MySQL on macOS Sierra

This procedure explains how to install MySQL using Homebrew on macOS Sierra 10.12

Install Homebrew

  • Installing Homebrew is effortless, open Terminal and enter :
    $ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
  • Note: Homebrew will download and install Command Line Tools for Xcode 8.0 as part of the installation process.

Install MySQL

At this time of writing, Homebrew has MySQL version 5.7.15 as default formulae in its main repository :