Skip to content

Instantly share code, notes, and snippets.

View nandomoreirame's full-sized avatar
🎧
Working from home

Fernando Moreira nandomoreirame

🎧
Working from home
View GitHub Profile
@nandomoreirame
nandomoreirame / how-much-in-localstorage.js
Created April 5, 2021 16:41
how much is in localstorage
let _lsTotal = 0;
let _xLen;
let _x;
for (_x in localStorage) {
if (!localStorage.hasOwnProperty(_x)) {
continue;
}
_xLen = ((localStorage[_x].length + _x.length) * 2);
_lsTotal += _xLen;
@nandomoreirame
nandomoreirame / promise-timeout.js
Created March 31, 2020 20:46
Timeout with Promise for use async await
const timeout = ms => new Promise(resolve => setTimeout(resolve, ms));
const sleep = async (fn, ...args) => {
await timeout(3000);
return fn(...args);
};
@nandomoreirame
nandomoreirame / nuxt-plugin-axios.js
Created January 23, 2020 21:12
Nuxt.js plugin Axios
export default function ({ $axios }, { redirect }) {
$axios.defaults.headers['Content-Type'] = 'application/json';
$axios.onRequest((config) => {
const apiToken = process.env.API_USER_TOKEN || '';
config.headers.Authorization = apiToken ? `JWT ${apiToken}` : '';
console.log(`${config.baseURL}${config.url}`, 'Request');
return config;
@nandomoreirame
nandomoreirame / image-url.js
Last active November 27, 2019 14:13
Add https to image - Vue
import { replaceUrl } from './utils';
export default {
computed: {
partnerImage() {
return replaceUrl(this.item.partner.imageUrl);
},
},
};
@nandomoreirame
nandomoreirame / geolocation-store.js
Created September 27, 2019 19:52
GeoLocation Vuex Store
const state = {
loading: false,
geolocation: {},
};
const mutations = {
TOGGLE_LOADING(state, payload) {
state.loading = !!payload;
},
CHANGE_GEOLOCATION(state, payload) {
const form = {
name: '',
email: '',
phone: '',
message: ''
}
export default {
data: () => ({
form
@nandomoreirame
nandomoreirame / gpg-key.md
Last active August 1, 2021 19:53
Github verify commits

Keybase proof

I hereby claim:

  • I am nandomoreirame on github.
  • I am onandomoreira (https://keybase.io/onandomoreira) on keybase.
  • I have a public key ASCWboqGKY1Tl79c0VTsmn4LKZNn678UOOnOH9GJzUFaFAo

To claim this, I am signing this object:

@nandomoreirame
nandomoreirame / functions.php
Created August 19, 2019 13:23
Function get page ID by slug
<?php
function get_page_id_by_slug($page_slug) {
$page = get_page_by_path($page_slug);
if ($page) {
return $page->ID;
}
return null;
@nandomoreirame
nandomoreirame / http-axios.js
Created August 19, 2019 13:18
Axios http interceptors with NProgress
import axios from 'axios'
import NProgress from 'nprogress'
import config, { isProduction } from '@/config'
/**
* Axios methods
* Doc: https://kapeli.com/cheat_sheets/Axios.docset/Contents/Resources/Documents/index
*
* http
* .get(url, { params })
@nandomoreirame
nandomoreirame / .editorconfig
Last active August 4, 2021 20:31
my .editorconfig
# https://editorconfig.org
root = true
[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true