Skip to content

Instantly share code, notes, and snippets.

View durgaswaroop's full-sized avatar
💭
Having Fun

Swaroop durgaswaroop

💭
Having Fun
View GitHub Profile
@krnd
krnd / .flake8
Last active August 23, 2023 12:11
python-flake8
# .flake8
#
# AUTHOR
# krnd
#
# VERSION
# 1.4
#
# SEE ALSO
# http://flake8.pycqa.org/en/latest/user/options.html
@durgaswaroop
durgaswaroop / JavaOptionalsReference.md
Last active October 5, 2023 12:00
Java Optional usage and Best practices
  • Optional.empty() - An empty optional
  • Optional.of(t) - returns a present Optional containing t. (t must be non-null)
  • Optional.ofNullable(t) - returns an Optional with t that can be null

Rules

  1. Never return null from a method that's supposed to return an optional. It defeats the purpose of Optional
  2. Never do opt.get() unless you can prove that the optional is present.
  3. Prefer alternatives to using opt.isPresent() followed by opt.get()
  4. It's generally a bad idea to create an Optional for the sole purpose of chaining methods from it to get a value.
  5. If an Optional chain is nested or has an intermediate result of Optional<Optional>, it is probably too complex.
@durgaswaroop
durgaswaroop / git_reference.md
Last active February 1, 2018 09:53
Useful Git Reference

Interactive Rebase

git rebase -i HEAD~3 // To pick three commits including HEAD. So, you get HEAD, HEAD^, HEAD^^

squash a commit ig you want to combine two commits as a single one.

Revert a file/folder to a commit

git checkout <commit_hash> -- <file/folder name>

Diff current version of file/folder with the version on another commit

@pgilad
pgilad / Instructions.md
Last active March 31, 2024 22:30
Git commit-msg hook to validate for jira issue or the word merge

Instructions

  • copy the file commit-msg to .git/hooks/commit-msg
  • make sure your delete the sample file .git/hooks/commit-msg.sample
  • Make commit msg executable. chmod +x .git/hooks/commit-msg
  • Edit commit-msg to better fit your development branch, commit regex and error message
  • Profit $$

Shell example

@masak
masak / explanation.md
Last active April 11, 2024 02:50
How is git commit sha1 formed

Ok, I geeked out, and this is probably more information than you need. But it completely answers the question. Sorry. ☺

Locally, I'm at this commit:

$ git show
commit d6cd1e2bd19e03a81132a23b2025920577f84e37
Author: jnthn <jnthn@jnthn.net>
Date:   Sun Apr 15 16:35:03 2012 +0200

When I added FIRST/NEXT/LAST, it was idiomatic but not quite so fast. This makes it faster. Another little bit of masak++'s program.