Skip to content

Instantly share code, notes, and snippets.

Avatar
👨‍💻
Trying to be an OSS contributor

Dinesh B dineshba

👨‍💻
Trying to be an OSS contributor
View GitHub Profile
View keybase.md

Keybase proof

I hereby claim:

  • I am dineshba on github.
  • I am dineshba (https://keybase.io/dineshba) on keybase.
  • I have a public key ASAV74ALoKc9qPC27Wsupaqr6xAXXG3PK9KF6SKaZePFyQo

To claim this, I am signing this object:

View command_line_app.yaml
Learning
- 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
View custom_aliases.sh
### 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
dineshba / show_commit.sh
Last active Mar 23, 2019
Display what the commit is made of. It will show the tree, blobs and the structure of it.
View show_commit.sh
# usage show_commit commit-sha
# usage show_commit HEAD
#!/bin/sh
show_tree() {
spacing=$2
printf "$spacing showing tree $1 \n"
for one in $(git cat-file -p $1 | awk '{printf $2"--"$3 "\n"}'); do
printf "$spacing $one \n"
done;
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) {
self.name = 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 !laptop.name.contains("Mac") })
.filter({laptop in laptop.fan != nil})
.map({laptop in laptop.fan!.name})
// Simplified
let fanNames = computerLab.laptops
.filter({laptop in !laptop.name.contains("Mac") })
.compactMap({laptop in laptop.fan?.name}) //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 laptop.name.contains("Mac") {
macLaptops.append(laptop)
You can’t perform that action at this time.