Skip to content

Instantly share code, notes, and snippets.

View sr2ds's full-sized avatar
:octocat:
Coding

David Silva sr2ds

:octocat:
Coding
View GitHub Profile
@sr2ds
sr2ds / genericTests.js
Last active July 5, 2022 11:55
Methods to make a simple automatic tests system to non-tdd systems
/**
* code from: https://gist.github.com/sr2ds/1786aaff13948c89f4efcb7124ce2222
*
* Author: David Silva
* Dependencies: expressJs, mongoose, mocha, chai and chaiHttp
* necessary run mocha command with --delay param
*
* how it works:
* this project will allow you to store the state of all requests
* and use it to do automatic tests
@sr2ds
sr2ds / log-requests-express-middleware.js
Last active June 23, 2022 19:47
Middleware to make logs for requests in NodeJs - ExpressJs
// Mongoose model to store logs
logModel = () => {
const db = require('../lib/db');
const Schema = db.Schema;
const logsSchema = new Schema({
method: { type: String, trim: true },
url: { type: String, trim: true },
query: { type: Object, },
@sr2ds
sr2ds / getMemoryUsage.php
Created November 9, 2021 10:22
Check memory usage PHP script
<?php
// https://www.php.net/manual/en/function.memory-get-usage.php#96280
function convert($size)
{
$unit=array('b','kb','mb','gb','tb','pb');
return @round($size/pow(1024,($i=floor(log($size,1024)))),2).' '.$unit[$i];
}
echo convert(memory_get_usage(true)); // 123 kb
@sr2ds
sr2ds / life.json
Last active July 23, 2021 14:42
Array with life moments
[
{
"date": "2020-06",
"title": "",
"description": "Em desenvolvimento ...",
"category": "Tech Lead - Sr Developer",
"icon": "code",
"color": "white",
"tags": [
"Linux",
@sr2ds
sr2ds / check-redis-queues-containers.sh
Last active April 9, 2021 15:36
Check Queues Health Redis Docker Containers
#!/bin/bash
## Check Queues Health Redis Docker Containers
# if your have many redis containers with queue processing, this script can help you
# when any application worker stop or have delayed, this script can send mail for you with this information
sendTo="email@email.com"
lengthToWarning="10"
docker ps | grep redis | awk '{print $1}' | while read container; do
@sr2ds
sr2ds / PdfThumbnail.vue
Created November 6, 2020 18:21
A simple PDF Thumbnail Component Viewer for VueJs
<template>
<div>
<div class="row">
<div class="col-sm-4">
<a :href="fileUrl">
<canvas :id="_uid" />
</a>
</div>
</div>
</div>
@sr2ds
sr2ds / gitTagJsonOutputMultiProject.js
Last active September 2, 2020 20:13
NodeJs script to get all tags in json format from multiple local git repositories
const moment = require('moment')
// Define your local projects in here
const projects = [
{ name: 'painel', source: '~/apps/apis/api-carrinho', tags: [] },
{ name: 'pagamento', source: '~/apps/apis/api-pagamento', tags: [] }
]
// https://gist.github.com/sr2ds/20666cbae5621cf2ede8e7bffec8ae0d
const gitCommand = ` \
@sr2ds
sr2ds / gitTagJsonOutput.js
Created September 2, 2020 16:21
NodeJs script to get all tags in json format from local git repository
// import lib to execute shell
const shellExec = require('shell-exec')
// build shell command to get tags with subject and date
const gitCommand = ` \
git tag -l \
--format='{\n
"tag": "%(tag)", \n \
"subject": "%(subject)", \n \
"created": "%(creatordate)" \n \
@sr2ds
sr2ds / gitRemoveLocalBranch.sh
Created May 4, 2020 13:05
git Remove merged local branch
#!/bin/bash
git branch --merge | grep -v develop| grep -v master | awk '{ print $1 }'| while read branch; do git branch -D $branch; done