Skip to content

Instantly share code, notes, and snippets.

@althonos
althonos / setup.cfg
Last active March 4, 2024 18:08
A `setup.cfg` template for my Python projects
# https://gist.github.com/althonos/6914b896789d3f2078d1e6237642c35c
[metadata]
name = {name}
version = file: {name}/_version.txt
author = Martin Larralde
author_email = martin.larralde@embl.de
url = https://github.com/althonos/{name}
description = {description}
long_description = file: README.md
@kxzk
kxzk / dask_read.py
Last active March 29, 2022 18:26
reading in multiple csv in dask
import dask.dataframe as dd
df = dd.read_csv('*.csv')
@jonathan-kosgei
jonathan-kosgei / timer.py
Last active June 14, 2021 05:01
Python Decorator to Time a Function
""" A simple decorator that times the duration of a function's execution. More info on Decorators at https://pythonconquerstheuniverse.wordpress.com/2009/08/06/introduction-to-python-decorators-part-1/"""
import timeit
def timer(function):
def new_function():
start_time = timeit.default_timer()
function()
elapsed = timeit.default_timer() - start_time
print('Function "{name}" took {time} seconds to complete.'.format(name=function.__name__, time=elapsed))
return new_function()
@sdasgup3
sdasgup3 / infonum.py
Created November 2, 2017 03:14
Decimal-Hexadecimal-2's complement Binary Calculator
#!/usr/bin/python
##############################################################################################################
# Extract information about a number. #
# #
# Example Usage: python infonum.py --bit 4 0xf #
# Output: #
# Base 10: -1 #
# Base 16: f #
# 2's Compliment binary: 1111 #
@bradmontgomery
bradmontgomery / LICENSE.txt
Last active December 1, 2023 21:01
A python decorator that logs execution time.
Copyright 2020 Brad Montgomery
Permission is hereby granted, free of charge, to any person obtaining a copy of this software
and associated documentation files (the "Software"), to deal in the Software without restriction,
including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial
portions of the Software.
@nipunsadvilkar
nipunsadvilkar / Different_style_guide_python.md
Last active March 20, 2024 22:39
What is the standard Python docstring format?

Formats

Python docstrings can be written following several formats as the other posts showed. However the default Sphinx docstring format was not mentioned and is based on reStructuredText (reST). You can get some information about the main formats in that tuto.

Note that the reST is recommended by the PEP 287

There follows the main used formats for docstrings.

- Epytext

@natemcmaster
natemcmaster / zip2tgz.sh
Last active October 27, 2023 21:44
Convert zip to tar.gz file
#!/usr/bin/env bash
if [[ $# < 2 ]]; then
echo "Usage: [src] [dest]"
exit 1
fi
function realpath() {
[[ $1 = /* ]] && echo "$1" || echo "$PWD/${1#./}"
}
@mivade
mivade / cli.py
Last active January 18, 2024 07:51
Using a decorator to simplify subcommand creation with argparse
"""This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.
In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
# Select rows with first name Antonio, # and all columns between 'city' and 'email'
data.loc[data['first_name'] == 'Antonio', 'city':'email']
# Select rows where the email column ends with 'hotmail.com', include all columns
data.loc[data['email'].str.endswith("hotmail.com")]
# Select rows with last_name equal to some values, all columns
data.loc[data['first_name'].isin(['France', 'Tyisha', 'Eric'])]
@prschmid
prschmid / open_sftp.py
Last active January 27, 2023 08:35
python open_sftp() context manager for sftp read and writing of files with similar behavior to open()
from contextlib import contextmanager
from urlparse import urlparse
from paramiko import AuthenticationException
import pysftp
@contextmanager
def open_sftp(url, mode='r', n_retries=5, retry_sleep_time=5):
"""Context manager to read/write a file via SFTP