Skip to content

Instantly share code, notes, and snippets.

@jeff-silva
Last active January 16, 2024 23:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeff-silva/2ba8a88098cb5cceb3ab12eb04ba0c39 to your computer and use it in GitHub Desktop.
Save jeff-silva/2ba8a88098cb5cceb3ab12eb04ba0c39 to your computer and use it in GitHub Desktop.
Awesome
# Docker composer
docker run --rm -it -v ${PWD}:/app -w /app composer bash
# Docker bash node
docker run --rm -it -v ${PWD}:/app -w /app node bash
# Create "new-branch" from "dev"
git checkout -b new-branch dev
# Couldn't find remote ref branch-name
git push -u origin branch-name
# Switch to branch, -b create branch if does not exists
git checkout branch-name
git checkout -b branch-name
# If repository folder has permission error
git config core.fileMode false
# Remove all changes
git reset --hard

Brasil com S

Banco de imagens gratuitas adaptadas para a realidade brasileira
https://www.brasilcoms.com.br


Story Set

Ícones gratuitos com ferramenta para animação
https://storyset.com

Para criar uma imagem animada, faça uma busca, clique na imagem desejada e então em "animate it"


Flaticon

Ícones gratuitos com vários formatos para exportação
https://www.flaticon.com


Unspash

Banco de imagens gratuito
https://unsplash.com

API de imagens aleatórias do Unsplash
https://source.unsplash.com
https://source.unsplash.com/random/800x600
https://source.unsplash.com/800x600/?nature,water


Nappy

Banco de imagens gratuitas só com pessoas negras
https://nappy.co/

Format number

const formatNumber = (number) => {
  return Intl.NumberFormat('en', {
    notation: 'compact',
    minimumFractionDigits: '0',
  }).format(number);
};

// formatNumber(10000)    => 10k
// formatNumber(100000)   => 100k
// formatNumber(1000000)  => 1M
// formatNumber(10000000) => 1B

Validação de CPF, CNPJ, CNH, NIS, Título Eleitoral e Cartão Nacional de Saúde com Laravel.

# Run specific migration
php artisan migrate --path=/database/migrations/2020_01_01_000000_create_example_table.php
# Rollback specific migration
php artisan migrate:rollback --path=/database/migrations/2020_01_01_000000_create_example_table.php
# Create model and controller
php artisan make:controller ModelController --model=Model
// Show raw sql command
function ddquery($query) {
    $sql = vsprintf(str_replace(['?'], array('\'%s\''), $query->toSql()), $query->getBindings());
    dd($sql, $query->get()->toArray());
}
# Create sail app: "app" is application folder name.
# add ?with=mysql,redis to create custom services
curl -s "https://laravel.build/app" | bash
# Delete recursively
sudo rm -rf ./node_modules
# Change folder permission
sudo chmod -R 777 ./node_modules
# Delete all Zone.Identifier files
find . -name "*:Zone.Identifier" -type f -delete
# Create server.crt and server.key files
openssl genrsa 2048 > server.key
chmod 400 server.key
openssl req -new -x509 -nodes -sha256 -days 365 -key server.key -out server.crt
-- Date range percent between two dates (date_start, date_current, date_final)
-- Example table schema:
-- projects: id(int), title(varchar 255), date_start(datetime), date_final(datetime)

select *,

	@total_hours := greatest(0, TIMESTAMPDIFF(HOUR, date_start, date_final)) as total_hours,

	@total_hours_past :=
		if(date_start='0000-00-00 00:00:00' OR date_start='1970-01-01 00:00:00', 0,
		greatest(0, TIMESTAMPDIFF(HOUR, date_start, curdate()))
	) as total_hours_past,

	ROUND(LEAST(100, GREATEST(0, ifnull(((@total_hours_past/@total_hours)*100), 0))), 2) as total_hours_percent,

from `projects`;
-- Disable foreign key check (0:disable, 1:enable)
SET FOREIGN_KEY_CHECKS=0;
SET GLOBAL FOREIGN_KEY_CHECKS=0;
# Install NPM globally
npm install -g npm@latest
<!DOCTYPE html><html lang="en"><head>
<meta charset="UTF-8"><title>Swagger UI</title>
<link rel="stylesheet" href="https://unpkg.com/swagger-ui-dist@3.12.1/swagger-ui.css">
<style>html, body {margin:0; padding:0;}</style>
</head><body>
<div id="swagger-ui"></div>
<script src="https://unpkg.com/swagger-ui-dist@3.12.1/swagger-ui-standalone-preset.js"></script>
<script src="https://unpkg.com/swagger-ui-dist@3.12.1/swagger-ui-bundle.js"></script>
<script>
window.onload = function() {
new SwaggerUIBundle({
dom_id: "#swagger-ui",
deepLinking: true,
presets: [SwaggerUIBundle.presets.apis, SwaggerUIStandalonePreset],
layout: "StandaloneLayout",
spec: {
"openapi": "3.0.2",
"info": {
"title": "JSONPlaceholder",
"description": "Fake Online REST API for Testing and Prototyping",
"version": "0.0.1"
},
"paths": {
"/posts": {
"get": {
"description": "List all posts",
"responses": {
"200": {
"description": "Successfully fetched all posts from JSONPlaceholder",
"content": {
"application/json": {
"schema": {
"type": "array",
"items": {
"type": "object",
"properties": {
"userId": {
"type": "number"
},
"id": {
"type": "number"
},
"title": {
"type": "string"
},
"body": {
"type": "string"
}
},
"example": {
"userId": 1,
"id": 1,
"title": "sunt aut facere repellat provident occaecati excepturi optio reprehenderit",
"body": "quia et suscipit\nsuscipit recusandae consequuntur expedita et cum\nreprehenderit molestiae ut ut quas totam\nnostrum rerum est autem sunt rem eveniet architecto"
}
}
}
}
}
}
}
}
}
}
},
});
};
</script>
</body></html>

