Skip to content

Instantly share code, notes, and snippets.

Avatar

Jeet Sukumaran jeetsukumaran

View GitHub Profile
@jeetsukumaran
jeetsukumaran / d.py
Created Jan 3, 2022
Simple Bare-Bones Data-as-Attributes Classes
View d.py
# "heavy" approach (can be useful if you want to derive
# and add simple behavior, e.g. validation etc.)
class Attributes:
def __init__(self, **kwargs):
# Alternatively:
# self.__dict__.update(kwargs)
for k, v in kwargs.items():
setattr(self, k, v)
# or otherwise:
View create-python-project.py
#! /usr/bin/env python
###############################################################################
##
## Copyright 2012 Jeet Sukumaran.
##
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Fountion; either version 3 of the License, or
## (at your option) any ler version.
View git-clone-subdir
#! /bin/bash
set -e -o pipefail
prog_name=$(basename ${0})
if [[ -z "$1" || -z "$2" ]]
then
echo "Usage: ${prog_name} <REPO> <SUBDIR> [<DEST>]"
exit 1
View conda-environment-name-bash-completion.bash
# Bash completion of conda environment names {{{3
#
# Triggered on:
# - ``conda activate <TAB>``
# - ``conda ... --clone <TAB>``
# - ``conda ... --name <TAB>``
#
# (C) 2021 Jeet Sukumaran
# (Free to use under the MIT License terms)
function _conda_env_complete() {
View llc-16color.sh
# Colorized ``ls``
#
# ``ls`` has native support for colorizing the entries themselves, which can
# be seen by running ``ls --color`` or ``ls --color=auto``, and this can be
# made standard by aliasing these to ``ls`` in your ``.bashrc.
#
# The colors of the file/directory entries themselves can be customized by
# adding the following in your ``~/.bashrc`` :
#
View tablefile.py
#! /usr/bin/env python
###############################################################################
##
## Copyright 2014 Jeet Sukumaran.
##
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 3 of the License, or
## (at your option) any later version.
View parsetexerr
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import re
import os
import pathlib
import sys
import argparse
import codecs
View fix-git-branch-names.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import pathlib
import sys
import argparse
import subprocess
"""
View fix-git-branch-name.sh
#! /bin/bash
# Fix your Git repo branch names.
# Free to use (at your own risk), and share/modify, as long
# as you are not a racist or a tedious "2-sides" bore.
set -x
set -e -o pipefail
git branch -m master main
git push
git push origin :master
git push --set-upstream origin main
View flattendirs
#! /usr/bin/env python3
################################################################################
# Copyright 2020 Jeet Sukumaran
#
# 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