Skip to content

Instantly share code, notes, and snippets.

View viniroger's full-sized avatar

Vinicius Roggério da Rocha viniroger

View GitHub Profile
@viniroger
viniroger / gist.sh
Last active December 14, 2017 09:42
Exemplo de um gist
#!/bin/bash
## Script qualquer
echo "Monolito Nimbus - esse código está publicado em GitHubGist"
@viniroger
viniroger / medias.R
Last active December 15, 2017 13:13
Calcular médias mensais e semanais
library(xts)
lugar = 'RiodeJaneiro-RJ'
file_in = paste('/path/ObsVar_diario_',lugar,'.csv',sep='')
file_out_mensal = paste('/path/ObsVar_mensal_',lugar,'.csv',sep='')
file_out_semanal = paste('/path/ObsVar_semanal_',lugar,'.csv',sep='')
write_file = function(dados,file_out){
# Arredondar para inteiro
coredata(dados) = round(coredata(dados))
@viniroger
viniroger / meses.sh
Created January 26, 2018 13:32
Loop para imprimir os meses em um intervalo
#!/bin/bash
# Script para imprimir os meses dentro de um intervalo
data_inicial="2015-10-01"
data_final="2017-02-01"
ini_sec=$( date -d "$data_inicial" "+%s" )
fim_sec=$( date -d "$data_final" "+%s" )
data_sec=$ini_sec
for (( i=0; data_sec < fim_sec; ++i )); do
@viniroger
viniroger / infinito.sh
Created January 26, 2018 13:54
Loop infinito
#!/bin/bash
# Script para imprimir sequência de números infinitamente
numero=0
while true; do
echo $numero
sleep 1
numero=$((numero + 1))
done
@viniroger
viniroger / select_year.R
Created March 20, 2018 10:55
Selecionar período em uma série temporal
# y is a time serie - ts()
year_date = window(y, start = c(2017,1), end = c(2017,12))
@viniroger
viniroger / separate_data.R
Last active April 3, 2018 11:58
Separate data by dates
# Pacote SQLDF e suas dependencias
suppressPackageStartupMessages(require(tcltk,lib=end_libs))
suppressPackageStartupMessages(require(proto,lib=end_libs))
suppressPackageStartupMessages(require(gsubfn,lib=end_libs))
suppressPackageStartupMessages(require(RSQLite,lib=end_libs))
suppressPackageStartupMessages(require(sqldf,lib=end_libs))
# Separate last data part to xreg_fut
data_ini = as.character(data$data[1])
data_lim1 = "2017-01-01"
@viniroger
viniroger / quiz_example.xml
Last active May 3, 2018 11:15
Quiz on XML exported (and indented) from WP-Pro-Quiz plugin with 1 quiz containing 2 questions | model ready to import
<?xml version="1.0" encoding="UTF-8"?>
<wpProQuiz>
<header version="0.37" exportVersion="1" />
<data>
<quiz>
<title titleHidden="false"><![CDATA[Título do questionário]]></title>
<text><![CDATA[Breve descrição do questionário]]></text>
<category>Bloco 1</category>
<resultText gradeEnabled="false"><![CDATA[Comentário no fim dos resultados]]></resultText>
<btnRestartQuizHidden>false</btnRestartQuizHidden>
@viniroger
viniroger / list_files.R
Created May 18, 2018 09:04
Listar os arquivos do diretório "dados" terminados em ".csv", guardando os nomes em uma lista
files = list.files(path = 'dados', pattern = '.csv')
@viniroger
viniroger / write_week.R
Created May 18, 2018 09:10
Função para escrever número da semana entrando com data formato YYYY-mm-dd (conferir em http://whatweekisit.org/calendar-2018.html)
date_ini = '2018-05-10'
get_week_numbers = function(date_ini){
# Week number of first day from next month (1st week)
week_ini = as.integer(format(as.Date(date_ini), '%W'))
# Week number of first day from next-next month (4th or 5th week) minus 1 (+2 pra completar 6 semanas)
date_end_temp = as.character(as.Date(date_ini) + 31)
date_end = paste(strsplit(date_end_temp, '-')[[1]][1], strsplit(date_end_temp, '-')[[1]][2], '01', sep = '-')
week_end = as.integer(format(as.Date(date_end), '%W')) - 1 + 2
# Return array with year and week numbers
year = format(as.Date(date_ini), '%Y')
@viniroger
viniroger / ping_test.sh
Last active June 5, 2018 20:10
Test many IP addresses and save output on log file
#!/bin/bash
# Script to test many IP addresses
ips=( '192.168.0.1' '192.168.0.2' '192.168.0.4' '192.168.0.12' '192.168.0.102' )
descr=( 'Host 1' 'Host 2' 'Host 3' 'Host 4' 'Host 5' )
filename='pings_'$(cat /etc/hostname)'.txt'
rm -f $filename; touch $filename
n=0
for ip in "${ips[@]}"; do