Skip to content

Instantly share code, notes, and snippets.

View yashika51's full-sized avatar
💻
Learning by doing

Yashika Sharma yashika51

💻
Learning by doing
View GitHub Profile
@mgaitan
mgaitan / autofactory.py
Last active January 8, 2025 08:00
Automatically define factory boy recipes for dataclasses by inspecting the type annotations
## See https://github.com/FactoryBoy/factory_boy/issues/836
import inspect
from typing import List, get_args, get_origin
import factory
import factory.fuzzy
from dataclasses import dataclass, Field, MISSING, is_dataclass
from enum import Enum
from datetime import date, datetime
from decimal import Decimal
@cekstam
cekstam / gist:a7758b8f315835d479f379715eebd0c3
Last active October 4, 2024 16:46
create valid JSON from git log using python and ast.literal_string
git log -n 10\
--pretty=format:'{"commit": "%H", "author": "%aN <%aE>", "date": "%ai", "message": """%B""", "notes": """%N""" },' \
$@ | awk 'BEGIN { print("[") } { print($0) } END { print("]") }' | python -u -c \
'import ast,json,sys; print(json.dumps(ast.literal_eval(sys.stdin.read())))'
@esoergel
esoergel / staticmethod.md
Last active May 24, 2023 12:34
Brief explanation and example of python's `staticmethod` decorator

You ever factor something out of a method and realize you can get rid of the dependency on self (which is really nice to do for clarity and testability)?

In my experience, typically this is then pulled in to a function, but then you have to move the definition all the way outside of the class, which can suck.

To compensate for this, sometimes you'll leave it as a method and just not use self in the body. This is a good use case for the @staticmethod decorator, which I'll explain:

@pwenzel
pwenzel / git-log-to-tsv.sh
Created June 6, 2012 20:53
Git Log to Tab-Delimited CSV File
# Local Dates:
git log --date=local --pretty=format:"%h%x09%an%x09%ad%x09%s" > commits.local.tsv.txt
# ISO Dates:
git log --date=iso --pretty=format:"%h%x09%an%x09%ad%x09%s" > commits.iso.tsv.txt
@textarcana
textarcana / git-log2json.sh
Last active January 24, 2025 22:12
Convert Git logs to JSON. The first script (git-log2json.sh) is all you need, the other two files contain only optional bonus features 😀THIS GIST NOW HAS A FULL GIT REPO: https://github.com/context-driven-testing-toolkit/git-log2json
#!/usr/bin/env bash
# Use this one-liner to produce a JSON literal from the Git log:
git log \
--pretty=format:'{%n "commit": "%H",%n "author": "%aN <%aE>",%n "date": "%ad",%n "message": "%f"%n},' \
$@ | \
perl -pe 'BEGIN{print "["}; END{print "]\n"}' | \
perl -pe 's/},]/}]/'