Abrir Gmail ao clicar em um link com protocolo mailto:

Abra o Gmail pelo navegador e digite o código abaixo no console:

navigator.registerProtocolHandler("mailto", "https://mail.google.com/mail/?extsrc=mailto&url=%s", "Gmail");

Um browser de confirmação será exibido, e caso confirmado, registrará o protocolo.
É possível registar mais de uma ação para um protocolo, portanto, caso queira remover ou tornar padrão um protocolo registrado pelo navegador, acesse chrome://settings/handlers para gerenciar.

Wordpress: erro no /wp-admin/admin-ajax.php O erro nunca é informado nesse endpoint. Para ter uma pista de onde esta ocorrendo o problema, edite o arquivo /wp-includes/class-wp-fatal-error-handler.php e no método display_default_error_template insira um print_r($error); die;. É uma solução horrível, mas é o que resta quando não existe mais esperanças.

Tools and Services

JSON Resume

The open source initiative to create a JSON-based standard for resumes. For developers, by developers. https://jsonresume.org/

<svg width="100%" :viewBox="up.svg.viewBox" style="border:solid 1px red;">
<circle cx="0" cy="0" r="2" style="stroke:red;"/>
<rect x="0" :y="up.height*-1" :width="up.width" :height="up.height" style="fill:#000;" />
<!-- <path style="stroke:#000; stroke-width:1; fill:transparent;" :d="[
'M 0 0',
't 10 0',
't 10 -2',
't 10 0',
't 10 -5',
't 10 5',
].join(' ')" /> -->
<!-- <path style="stroke:#000; stroke-width:1; fill:transparent;" :d="[
'M 0 0',
's 5 0 10 0',
's 5 -5 10 0',
's 5 -10 10 0',
's 5 -20 10 0',
's 5 -50 10 0',
's 5 -100 10 0',
].join(' ')" /> -->
<path style="stroke:#ddd; stroke-width:1; fill:transparent;" :d="up.svg.path" />
</svg>
<v-defaults-provider
:defaults="{
VTextField: { hideDetails: true },
}"
>
<v-row no-gutters>
<v-col cols="4"><v-text-field label="width" v-model.number="up.width" type="number" /></v-col>
<v-col cols="4"><v-text-field label="height" v-model.number="up.height" type="number" /></v-col>
<v-col cols="4"><v-text-field label="viewBoxOffset" v-model.number="up.viewBoxOffset" type="number" /></v-col>
<v-col cols="4"><v-text-field label="rows" v-model.number="up.rows" type="number" /></v-col>
<v-col cols="4"><v-text-field label="cols" v-model.number="up.cols" type="number" /></v-col>
<v-col cols="4"><v-text-field label="elevHeight" v-model.number="up.elevHeight" type="number" /></v-col>
<v-col cols="4"><v-text-field label="elevRandom" v-model.number="up.elevRandom" type="number" /></v-col>
<!-- <v-col cols="12">{{ up.svg.path }}</v-col> -->
</v-row>
</v-defaults-provider>
<!-- <pre>{{ up }}</pre> -->
<script setup>
import _ from 'lodash';
import { reactive, computed } from 'vue';
const gaussCurve = (numPoints, maxValue, mean) => {
const points = [];
const standardDeviation = maxValue / 3;
for (let i = 0; i < numPoints; i++) {
const x = (i / (numPoints - 1)) * (maxValue * 2) - maxValue;
const y = (1 / (standardDeviation * Math.sqrt(2 * Math.PI))) * Math.exp(-(Math.pow(x - mean, 2) / (2 * Math.pow(standardDeviation, 2))));
points.push(y);
}
const maxPointValue = Math.max(...points);
const scaleFactor = maxValue / maxPointValue;
const scaledPoints = points.map((value) => value * scaleFactor);
return scaledPoints.map(n => Math.round(n));
};
const up = reactive({
viewBox: '0 0 0 0',
viewBoxOffset: 50,
width: 400,
height: 400,
rows: 20,
cols: 20,
elevHeight: 100,
elevRandom: 10,
path: '',
svg: computed(() => {
const viewBox = [
-up.viewBoxOffset,
(up.height+up.viewBoxOffset)*-1,
up.width+(up.viewBoxOffset*2),
up.height+(up.viewBoxOffset*2),
].join(' ');
const path = _.range(up.rows).map((i, y) => {
y = (i*(up.height/up.rows))*-1;
return `M 0 ${y} `+ gaussCurve(up.cols, up.elevHeight, 0).map((n, ii) => {
const r = _.random(n-up.elevRandom, n+up.elevRandom, true) *-1;
const xx = (ii+1)*(up.width/up.cols);
const yy = y+r;
return `T ${xx} ${yy}`;
}).join(' ');
}).join(' ');
return {
viewBox,
path,
};
}),
});
</script>
# Deletar pasta rapidamente
rmdir /s /q node_modules
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment