Skip to content

Instantly share code, notes, and snippets.

View YordanGeorgiev's full-sized avatar

Yordan Georgiev YordanGeorgiev

View GitHub Profile
@YordanGeorgiev
YordanGeorgiev / git-checkout-basics.sh
Last active April 25, 2024 18:18
[git checkout basics] git checkout basics #git #checkout #git-checkout
# how-to checkout, aka start working on another branch
git checkout another-non-current-branch-name
# how-to checkout, aka start working on another branch and overwrite all changes !!!
git checkout another-non-current-branch-name --force
# how-to get a file from another branch ( herewith develop )
git checkout develop -- src/main/scala/com/company/path/to/class/CoolTrait.scala
# how-to get a file from another branch ( herewith develop ) and overwrite it
@YordanGeorgiev
YordanGeorgiev / git-stash-basics.sh
Created April 19, 2018 08:05
[git stash basics] git stash basics #git #stash #git-stash
# save your current working copy into the git stash
git stash
# check what there is in the git stash
git stash list
# how-to remove a stash item
git stash drop stash@{0}
# how-to pick a git stash
@YordanGeorgiev
YordanGeorgiev / simple-control-flow-example.dot
Last active May 4, 2018 10:44
[simple-graphviz-control-flow-example] how-to create a simple control flow diagram with GraphViz #graphviz #dot #control-flow #dia #
digraph {
label=" \n\n simplified workflow \n control flow diagram ";
edge[color=maroon,arrowsize=.7 ,len=2.0];
node[shape=box,style="filled,rounded",color=cornflowerblue,fontcolor=white, fontsize=12, fixedsize=true,width = 6.0, height = .75];
node[shape="diamond",style="filled",color=cornflowerblue,fontcolor=white, fontsize=12,fixedsize=true,width = 7.0, height = .75 ];
node[shape="circle", style="filled,rounded",color=cornflowerblue,fontcolor=white, fontsize=12, fixedsize=true,width = 1.25 ];
start_workflow[shape="circle",label="start the \n workflow"];
landing_dir[shape="box", label=" scan the \n landing dir "];
workflow_stop_on_conf_error[shape="circle", label="workflow stop"];
@YordanGeorgiev
YordanGeorgiev / squash-feature-branch.sh
Last active April 27, 2018 11:06
[squash-feature-branch-into-develop] how-to squash your feature branch into develop #git #squash #feature-branch #devops
# how-to rebase your feature branch into develop quickly
# check the status
git status
# check the git log
git log --pretty --format='%h %ai %<(15)%an ::: %s'
# set your current branch , make a backup of it , caveat minute precision
curr_branch=$(git rev-parse --abbrev-ref HEAD); git branch "$curr_branch"--$(date "+%Y%m%d_%H%M"); git branch -a | grep $curr_branch | sort -nr
@YordanGeorgiev
YordanGeorgiev / scala-exceptions-handling.scala
Last active April 17, 2018 00:07
[throw-more-than-1-exception-at-once] how-to throw and handle more than 1 exceptions at once #scala #exceptions
try {
throw new CustomValidationException1( CustomErrorCode.STUPID_FAIL_1
"could be throw new CustomValidationException2")
} catch {
case e
if (e.isInstanceOf[CustomValidationException1] || e
.isInstanceOf[CustomValidationException2]) => {
// run a common handling for the both custom exceptions
println(e.getMessage)
println(e.errorCode.toString) // an example of common behaviour
@YordanGeorgiev
YordanGeorgiev / git-pre-push.sh
Last active April 16, 2018 16:27
[git-pre-push] a sample git pre-push hook #git
#!/usr/bin/env bash
set +x
echo "checking for own todo left-overs ... "$(grep -ri 'todo:ygeorgie' . | grep -v 'pre-commit' | wc -l)" found."
grep -rnHi 'todo:ygeorgie' . | grep -v 'pre-commit'
sleep 2
set -e
echo "running scalafmt tasks ..."
@YordanGeorgiev
YordanGeorgiev / credential.scala
Last active January 15, 2019 08:53
[sbt credentials file] sbt credentials files #scala #sbt #credentials
realm=Artifactory Realm
host=company-artifactory.net
user=cuser
password=cpwd
// eof file /Users/phz/.ivy2/credential
// check also the following file: ~/.sbt/0.13/credentials.sbt
@YordanGeorgiev
YordanGeorgiev / copy-file-in-spark.scala
Last active April 17, 2018 14:21
[copy or move files in hadoop fs with spark] how-to copy or move files in hadoop fs with scala spark #scala #spark #file #copy #move
import org.apache.hadoop.fs.{FileAlreadyExistsException, FileSystem, FileUtil, Path}
val srcFileSystem: FileSystem = FileSystemUtil
.apply(spark.sparkContext.hadoopConfiguration)
.getFileSystem(sourceFile)
val dstFileSystem: FileSystem = FileSystemUtil
.apply(spark.sparkContext.hadoopConfiguration)
.getFileSystem(sourceFile)
FileUtil.copy(
@YordanGeorgiev
YordanGeorgiev / build.sbt.scala
Last active April 25, 2019 11:33
[build.sbt example for spark proj] how-to define build.sbt for a spark project #spark #scala #build.sbt #sbt
// add some stats for each test
testOptions in Test += Tests.Argument(TestFrameworks.ScalaTest, "-oD")
// might or might not suits your reqs
fork in Test := true
// might or might not suit your reqs
parallelExecution in Test := false
// the verbosity level after issuing the sbt test command
@YordanGeorgiev
YordanGeorgiev / fall-trough-random-cases.scala
Created April 4, 2018 11:33
[fall-trough-random-cases] how-to fall trough random cases with match in scala #scala #match #case #fall-trough
// pick randomly a file type to generate a valid dataframe for
val random = math.random
val randomType : RandomType = {
random match {
case a if (random >= 0 && random < 0.33) => {
RandomType.Type1
}
case b if (random >= 0.33 && random < 0.66) => {
RandomType.Type2
}