Skip to content

Instantly share code, notes, and snippets.

View willi-dev's full-sized avatar

willi-dev willi-dev

View GitHub Profile
@willi-dev
willi-dev / axios.refresh_token.js
Created June 24, 2020 04:17 — forked from Godofbrowser/axios.refresh_token.1.js
Axios interceptor for refresh token when you have multiple parallel requests. Demo implementation: https://github.com/Godofbrowser/axios-refresh-multiple-request
// for multiple requests
let isRefreshing = false;
let failedQueue = [];
const processQueue = (error, token = null) => {
failedQueue.forEach(prom => {
if (error) {
prom.reject(error);
} else {
prom.resolve(token);
@willi-dev
willi-dev / adminer_setup.sh
Created June 23, 2020 06:47 — forked from zloynemec/adminer_setup.sh
Secure adminer nginx setup
# Secure adminer setup
# Author Taras Kozlov
# download adminer to separate directory
mkdir -p /var/www/admin
cd /var/www/admin
wget http://www.adminer.org/latest.php -O adminer.php
echo '<?php phpinfo(); >' > info.php
sudo -i
@willi-dev
willi-dev / axios-interceptors-refresh-token.js
Created June 17, 2020 07:47 — forked from mkjiau/axios-interceptors-refresh-token.js
Axios interceptors for token refreshing and more than 2 async requests available
let isRefreshing = false;
let refreshSubscribers = [];
const instance = axios.create({
baseURL: Config.API_URL,
});
instance.interceptors.response.use(response => {
return response;
}, error => {
@willi-dev
willi-dev / iframe.html
Created May 15, 2020 02:37 — forked from cirocosta/iframe.html
Sending messages from child iframe to parent webpage
<!DOCTYPE html>
<html>
<head>
<title>My Iframe</title>
</head>
<body>
<button>Botão</button>
<script type="text/javascript">
############ first stage / builder #############
FROM node:12.5.0-alpine AS builder
WORKDIR /app
ADD package.json ./
ADD yarn.lock ./
RUN yarn
ADD . ./
RUN yarn build
@willi-dev
willi-dev / reduceExamples.js
Created March 9, 2020 03:39 — forked from quangnd/reduceExamples.js
Some examples about reduce() in Javascript
//Example 1 - Calculate average value of an array (transform array into a single number)
var scores = [89, 76, 47, 95]
var initialValue = 0
var reducer = function (accumulator, item) {
return accumulator + item
}
var total = scores.reduce(reducer, initialValue)
var average = total / scores.length
/*Explain about function
@willi-dev
willi-dev / babel-webpack.md
Created November 13, 2019 00:50 — forked from ncochard/babel-webpack.md
The correct way to compile ES6 using babel...

When you create a npm package, remember it might be used in a browser or a server, or even a command line utility… For each package you create, please pay attention at what it will be used for:

  1. Is it going to be used as a dependency to a nodejs application that is not bundled? (e.g. command line utilities)
  2. Is it going to be used as a dependency to a nodejs application that is bundled? (e.g. AWS Lambdas)
  3. Is it going to be used as a dependency to a browser application (always bundled)?.
  • In cases 2) and 3) you want to allow for tree shaking.
  • In cases 1) and 2) you want to benefit from the "ES6"/"ES next" features supported natively by nodejs.
  • In case 3) you also want to benefit from the native support of "ES6" from your browser.
@willi-dev
willi-dev / routeDeploy.js
Created September 27, 2019 05:56 — forked from clonn/routeDeploy.js
Node.js with Express, deploy through web hook. this is route part code.
var exec = require('child_process').exec;
var set = function (app) {
app.post('/deploy', function (req, res) {
var feedback;
var branch = 'master';
try {
feedback = JSON.parse(req.body.payload);
@willi-dev
willi-dev / better-nodejs-require-paths.md
Created September 23, 2019 02:34 — forked from branneman/better-nodejs-require-paths.md
Better local require() paths for Node.js

Better local require() paths for Node.js

Problem

When the directory structure of your Node.js application (not library!) has some depth, you end up with a lot of annoying relative paths in your require calls like:

const Article = require('../../../../app/models/article');

Those suck for maintenance and they're ugly.

Possible solutions

@willi-dev
willi-dev / Postman.desktop
Created September 9, 2019 07:40 — forked from aviskase/Postman.desktop
Install Postman
[Desktop Entry]
Encoding=UTF-8
Name=Postman
Exec=postman
Icon=/home/USERNAME/Postman/app/resources/app/assets/icon.png
Terminal=false
Type=Application
Categories=Development;