Skip to content

Instantly share code, notes, and snippets.

View nmcolome's full-sized avatar

Natalia Colomé nmcolome

View GitHub Profile
@nmcolome
nmcolome / commit-msg
Created April 27, 2023 00:51 — forked from wesbos/commit-msg
ESLint 3.0 Git Pre Commit Hook
#!/bin/bash
files=$(git diff --cached --name-only | grep '\.jsx\?$')
# Prevent ESLint help message if no files matched
if [[ $files = "" ]] ; then
exit 0
fi
failed=0
for file in ${files}; do
@nmcolome
nmcolome / remove_ignored.md
Last active July 30, 2020 03:13
Make Git 'forget' about a file that was tracked but now is ignored

When you want to be specific:

To remove a file

git rm --cached <file>

To remove a directory

git rm -r --cached <folder>

@nmcolome
nmcolome / python_environment_setup.md
Created June 25, 2020 19:16 — forked from wronk/python_environment_setup.md
Setting up your python development environment (with pyenv, virtualenv, and virtualenvwrapper)

Overview of Python Virtual Environments

This guide is targetted at intermediate or expert users who want low-level control over their Python environments.

When you're working on multiple coding projects, you might want a couple different version of Python and/or modules installed. This helps keep each workflow in its own sandbox instead of trying to juggle multiple projects (each with different dependencies) on your system's version of Python. The guide here covers one way to handle multiple Python versions and Python environments on your own (i.e., without a package manager like conda). See the Using the workflow section to view the end result.


h/t @sharkinsspatial for linking me to the perfect cartoon

@nmcolome
nmcolome / python_tests_dir_structure.md
Created May 24, 2020 06:07 — forked from tasdikrahman/python_tests_dir_structure.md
Typical Directory structure for python tests

A Typical directory structure for running tests using unittest

Ref : stackoverflow

The best solution in my opinion is to use the unittest [command line interface][1] which will add the directory to the sys.path so you don't have to (done in the TestLoader class).

For example for a directory structure like this:

new_project

├── antigravity.py

class Api::V1::ProfitAndLossController < ApplicationController
def index
render json: Sale.get_profit_and_loss, each_serializer: ProfitAndLossSerializer
end
end
class Client < ApplicationRecord
...
def self.get_top_customers
month = Sale.get_latest_month
Client.find_by_sql [
"WITH top_cust AS (
SELECT SUM(sales.amount) AS sales_17,
SUM(discounts.amount) AS discounts_17,
SUM(sales.amount) + SUM(discounts.amount) AS net_sales_17,
class DashboardSerializer < ActiveModel::Serializer
attributes :clusters,
:products,
:categories,
:net_sales_curr_year,
:segment_contribution,
:net_sales_prev_year,
:discounts_17
def net_sales_prev_year
WITH {subquery_name} AS (
{subquery_body}
)
SELECT ...
FROM {subquery_name}
WHERE ...
class Sale < ApplicationRecord
...
def self.get_latest_month
Sale.order(transaction_date: :desc)
.limit(1)
.pluck(:transaction_date)[0]
.month
end
end
class Sale < ApplicationRecord
...
def self.get_dashboard
month = get_latest_month
Sale.find_by_sql [
"WITH ytd_2017 AS (
SELECT SUM(sales.amount) AS sales_17,
SUM(discounts.amount) AS discounts_17,
client_clusters.name AS clusters,