Skip to content

Instantly share code, notes, and snippets.

View crscardellino's full-sized avatar

Cristian Cardellino crscardellino

View GitHub Profile
@crscardellino
crscardellino / wines-data.csv
Last active May 5, 2024 15:23
Wine dataset from the UCI repository, in CSV format, split into train/test/validation. Source: https://archive.ics.uci.edu/dataset/109/wine
Quality Split Alcohol Malic acid Ash Alcalinity of ash Magnesium Total phenols Flavanoids Nonflavanoid phenols Proanthocyanins Color intensity Hue OD280/OD315 of diluted wines Proline
1 train 13.16 2.36 2.67 18.6 101 2.8 3.24 0.3 2.81 5.68 1.03 3.17 1185
1 train 14.37 1.95 2.5 16.8 113 3.85 3.49 0.24 2.18 7.8 0.86 3.45 1480
1 train 14.2 1.76 2.45 15.2 112 3.27 3.39 0.34 1.97 6.75 1.05 2.85 1450
1 train 14.83 1.64 2.17 14.0 97 2.8 2.98 0.29 1.98 5.2 1.08 2.85 1045
1 train 13.86 1.35 2.27 16.0 98 2.98 3.15 0.22 1.85 7.22 1.01 3.55 1045
1 train 14.12 1.48 2.32 16.8 95 2.2 2.43 0.26 1.57 5.0 1.17 2.82 1280
1 train 13.75 1.73 2.41 16.0 89 2.6 2.76 0.29 1.81 5.6 1.15 2.9 1320
1 train 13.63 1.81 2.7 17.2 112 2.85 2.91 0.3 1.46 7.3 1.28 2.88 1310
1 train 14.3 1.92 2.72 20.0 120 2.8 3.14 0.33 1.97 6.2 1.07 2.65 1280
@crscardellino
crscardellino / flatten_dict.py
Last active August 28, 2022 13:25
Python Flatten Dictionary
from collections.abc import MutableMapping
from typing import Any, Dict
def _flatten_dict_gen(d: MutableMapping, parent_key: str, sep: str):
for k, v in d.items():
new_key = parent_key + sep + k if parent_key else k
if isinstance(v, MutableMapping):
yield from flatten_dict(v, new_key, sep).items()
elif isinstance(v, list) or isinstance(v, list):
@crscardellino
crscardellino / get_1_to_n_combinations.py
Last active January 27, 2022 20:14
Get all the combinations from 1 to n elements of a list (where n is the length of the list)
def get_1_to_n_combinations(lst):
return list(itertools.chain([
c
for r in range(1, len(lst) + 1)
for c in itertools.combinations(sorted(lst), r)
]))
@crscardellino
crscardellino / nginx_access_logs_regex.py
Last active March 27, 2019 15:40
Regex to parse access logs from NGINX (inspired on https://gist.github.com/hreeder/f1ffe1408d296ce0591d)
import re
log_regex = re.compile(r"""(?P<remote_addr>[0-9a-f\.:]+)\s+-\s+""" +
r"""(?P<remote_user>\S+)\s+""" +
r"""\[(?P<date_day>\d{2})\/(?P<date_month>[a-zA-Z]{3})\/(?P<date_year>\d{4}):""" +
r"""(?P<time_hour>\d{2}):(?P<time_minutes>\d{2}):(?P<time_seconds>\d{2})\s+""" +
r"""(?P<time_offset>(?:\-|\+)\d{4})\]\s+""" +
r"""\"(?P<http_action>[a-zA-Z]+)\s+(?P<http_path>\S+)\s+(?P<http_protocol>\S+)\"\s+""" +
r"""(?P<status_code>\d+)\s+""" +
r"""(?P<bytes_sent>\d+)\s+""" +
@crscardellino
crscardellino / boot_ip_mailer.py
Last active March 21, 2017 23:19
Script to send IP address after boot
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import absolute_import, print_function, unicode_literals
import datetime
import smtplib
import subprocess
import sys
@crscardellino
crscardellino / slurm.sh
Last active September 28, 2017 02:15
Slurm job submit script
#!/bin/bash
### Lines "#SBATCH" configure the job resources
### (even though they look like bash comments)
### Job queue to use (options: batch)
#SBATCH --partition=batch
### Amount of nodes to use
#SBATCH --nodes=1
@crscardellino
crscardellino / maxjobs.sh
Last active April 21, 2017 14:48
Snippet to use for simple bash paralelism
#!/usr/bin/env bash
set -e
maxcores=${1:-6}
sleeptime=${2:-5}
function maxjobs {
while [ $(jobs | wc -l) -ge $maxcores ]
do
sleep $sleeptime
# -*- coding: utf-8 -*-
from __future__ import absolute_import, print_function, unicode_literals
import fnmatch
import os
def traverse_directory(path, file_pattern='*'):
for root, _, filenames in os.walk(path):
for filename in fnmatch.filter(filenames, file_pattern):
@crscardellino
crscardellino / check_process.py
Created December 19, 2016 18:11
Git to check a running process and send an email when finished
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import absolute_import, print_function, unicode_literals
import argparse
import os
import smtplib
import subprocess
import sys