Skip to content

Instantly share code, notes, and snippets.

Trying to be an OSS contributor

Dinesh B dineshba

Trying to be an OSS contributor
View GitHub Profile

Keybase proof

I hereby claim:

  • I am dineshba on github.
  • I am dineshba ( on keybase.
  • I have a public key ASAV74ALoKc9qPC27Wsupaqr6xAXXG3PK9KF6SKaZePFyQo

To claim this, I am signing this object:

View command_line_app.yaml
- Technical
- Use stderr and stdout properly (60% content for this 5w1h) (why do we need stderr, redirection, identify)
- Use feature toggles
- Write modular code in pkg dir so that anybody can import and use it (Eg helm, kubectl)
- Easy dev setup (Makefile)
- Logging at different log level (--debug flag)
- 12 factor app (file, env, flag)
- hyperfine for benchmark
- NonTechnical
### custom shell prompt ###
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
PS1='\[\e[31;47m\]$(kubectl config current-context)\[\e[m\]\[\e[36;47m\]$(kubectl config view --minify --output 'jsonpath={..namespace}')\[\e[m\]\w\[\033[32m\]$(parse_git_branch)\[\033[00m\] \$ '
### cd dir interactively ###
alias godir='cd $(find ~/projects -type d -maxdepth 2 | fzf)'
### load tmux session interactively ###
dineshba /
Last active Mar 23, 2019
Display what the commit is made of. It will show the tree, blobs and the structure of it.
# usage show_commit commit-sha
# usage show_commit HEAD
show_tree() {
printf "$spacing showing tree $1 \n"
for one in $(git cat-file -p $1 | awk '{printf $2"--"$3 "\n"}'); do
printf "$spacing $one \n"
View if_let.swift
var optionalValue: Int?
if let value = optionalValue { // unwraps optionalValue and assigns
// it to variable named value
print(value) // type of value = Int
else {
print("not able to unwrap optionalValue as it is nil")
//Let's rewrite the sum function using if-let
func sum(_ optionalAugend: Int?, _ optionalAddend: Int?) -> Int? {
View protocol_example.swift
struct Cherry: Eatable {
var taste: Taste = Taste.sweet
func isBitter() -> Bool {
return self.taste == .bitter
let 🍒 = Cherry() // literally we can have variable name like this🤓
struct Chilly: Eatable {
var taste: Taste = Taste.spicy
View class.swift
class Dog {
var name: String
var weight: Int
// constructor or initializer
init(name: String, weight: Int) { = name
self.weight = weight
View smart_casting.swift
var anyValue: Any // If we don't know the type at compile time,
// we can use `Any`. It is mostly used for data
// coming from network which can be type casted as below.
anyValue = "string value" // assinging string value
anyValue is String // true
// type checking using `is` operator
if let stringValue = anyValue as? String { // if anyValue is castable to String, it will
print(stringValue.uppercased()) // store in stringValue and enter into `if-let`
View closure_example.swift
let fanNames = computerLab.laptops
.filter({laptop in !"Mac") })
.filter({laptop in != nil})
.map({laptop in!.name})
// Simplified
let fanNames = computerLab.laptops
.filter({laptop in !"Mac") })
.compactMap({laptop in}) //compactMap will filter out nil values by default
View closure.swift
struct ComputerLab { // Computer Lab contains list of laptops.
let laptops: [Laptop]
// we want to get the list of mac laptops
// Traditional way
var macLaptops: [Laptop] = []
for laptop in computerLab.laptops {
if"Mac") {
You can’t perform that action at this time.