Skip to content

Instantly share code, notes, and snippets.

View theist's full-sized avatar
🐼

Carlos Peñas San José theist

🐼
View GitHub Profile
import urllib2
import json
def to_dotted(var, root=""):
if isinstance(var, dict):
for k in var.keys():
for r in to_dotted(var[k], root + "." + str(k)):
yield r
elif isinstance(var, list):
#!/usr/bin/env ruby
require 'json'
require 'paint'
curl = `curl -s 'https://elecciones28a.porcentual.es/widgets/2019-elecciones/data/00/json/widgets/widget-map.json' -H 'Accept: */*' -H 'Referer: https://newtral.es/resultado-elecciones-28a/' -H 'Origin: https://newtral.es' -H 'User-Agent: Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.121 Mobile Safari/537.36' --compressed`
res = JSON.parse(curl)['resultados']
escrutado = ""
@theist
theist / adosados.rb
Created January 8, 2018 19:12
implementacion rapida ruby de resolucion de "adosados" metodo ABN
#!/usr/bin/env ruby
#
numero = ARGV.shift.to_i
# si el numero es menor de 100 o mayor de 999 no puedo!
puts "+-----------------+"
puts "|" + "#{numero}".center(17) + "|"
puts "+-----+-----+-----+"
[global_tags]
[agent]
interval = "10s"
flush_interval = "10s"
precision = ""
debug = false
quiet = false
logfile = ""
hostname = ""
omit_hostname = true
@theist
theist / cronshell.sh
Created March 2, 2017 23:32
quick cronshell
#!/bin/bash
CRONLOG=/var/log/cron.log
RID=$(cat /dev/urandom | tr -dc "[:alpha:]" | head -c 8)
CMD=$@
START=$(date +%s)
echo "---- CRON --- START at $(date) --------" | ts | sed "s/^/[${RID}] /" >> ${CRONLOG}
echo "-- CMD: $@ ----" | ts | sed "s/^/[${RID}] /" >> ${CRONLOG}
/bin/bash -c "$@" > >( sed 's/^//') 2> >( sed 's/^/ [ERR]: /' ) | ts | sed "s/^/[${RID}] /" >> ${CRONLOG}
RETURN=$?
END=$(date +%s)
@theist
theist / Dockerfile
Created December 19, 2016 14:34
laice dockerfile
FROM debian
RUN apt-get -y update && apt-get -y install python3 python3-pip build-essential git wget curl
RUN curl -sL https://deb.nodesource.com/setup_4.x | bash -
RUN apt-get install -y nodejs
RUN git clone https://github.com/kendricktan/laice.git
WORKDIR laice
RUN npm install -g bower
RUN bower install --allow-root
RUN pip3 install -r requirements.txt
#RUN python3 -m spacy.en.download --force all # (LONG TIME, prone to fail and adds 700Mb img size, but leads to accurate results)
@theist
theist / rspec_sample.rb
Created October 27, 2016 22:06
rspec sample 1
require 'csv'
require 'excon'
# Cargamos los datos de redirecciones
csv_data = CSV(File.open('redirects.csv').read).read
#borramos la columna de encabezado
csv_data.delete_at(0)
# Configuramos excon para que no verifique el SSL y tenga un timeout bajo
Excon.defaults[:ssl_verify_peer] = false
input {
s3 {
# KEY / Secret de amazon, editar segun convenga
access_key_id => "AKIATITELAVOYADECIR"
secret_access_key => "876af98asd6f98ew6fasd98f"
# Bucket de s3 dodne se guarda el billing
bucket => "billing-bucket"
# prefijo (comienzo del nombre de fichero)
prefix => "555555555555555-aws-billing-csv-"
}
input {
s3 {
access_key_id => "AKIATITELOVOYADECIR"
secret_access_key => "Lw8QT+som3r4Nd0mB1Ts"
bucket => "billing-bucket-name"
prefix => "555555555555-aws-billing-csv-"
}
}
output {
if [date_error] in [tags] {
stdout { codec => plain }
} else {
stdout { codec => dots }
elasticsearch {
hosts => ["elasticsearch:9200"]
}
}
}