Skip to content

Instantly share code, notes, and snippets.

View danielcs88's full-sized avatar

Daniel Cárdenas danielcs88

View GitHub Profile
@danielcs88
danielcs88 / beer_data_analysis.ipynb
Last active September 17, 2023 02:30
beer_data_analysis.ipynb
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@danielcs88
danielcs88 / sum_if_dates.md
Created August 9, 2023 23:18
SUMIF given comparison to TODAY()

Sum values in column B, given condition in all dates in column A

=sumif(A4:A1000,"<="&TODAY(),B4:B1000)

Link

@danielcs88
danielcs88 / black_clipboard.zsh
Last active August 22, 2023 22:32
Black Format Clipboard Code
# Instead of abusing black.vercel.app for over 3 years, I finally wrote a
# little utility to take clipboard Python code, format with Black, and
# finally copy formatted code to clipboard, and output using bat.
# add to a zsh file in ~/.oh-my-zsh/custom/
# and/or to .zshenv
# Required
# ========
#
@danielcs88
danielcs88 / col_matrix.py
Created January 20, 2023 02:05
Iterate through columns in a matrix (`list[list[int]]`) in standard Python
grid = [
[1, 3, 2, 5, 4, 6, 9, 8, 7],
[4, 6, 5, 8, 7, 9, 3, 2, 1],
[7, 9, 8, 2, 1, 3, 6, 5, 4],
[9, 2, 1, 4, 3, 5, 8, 7, 6],
[3, 5, 4, 7, 6, 8, 2, 1, 9],
[6, 8, 7, 1, 9, 2, 5, 4, 3],
[5, 7, 6, 9, 8, 1, 4, 3, 2],
[2, 4, 3, 6, 5, 7, 1, 9, 8],
[8, 1, 9, 3, 2, 4, 7, 6, 5],
@danielcs88
danielcs88 / pipe_several.py
Last active January 4, 2023 06:43
Pipe Function to several columns
# Instead of repeating yourself
df["started_at"] = pd.to_datetime(df["started_at")
df["ended_at"] = pd.to_datetime(df["ended_at"])
# Leverage the power of pipe
df.pipe(
lambda x: x.assign(
**{ # Apply same function to both columns in one go
col: pd.to_datetime(x[col], format="%Y-%m-%d %H:%M:%S")
for col in ["started_at", "ended_at"]
@danielcs88
danielcs88 / example.md
Last active December 4, 2022 03:59
Reverse Non-Unique Value Dictionary

Example:

example = {
    ("Rock", "Rock"): "Draw",
    ("Rock", "Paper"): "Win",
    ("Rock", "Scissors"): "Loss",
    ("Paper", "Rock"): "Loss",
    ("Paper", "Paper"): "Draw",
    ("Paper", "Scissors"): "Win",
@danielcs88
danielcs88 / sql_query.py
Created May 22, 2022 09:36
SQL queries within Pandas DataFrames
import re
import matplotlib.pyplot as plt
import pandas as pd
from sqlalchemy import create_engine
def sql_query(query: str) -> pd.DataFrame:
"""
Helper function to run SQL queries on in-house Pandas DataFrames
@danielcs88
danielcs88 / variables.txt
Last active May 8, 2022 00:22
Extended Description of Variables
╔═══════════╦═════════════════╦════════╦════════════════════════════════════════════════════════════════════════════════════╗
║ RNUM ║ QNAME ║ YEAR ║ DESCRIPTION ║
╠═══════════╬═════════════════╬════════╬════════════════════════════════════════════════════════════════════════════════════╣
║ R00001.00 ║ case_id ║ 1979 ║ ORIGINAL QUESTION NAME: CASEID ║
║ ║ ║ ║ ║
║ ║ ║ ║ NOTE: THIS NUMBER WAS ASSIGNED ACCORDING TO THE RECORD NUMBER OF EACH RESPONDENT ║
║ ║ ║ ║ ON THE TAPE. THE FIRST RESPONDENT WAS ASSIGNED ID#1, THE SECOND WAS ASSIGNED ║
║ ║ ║ ║ ID#2, ETC. ║
╠═══════════╬═══
@danielcs88
danielcs88 / espanso.md
Last active May 6, 2022 14:02
Espanso

Espanso

Instructions

  1. Install Espanso by downloading the file from here

    image

    ins

@danielcs88
danielcs88 / prism.css
Created April 4, 2022 03:16
Prism CSS
/* PrismJS 1.27.0
https://prismjs.com/download.html#themes=prism&languages=markup+css+clike+javascript+python */
code[class*=language-],pre[class*=language-]{color:#000;background:0 0;text-shadow:0 1px #fff;font-family:Consolas,Monaco,'Andale Mono','Ubuntu Mono',monospace;font-size:1em;text-align:left;white-space:pre;word-spacing:normal;word-break:normal;word-wrap:normal;line-height:1.5;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-hyphens:none;-moz-hyphens:none;-ms-hyphens:none;hyphens:none}code[class*=language-] ::-moz-selection,code[class*=language-]::-moz-selection,pre[class*=language-] ::-moz-selection,pre[class*=language-]::-moz-selection{text-shadow:none;background:#b3d4fc}code[class*=language-] ::selection,code[class*=language-]::selection,pre[class*=language-] ::selection,pre[class*=language-]::selection{text-shadow:none;background:#b3d4fc}@media print{code[class*=language-],pre[class*=language-]{text-shadow:none}}pre[class*=language-]{padding:1em;margin:.5em 0;overflow:auto}:not(pre)>code[class*=