Skip to content

Instantly share code, notes, and snippets.

View tangoabcdelta's full-sized avatar

tangoabcdelta

View GitHub Profile
@tangoabcdelta
tangoabcdelta / git_hist_command.md
Last active October 31, 2023 05:10
Adding `git hist` alias that shows you the history of a directory or a file

To create a git hist alias in your Bash profile that:

  1. prints the history of the whole directory if no arguments are specified, and
  2. if a file or directory is specified, it shows the history of that,

you can add the following lines to your ~/.bash_profile or ~/.bashrc file:

# define a Bash function called git hist
git hist() {
@tangoabcdelta
tangoabcdelta / country.rank.md
Last active August 8, 2023 14:02
list of countries with the highest estimated number of civilian-owned guns
+----------+-----------------------+
|  Country | Estimated Gun Count   |
+----------+-----------------------+
| USA      | Over 390 million      |
| India    | Over 70 million       |
| China    | Around 50 million     |
| Pakistan | Over 20 million       |
| Russia   | Over 15 million       |
| Brazil | Over 15 million |
@tangoabcdelta
tangoabcdelta / Instr.md
Created July 31, 2023 12:24
git push origin eval(/the current branch i am on/)
  • Retrieves the name of the currently checked-out branch: git rev-parse --abbrev-ref HEAD
  • The HEAD keyword refers to the currently active commit
  • The param --abbrev-ref ensures that only the branch name (without the "refs/heads/" prefix) is returned.
  • Use the $(...) syntax to execute shell commands within the command line. $(...) is called command substitution in Bash.
  • This allows the output of the git rev-parse command to be used as an argument to git push origin.
  • Push the current branch to the remote named "origin":
git push origin $(git rev-parse --abbrev-ref HEAD)
@tangoabcdelta
tangoabcdelta / stock-count.js
Created July 31, 2023 05:39
Calculate how many more shares to buy to recoup losses
function calculateAdditionalStocks(initialStocks, initialPrice, currentPrice, targetPrice) {
const initialInvestment = initialStocks * initialPrice;
const currentHoldingValue = initialStocks * currentPrice;
const loss = initialInvestment - currentHoldingValue;
const additionalInvestmentNeeded = initialInvestment - targetPrice * initialStocks;
const additionalStocks = Math.ceil(additionalInvestmentNeeded / currentPrice);
return additionalStocks;
}
@tangoabcdelta
tangoabcdelta / checkout-all-repos.sh
Last active May 22, 2023 12:14
recursively checkout all folders
#!/bin/bash
# this file recursively traverse through each sub-folder inside the parent folder
# it performs the git actions e.g. stash, rebase from main and move on as specified
# it also waits for manual conflict resolution if necessary
# set permission for this file: chmod +x checkout-all-repos.sh
# execute the script: `./checkout-all-repos.sh`
@tangoabcdelta
tangoabcdelta / How to Debug a Node js app in a Docker Container.md
Created December 21, 2022 08:28
How to Debug a Node.js app in a Docker Container
@tangoabcdelta
tangoabcdelta / instructions.md
Created December 20, 2022 05:22
git-crypt: command not found error thrown while launching source tree
  • Go to SourceTree > Preferences > Git > Git Version (section)

  • Select "Reset to Embedded Git"

  • Note: Do not use the system version of git

  • Now you need to add path of git-crypt as a symlink

  • From https://jira.atlassian.com/browse/SRCTREE-2511 : The easiest solution would be to symlink git-crypt1 to the same location as your git` binary due to variations in how to configure (per major OS revision)

  • Locate your SourceTree installation directory

  • Locate the embedded git path. This is usually /Applications/Sourcetree.app/Contents/Resources/git_local/bin/

  • Run which git-crypt

@tangoabcdelta
tangoabcdelta / Run.IntelliJ.sh
Last active August 29, 2022 19:39
How to set path to $JAVA_HOME in environment variable correctly in Mac OS (new and old - zsh and bash, both)
# For newer Mac OS versions where zsh is the default terminal
$ nano ~/.zshenv
# For older Mac OS versions where bash is the default terminal
$ nano ~/.bash_profile
# add the following two entries in ~/.zshenv
export JAVA_HOME=$(/usr/libexec/java_home)
export PATH=/correct/path/to/apache-maven-3.8.6/bin:$PATH
@tangoabcdelta
tangoabcdelta / index.css
Created August 26, 2022 06:12
BarcodeDetector Experimental Web APIs
html, body {
background: #111;
color: white;
height: 100%;
}
canvas {
display: none;
height: auto;
object-fit: contain;
@tangoabcdelta
tangoabcdelta / another.example.of.prototype.replacement.js
Last active August 7, 2022 22:53
Pprototypal inheritance in JavaScript
function Person(name) {
this.name = name;
}
const a = new Person("a");
try {
console.log(a.getName()); // Output: TypeError: a.getName is not a function
} catch (e) {
console.error(e);