Skip to content

Instantly share code, notes, and snippets.

View NirantK's full-sized avatar

Nirant NirantK

View GitHub Profile

FWIW: I didn't produce the content present here. I've just copy-pasted it from somewhere over the Internet, but I cannot remember exactly the original source. I was also not able to find the author's name, so I cannot give him/her the proper credit.


Effective Engineer - Notes

What's an Effective Engineer?

Jupyter Notebook Hacks

Better Mindset

  • IMPORTANT: Frequently rewrite each cell logic into functions. These functions can be moved to separate .py files on regular intervals. Your notebook run should be mainly function calls.
    • This would prevent your notebook from becoming a giant pudding of several global variables
  • If particular cells take too long to run, add %%time cell magic as a warning + runtime logger
  • If you are on Py3.6+, please use f-strings! f"This is iteration: {iter_number}"is much more readable than .format() syntax
  • Any code that is used in more than 3 notebooks should be moved to .py files (such as utils.py) and imported such as from xxx_imports import *
  • Quite often, we frequently re-run same code cell. Instead, refactor that cell to a function and call that function repeatedly to prevent accidental edits
@NirantK
NirantK / pascal_pandas.ipynb
Created March 27, 2018 01:15
A quick way to get the bounding boxes in fastai csv format ready for bounding box regression using Pandas.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
_fstring = f'Total: {one + two}' # Go f-string!
_format = 'Total: {}'.format(one + two)
_percent = 'Total: %s' % (one + two)
_concatenation = 'Total: ' + str(one + two)
assert _fstring == _format == _percent == _concatenation
# inline variables, similar to LaTeX
name = "Fred"
print(f"He said his name is {name}.")
# 'He said his name is Fred.'
# auto-resolve variable scope when nested
width = 10
precision = 4
value = decimal.Decimal("12.34567")
print(f"result: {value:{width}.{precision}}") # nested fields
# 'result: 12.35'
@NirantK
NirantK / f-string-demo-4.py
Last active August 28, 2020 07:57
f string Spacing Demo
correct = 'correct'
phonetic_correct = 'phonetic_correct'
typo = 'typo'
phonetic_typo = 'phonetic_typo'
phonetic_distance = 'phonetic_distance'
print(f'No Spacing:')
print(f'{correct}|{phonetic_correct}|{typo}|{phonetic_typo}|{phonetic_distance}|\n')
# No Spacing:
# correct|phonetic_correct|typo|phonetic_typo|phonetic_distance|
@NirantK
NirantK / f-strings-demo-5.py
Created April 16, 2018 11:59
fstring expression eval demo
items = list(range(0, 5)) # create list of 5 elements
print(items)
# [0, 1, 2, 3, 4]
print(f'number of items: {len(items)}')
# number of items: 5
@NirantK
NirantK / f-strings-demo-6.py
Last active July 4, 2023 10:54
lambda functions in f strings
# If you feel you must use lambdas, they may be used inside of parentheses:
print(f'{(lambda x: x*3)(3)}')
# '9'
# not that this returned a <str> and not <int>
@NirantK
NirantK / gopath
Last active September 9, 2019 08:01 — forked from austingebauer/gopath
Set GOPATH, GOBIN, and PATH in current directory
#!/usr/bin/env bash
#
# Sets the GOPATH and GOBIN to the current directory.
# Adds GOBIN to the PATH.
#
# Usage:
# 1. Put this script somewhere on your PATH.
# 2. Enter directory of a golang project (contains src, pkg, bin)
# 3. Execute: . gopath