Skip to content

Instantly share code, notes, and snippets.

View arthuralvim's full-sized avatar

Arthur Alvim arthuralvim

View GitHub Profile
@bblanchon
bblanchon / example.py
Created April 9, 2021 09:03
Django Subquery Aggregate (Count, Sum...)
from django.db.models import OuterRef
weapons = Weapon.objects.filter(unit__player_id=OuterRef('id'))
units = Unit.objects.filter(player_id=OuterRef('id'))
qs = Player.objects.annotate(weapon_count=SubqueryCount(weapons),
rarity_sum=SubquerySum(units, 'rarity'))
@liorshk
liorshk / mlflow_gridsearch.py
Created April 22, 2020 15:24
Create MLFlow runs with Sklearn Gridsearch object
def log_run(gridsearch: sklearn.GridSearchCV, experiment_name: str, model_name: str, run_index: int, conda_env, tags={}):
"""Logging of cross validation results to mlflow tracking server
Args:
experiment_name (str): experiment name
model_name (str): Name of the model
run_index (int): Index of the run (in Gridsearch)
conda_env (str): A dictionary that describes the conda environment (MLFlow Format)
tags (dict): Dictionary of extra data and tags (usually features)
@gbzarelli
gbzarelli / test_mock_input.py
Last active December 6, 2023 19:20
Python - Mock input() method
from unittest.mock import patch
@patch('builtins.input', lambda _: 'y') # <- value to be returned by input method
def test_should_be_the_correct_value(self):
# replace with your class or method to be tested:
value = input('enter with a value')
assert value == 'y'
@stettix
stettix / things-i-believe.md
Last active March 20, 2024 17:45
Things I believe

Things I believe

This is a collection of the things I believe about software development. I have worked for years building backend and data processing systems, so read the below within that context.

Agree? Disagree? Feel free to let me know at @JanStette. See also my blog at www.janvsmachine.net.

Fundamentals

Keep it simple, stupid. You ain't gonna need it.

@lucianoratamero
lucianoratamero / README.md
Last active April 2, 2023 15:37
neovim configs - put inside ~/.config/nvim/
@tuantranf
tuantranf / mock_multiprocess_pool.md
Last active January 2, 2023 22:41
mocking multiprocess pool for unittest

Mocking multiprocess pool apply_async method

It seems python multiprocessing interface relies on pickling, and mock library and pickling don't go well together.

write mock of multiprocess class for pytest

module code

pool = Pool(cpu_count())
pool.apply_async(func=myfunc)
@berinhard
berinhard / setup-foxdot-processing.md
Last active November 9, 2023 09:34
Setup de Algorave com Pythonn
@moayadhani
moayadhani / GetGmailEmails.gs
Last active March 7, 2024 21:05
Get Gmail Emails By Assigned Label
var ui = SpreadsheetApp.getUi();
function onOpen(e){
ui.createMenu("Gmail Manager").addItem("Get Emails by Label", "getGmailEmails").addToUi();
}
function getGmailEmails(){
var input = ui.prompt('Label Name', 'Enter the label name that is assigned to your emails:', Browser.Buttons.OK_CANCEL);
version: '3'
services:
mongo-express:
image: mongo-express
ports:
- 8081:8081
environment:
ME_CONFIG_BASICAUTH_USERNAME: renatogroffe
ME_CONFIG_BASICAUTH_PASSWORD: MongoExpress2019!
@nivleshc
nivleshc / ansible-aws-inventory-worker.yml
Created April 12, 2019 03:46
Ansible Inventory Worker file. This is the file which actually carries out all the inventory tasks. It is called by the main file
# Name: ansible-aws-inventory-worker.yml
# Description: this is the worker file that called the main file (ansible-aws-inventory-main.yml) to to create an inventory of all the
# specific aws resources. This file, the worker file and the ansible inventory file must be placed in the same folder
# Prerequisites:
# - the worker file (ansible-aws-inventory-worker.yml) and the ansible hosts file must be present in the same folder as this file (ansible-aws-inventory-main.yml)
# - this script requires read access to all resources it will be querying. An AWS IAM user account must be created with the necessary permissions and with access keys enabled.
# At a minimum, to query all the resources mentioned above, the following permissions are required
# - AmazonVPCReadOnlyAccess
# - AmazonEC2ReadOnlyAccess
# - ElasticLoadBalancingReadOnly