Skip to content

Instantly share code, notes, and snippets.

Avatar
🚀

Edvaldo Szymonek edvaldoszy

🚀
View GitHub Profile
View nested-object-url-search-params.js
function getPathWithKey(path, key) {
return typeof path === 'string' ? `${path}[${key}]` : key;
}
/**
* Esta função converte um objeto plano com chaves aninhadas para
* o formato esperado pelo URLSearchParams, que é utilizado nas requisições
* que exige o "Content-Type": "application/x-www-form-urlencoded".
*
* Um objeto com estrutura
View docker-setup.sh
#!/bin/sh
CONFIG_FILE=/etc/docker/daemon.json
cat << CONFIG > $CONFIG_FILE
{
"log-driver": "json-file",
"log-opts": {
"max-size": "50m",
"max-file": "1"
View cors.conf
# https://enable-cors.org/server_nginx.html
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log /var/log/nginx/host.access.log main;
root /usr/share/nginx/html;
View convert-time-to-human-readable.js
function convertTimeToHumanReadable(time) {
const units = [
['days', 480], // 8 horas (8 * 60)
['hours', 60],
['minutes', 1],
];
function reducer({ duration, ...others }, [unit, amount]) {
const result = Math.floor(duration / amount);
@edvaldoszy
edvaldoszy / ReactNative.dockerfile
Last active Dec 10, 2019
Docker React Native Android
View ReactNative.dockerfile
FROM openjdk:8-jdk
ENV ANDROID_COMPILE_SDK="28"
ENV ANDROID_BUILD_TOOLS="28.0.3"
ENV ANDROID_SDK_TOOLS="4333796"
ENV ANDROID_HOME="${PWD}/android-sdk-linux"
ENV PATH="${PATH}:${PWD}/android-sdk-linux/platform-tools/"
RUN apt update -qy; \
apt install -qy curl unzip; \
@edvaldoszy
edvaldoszy / object-get-path.js
Last active Jan 23, 2020
Get path from JavaScript Object
View object-get-path.js
/**
* Get object path value or return defaultValue
* @param {object} object Object to get path value
* @param {string[]} keys Object path in an array
* @param {any} defaultValue Default value if the path does not exists
*/
function getPath(object, keys, defaultValue) {
if (keys.length === 1) {
const [curr] = keys;
return object[curr];
@edvaldoszy
edvaldoszy / csv-import.js
Created Nov 21, 2019
Faz a importação de um CSV para o banco de dados
View csv-import.js
const { Writable } = require('stream');
const { createReadStream } = require('fs');
const Split = require('stream-split');
const input = createReadStream('./votacao_candidato_munzona_2018_PR.csv', { encoding: 'latin1' });
// const [nl] = Buffer.from('\n');
// const buffer = Buffer.from('Edvaldo\nSzymonek');
// console.log(buffer[7] === nl);
@edvaldoszy
edvaldoszy / prepare-commit-msg.sh
Last active Oct 31, 2019
Modificando mensagem de commit
View prepare-commit-msg.sh
#!/bin/bash
MSG="$(cat $1)"
if [[ "$MSG" =~ ^\#[0-9]+ ]]; then
echo "gam-backlog${MSG}" > $1
fi
@edvaldoszy
edvaldoszy / d2-max-block
Last active Sep 7, 2019
Calcula a porcentagem de bloqueio de um personagem em Diablo II
View d2-max-block
#!/usr/bin/env node
require('./diablo2-calc-max-block');
@edvaldoszy
edvaldoszy / .bash_aliases
Last active Mar 31, 2020
Adicionado alias para o Docker
View .bash_aliases
alias yi='yarn install'
alias ya='yarn add $@'
alias yad='yarn add -D $@'
alias cai='rm -rf node_modules && yarn install'
alias rnra='react-native run-android'
alias rnri='react-native run-ios'
alias docp='docker container prune -f'
alias dosp='docker system prune --all'