Skip to content

Instantly share code, notes, and snippets.

View jaumebonet's full-sized avatar

Jaume Bonet jaumebonet

  • Lausanne, Switzerland
View GitHub Profile
@hectorcanto
hectorcanto / Makefile
Created November 11, 2020 11:56
A curated Makefile for a Python repository, with commands for using several code quality and security tools like Pylint, Flake, Bandit, Trivy ... Assumes everything is installed, a full demo repo is pending (it is a promise)
# https://misc.flogisoft.com/bash/tip_colors_and_formatting
RED="\\e[91m"
GREEN="\\e[32m"
BLUE="\\e[94m"
YELLOW="\\e[33m"
REGULAR="\\e[39m"
REPORTS=".coverage-reports"
SRC="app"
VERSION=$(shell cat ${SRC}/__init__.py | head -n 1 | cut -d" " -f 3 | tr -d "'")
@Kautenja
Kautenja / sftp_pandas.py
Last active January 6, 2023 04:39
Functions for working with remote files using pandas and paramiko (SFTP/SSH).
"""Functions for working with remote files using pandas and paramiko (SFTP/SSH)."""
import pandas as pd
import paramiko
def read_csv_sftp(hostname: str, username: str, remotepath: str, *args, **kwargs) -> pd.DataFrame:
"""
Read a file from a remote host using SFTP over SSH.
Args:
@Mlawrence95
Mlawrence95 / confusion_matrix.py
Last active March 26, 2024 10:25
Python: create a confusion matrix across two columns in a Pandas dataframe having only categorical data
import pandas as pd
def confusion_matrix(df: pd.DataFrame, col1: str, col2: str):
"""
Given a dataframe with at least
two categorical columns, create a
confusion matrix of the count of the columns
cross-counts
use like:
@stanchan
stanchan / mutually_exclusive_options.py
Created March 17, 2017 00:01
Python Click Mutually Exclusive Options
from click import command, option, Option, UsageError
class MutuallyExclusiveOption(Option):
def __init__(self, *args, **kwargs):
self.mutually_exclusive = set(kwargs.pop('mutually_exclusive', []))
help = kwargs.get('help', '')
if self.mutually_exclusive:
ex_str = ', '.join(self.mutually_exclusive)
kwargs['help'] = help + (
' NOTE: This argument is mutually exclusive with '
@5agado
5agado / Pandas and Seaborn.ipynb
Created February 20, 2017 13:33
Data Manipulation and Visualization with Pandas and Seaborn — A Practical Introduction
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@stucka
stucka / pipreplace.sh
Last active November 23, 2022 02:50
Force pip to reinstall all Python packages (works great with https://gist.github.com/stucka/0ced1cc71e1a5c374a18874471636d69)
#!/bin/bash
apt-get install libxml2-dev libssl-dev libffi-dev libxslt1-dev python-dev libjpeg-dev
pip freeze --local >pipfreeze.txt
tr '\n' ' ' < pipfreeze.txt >pipfreeze2.txt
pip install --upgrade --force-reinstall `cat pipfreeze2.txt`
@taoyuan
taoyuan / npm-using-https-for-git.sh
Last active June 25, 2024 16:25
Force git to use https:// instead of git://
# npm using https for git
git config --global url."https://github.com/".insteadOf git@github.com:
git config --global url."https://".insteadOf git://
# npm using git for https
git config --global url."git@github.com:".insteadOf https://github.com/
git config --global url."git://".insteadOf https://
@yoavram
yoavram / .travis.yml
Last active June 7, 2019 11:30
Build and deploy conda packages to Anaconda.org from Travis-CI
language: python
python:
- 2.7
- 3.4
# Setup anaconda
before_install:
- wget http://repo.continuum.io/miniconda/Miniconda-latest-Linux-x86_64.sh -O miniconda.sh
- chmod +x miniconda.sh
- ./miniconda.sh -b
@kevinelliott
kevinelliott / osx-10.11-setup.md
Last active April 10, 2022 15:47
Mac OS X 10.11 El Capitan Setup

Mac OS X 10.11 El Capitan

Custom recipe to get OS X 10.11 El Capitan running from scratch, setup applications and developer environment. This is very similar (and currently mostly the same) as my 10.10 Yosemite setup recipe (as found on this gist https://gist.github.com/kevinelliott/0726211d17020a6abc1f). Note that I expect this to change significantly as I install El Capitan several times.

I use this gist to keep track of the important software and steps required to have a functioning system after a semi-annual fresh install. On average, I reinstall each computer from scratch every 6 months, and I do not perform upgrades between distros.

This keeps the system performing at top speeds, clean of trojans, spyware, and ensures that I maintain good organizational practices for my content and backups. I highly recommend this.

You are encouraged to fork this and modify it to your heart's content to match your own needs.

@jlln
jlln / separator.py
Last active November 9, 2023 19:59
Efficiently split Pandas Dataframe cells containing lists into multiple rows, duplicating the other column's values.
def splitDataFrameList(df,target_column,separator):
''' df = dataframe to split,
target_column = the column containing the values to split
separator = the symbol used to perform the split
returns: a dataframe with each entry for the target column separated, with each element moved into a new row.
The values in the other columns are duplicated across the newly divided rows.
'''
def splitListToRows(row,row_accumulator,target_column,separator):
split_row = row[target_column].split(separator)