Skip to content

Instantly share code, notes, and snippets.

@ric2b
ric2b / extensions.py
Last active March 28, 2021 01:35 — forked from Framartin/extensions.py
Simplest scrapy extension to send all errors and exceptions to Sentry
import sentry_sdk
import os
from scrapy.exceptions import NotConfigured
class SentryLogging(object):
"""
Send exceptions and errors to Sentry.
"""
@classmethod
import csv
import glob
from collections import defaultdict
# run from the directory you extracted the takeout zip/tar files into
takeout_sections = glob.glob('takeout-*')
playlist_directories = [glob.glob(f'{section}/Takeout/Google Play Music/Playlists/*') for section in takeout_sections]
playlist_directories_flat = [item for sublist in playlist_directories for item in sublist]
@ric2b
ric2b / poetry_bug_report_1.toml
Last active December 13, 2019 14:20
--extras not included when doing `poetry export --extras "raspberry" -f requirements.txt`
[tool.poetry]
name = "my-project"
version = "0.1.0"
description = ""
authors = [
"myname <myname@example.com>"
]
[tool.poetry.dependencies]
python = "^3.6"
@ric2b
ric2b / advent_of_code_2017.py
Last active December 6, 2018 17:50
My solutions (and automated input fetcher and runner) to the daily "christmas calendar" programming puzzles from https://adventofcode.com/2017
import collections
from math import sqrt
from functools import reduce
import string
INPUTS_FILE = 'advent_of_code_inputs.txt'
SOLUTIONS_FILE = 'advent_of_code_solutions.txt'
SESSION_FILE = 'advent_of_code_session.txt'
SOLVER_CLASS_PREFIX = 'Day'
@ric2b
ric2b / run_cluster.sh
Created March 16, 2017 21:20
run a command in multiple machines
#!/bin/bash
user=myuser
# use ssh keys for simple login
machines=(ip1 ip2)
for machine in $(machines[*])
do
echo "running $1 on $user@$machine"
echo "$machine: $(ssh $user@$machine "$1") &
@ric2b
ric2b / rsync_cluster.sh
Last active March 16, 2017 21:22
rsync to multiple machines with same account
#!/bin/bash
user=myuser
# use ssh keys for simple login
machines=(ip1 ip2)
for machine in $(machines[*])
do
echo "sending $1 to $user@$machine:$2"
echo "$machine: $(rsync -avP $1 $user@$machine:$2)" &
#!/bin/bash
db=wells_US
collection=points
import_file=~/pocos-mapa-escala.geojson
executables_location=~/mongo
tools_location=~mongo-tools
dbs_location=~/dbs
logs_location=~/mongo_logs
@ric2b
ric2b / hook.io_commit_author_spoof_check.js
Created October 5, 2016 18:17
Hook.io webhook to prevent Github commits spoofed by the pusher (not authored by him. git allows you to modify commit authors at will, so you can impersonate other users)
// The hook variable has a bunch of information about the request, check hook.io's documentation to learn more about it
module['exports'] = function accessRequestData (hook) {
var request = require('request');
var OAuth_token = hook.env.token;
// After creating your token on Github.com -> Settings -> Personal access tokens,
// add the token as an environment variable names 'token' on hook.io.
var params = hook.params;
var pusher = params.pusher;
var repo = params.repository.full_name;
@ric2b
ric2b / random_points_in_square.py
Last active July 4, 2016 11:08
Calculate the average distance between 2 random points inside a 1x1 square using a Monte Carlo simulation
from random import random # the random function yelds values between 0 and 1
def distance(x1,y1,x2,y2):
return ((x1-x2)**2+(y1-y2)**2)**(1/2)
def results(n):
for i in range(n):
yield distance(random(),random(),random(),random())
  1. Instalar python 3.5 (64bits recomendado se o computador suportar):
  • Em linux já deve vir instalado, corre python3 no terminal para verificar. (também pode ser python mas confirma a versão)
  • Windows/Mac: https://www.python.org/downloads
  1. Confirmar que o pip (o instalador de bibliotecas de python) está instalado, abrindo uma linha de comandos e correndo pip3 --version ou pip --version (confirma que diz ser para python 3.5

  2. Instalar PyQt5.6, o QtDesigner5 e as ferramentas de conversão, pyuic5 e pyrcc5. Se o python for de 64bits o PyQt tb tem de ser.

  • Windows: https://www.riverbankcomputing.com/software/pyqt/download5
  • Linux/Mac: varia com a distribuição, procura como fazes para a tua se não for Arch ou Ubuntu. Tens de garantir que consegues correr pyuic5 e pyrcc5 no terminal, correr python3 ou python e depois fazer import PyQt5 e abrir o QtDesigner.
    • Ubuntu: sudo apt-get install python3-pyqt5 pyqt5-dev-tools qttools5-dev-tools. Para abrir o designer abre `/usr