Skip to content

Instantly share code, notes, and snippets.

View diogomachado's full-sized avatar
🎯
Focusing

Diogo Machado diogomachado

🎯
Focusing
View GitHub Profile

Semantic Commit Messages

See how a minor change to your commit message style can make you a better programmer.

Format: <type>(<scope>): <subject>

<scope> is optional

Example

@diogomachado
diogomachado / .hyper.js
Created August 21, 2022 13:33
Hyperjs config
'use strict'
// Future versions of Hyper may add additional config options,
// which will not automatically be merged into this file.
// See https://hyper.is#cfg for all currently supported options.
module.exports = {
config: {
// choose either `'stable'` for receiving highly polished,
// or `'canary'` for less polished but more frequent updates
updateChannel: 'stable',
// default font size in pixels for all tabs
@diogomachado
diogomachado / error-handling-with-fetch.md
Created January 17, 2021 15:18 — forked from odewahn/error-handling-with-fetch.md
Processing errors with Fetch API

I really liked @tjvantoll article Handling Failed HTTP Responses With fetch(). The one thing I found annoying with it, though, is that response.statusText always returns the generic error message associated with the error code. Most APIs, however, will generally return some kind of useful, more human friendly message in the body.

Here's a modification that will capture this message. The key is that rather than throwing an error, you just throw the response and then process it in the catch block to extract the message in the body:

fetch("/api/foo")
  .then( response => {
    if (!response.ok) { throw response }
    return response.json()  //we only get here if there is no error
 })
@diogomachado
diogomachado / mysql-docker.sh
Created January 15, 2021 01:39 — forked from spalladino/mysql-docker.sh
Backup and restore a mysql database from a running Docker mysql container
# Backup
docker exec CONTAINER /usr/bin/mysqldump -u root --password=root DATABASE > backup.sql
# Restore
cat backup.sql | docker exec -i CONTAINER /usr/bin/mysql -u root --password=root DATABASE
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
Anonymous UUID: 217AD8CA-3F97-8F7B-FC29-9D7E60A9765B
Wed Sep 4 19:33:49 2019
*** Panic Report ***
panic(cpu 0 caller 0xffffff80012b8a8f): initproc exited -- exit reason namespace 2 subcode 0xa description: none
uuid info:
0x10f9e9000 uuid = <3eba447f-a546-366b-b302-8dc3b21a3e30>
0x10460b000 uuid = <ae67e27b-133c-3e19-b3e1-d8151233254d>
@diogomachado
diogomachado / realtime.js
Created October 27, 2018 01:53
Pesquisa - Realtime Database
var pesquisa = "Diogo So";
var query = db
.ref('albuns')
.orderByChild('nome')
.startAt(pesquisa)
.endAt(pesquisa + "\uf8ff");
query.on('value', function(snapshot){
if (snapshot.val()){
{ "eventKey" : "LIKE", //REQUIRED String que representa o evento que gera o alerta
"loginReceiver" : "diogosm", //REQUIRED (alias, idpId or userCode) quem receberá o alerta
"priority" : "NORMAL", // Options: NONE (Doesn't send notification), LOW, NORMAL and HIGH
"object" : { // o objeto do alerta, como documento, postagem, imagem ou processo
"alertObjectId" : "1", // o número de identificação exclusivo do objeto
"alertObjectTypeDescriptionKey" : "Contract", // descrição do tipo de objeto
"alertObjectDescription" : "Agreement document", // a descrição do objeto mostrada no alerta
"alertObjectLink" : "/ecmnavigation?app_ecm_navigation_doc=7", // o link para acessar o objeto
"alertObjectDetailKey" : "from last Monday meeting", // (OPTIONAL) detalhes da chave
"alertObjectNote" : "Approved by the board members" // (OPTIONAL) a nota de objeto para informações extras, permite até 600 caracteres
@diogomachado
diogomachado / after_build.js
Created November 8, 2017 18:04
Livro - Hook para informar no terminal o tamanho do arquivo APK
module.exports = function(ctx) {
// Se certifica de ter a plataforma android
if (ctx.opts.platforms.indexOf('android') < 0) {
return;
}
// Inicializa as dependencias nodejs
var fs = ctx.requireCordovaModule('fs'),
path = ctx.requireCordovaModule('path'),
@diogomachado
diogomachado / after_prepare.js
Created September 1, 2017 13:27
Livro - Hook nodejs para deletar arquivos desnecessários do bower
#!/usr/bin/env node
var del = require('del');
var fs = require('fs');
var path = require('path');
// Diretório para excluir
var diretorio = 'platforms/android/assets/www/bower_components/';
function verificarDiretorio(diretorio, expressaoRegular, callback){