Skip to content

Instantly share code, notes, and snippets.

View marcelod's full-sized avatar
🎯
Focusing

Marcelo Diniz marcelod

🎯
Focusing
  • São Paulo - Brasil
View GitHub Profile
@marcelod
marcelod / printing.php
Created May 25, 2023 14:12 — forked from tiagoporto/printing.php
Printing In PHP.
<?php
$var = print "Variable";
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
# remove specific file from git cache
git rm --cached filename
# remove all files from git cache
git rm -r --cached .
git add .
git commit -m ".gitignore is now working"
@marcelod
marcelod / RemoveBranchsLocais.md
Last active August 29, 2022 20:55
Remove branchs locais que já foram enviadas para master (main)
@marcelod
marcelod / formatar_cnpj_cpf.md
Created August 18, 2022 22:07 — forked from davidalves1/formatar_cnpj_cpf.md
Função para formatar CNPJ e CPF, disponível em PHP e JS

PHP

function formatCnpjCpf($value)
{
  $CPF_LENGTH = 11;
  $cnpj_cpf = preg_replace("/\D/", '', $value);
  
  if (strlen($cnpj_cpf) === $CPF_LENGTH) {
    return preg_replace("/(\d{3})(\d{3})(\d{3})(\d{2})/", "\$1.\$2.\$3-\$4", $cnpj_cpf);
  } 
@marcelod
marcelod / rand.sql
Created July 30, 2022 01:53
Número aleatório sql
PARA GERAR UM NUMERO ALEATÓRIO NO SQL
-- ALEATORIO: (ALEATORIO() * (MAX - MIN + 1)) + MIN
-- exemplo de chamada
SELECT FLOOR((RAND() * (100-50+1)) + 50) AS ALEATORIO;
@marcelod
marcelod / seconds_to_time.php
Last active July 27, 2022 19:12
Convert seconds to hours : minutes : seconds
<?php
function seconds_to_time($seconds)
{
$normalized = (int) ($seconds ?? 0);
if ($normalized === 0) {
return '00:00:00';
}
<!doctype html>
<html lang="pt-BR">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>jsPDF</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<?php
$items = [];
foreach ($products as $value) {
$items[] = [
'product_id' => $value->id,
'name' => $value->name,
];
}
return collect($items)->all();
@marcelod
marcelod / gist:74162a499b13f4490587c771774bfb77
Last active September 14, 2020 13:09
Deploy com git automatizado

Parte do servidor

  • acessar via ssh o servidor, por exemplo ssh user@ip
  • no servidor, acessar a pasta do projeto, por exemplo, /var/www/meu-projeto/
  • criar e acessar a pasta, por exemplo app.git (mkdir app.git && cd app.git)
  • dentro de app.git, executar o comando git init --bare para criar um repositório mínimo git
  • criar um arquivo chamado post-receive dentro de app.git/hooks - nano hooks/post-receive e adicionar o seguinte conteúdo
#!/bin/sh