Skip to content

Instantly share code, notes, and snippets.

View YordanGeorgiev's full-sized avatar

Yordan Georgiev YordanGeorgiev

View GitHub Profile
@YordanGeorgiev
YordanGeorgiev / try-catch.scala
Created April 3, 2018 11:53
[try-catch-construct-in-scala] how-to write a try catch constuct in scala #scala #try #catch
object MyFancyErrCode extends Enumeration {
type MyFanceErrCode = Value
val NO_FILE: Value = Value
val NO_DIR: Value = Value
}
case class MyFancyCustomException1(val errCode :MyFancyErrCode , msg: String) extends Exception(msg)
case class MyFancyCustomException2(val errCode :MyFancyErrCode , msg: String) extends Exception(msg)
case class TotallyUnknownException(msg: String) extends Exception(msg)
@YordanGeorgiev
YordanGeorgiev / count-char-number-of-occurence.pl
Created April 2, 2018 17:55
[count-char-number-of-occurence] how-to count the number of occurence of a char in a string with perl
# how-many forward or backward slashes are there
$rel_levels++ while ($relative_path =~ m/[\/\\]/g);
@YordanGeorgiev
YordanGeorgiev / generate-dummy-df.scala
Created March 29, 2018 16:42
[generate-dummy-dataframe] how-to generate dummy data frame in scala spark #scala #spark
def genDummyDf(): DataFrame = {
spark
.createDataFrame(
spark.sparkContext.parallelize(
Seq(
Row("foo")
)),
StructType(
Seq(
StructField("bar", StringType)
@YordanGeorgiev
YordanGeorgiev / list-files-by-modified-time.sh
Created March 29, 2018 06:20
[list-files-by-modified-time] how-to list all the files and dirs non-recursively sorted by their modified time #bash #linux #freeBSD #Unix #shell #stat
# how-to list all the files and dir in a dir sorted by their
# modified time in the different shells
# usually mac os / Unix / FreeBSD stat
stat -f "%Sm %N" -t "%Y-%m-%d %H:%M:%S" ~/opt/comp/proj/*|sort
# STDOUT output:
# 2018-03-27 15:41:13 ~/opt/comp/proj/foo
# 2018-03-28 14:04:11 ~/opt/comp/proj/bar
# GNU Utils ( usually on Linux ) stat
@YordanGeorgiev
YordanGeorgiev / backup-git-branch.sh
Last active March 29, 2018 16:40
[backup-current-git-branch] how-to backup my current git branch #bash #git #branch
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 | less
@YordanGeorgiev
YordanGeorgiev / loop-trough-integers-sequence.scala
Created March 28, 2018 06:42
[loop trough sequence of integers ] how-to loop trough sequence of integers in scala #scala #loop #integers
(1 to 100).foreach(n => {
println ( "n: " + n.toString() )
})
@YordanGeorgiev
YordanGeorgiev / HdfsPathUtils.scala
Created March 28, 2018 06:24
[hdfs-path-utils] small path utils for hdfs in spark #spark #scala #hdfs #path #file #dir
import org.apache.hadoop.fs.{FileSystem, Path}
trait HavingSparkSession {
implicit val spark: SparkSession = SparkSession.builder().getOrCreate()
}
object HdfsPathUtils extends HavingSparkSession {
def pathExists(path: String): Boolean = {
val spark: SparkSession = SparkSession.builder().getOrCreate()
val conf = spark.sparkContext.hadoopConfiguration
@YordanGeorgiev
YordanGeorgiev / logback.example.xml
Last active April 18, 2024 11:06
[minimal-logback.xml-example] how-to configure the logback.xml minimalistically #scala #xml #logback #logging #configuration
<!-- all you need to know about log levels src: https://i.stack.imgur.com/Z5mag.png -->
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<logger name="com.datastax.driver.core.QueryLogger.SLOW" level="DEBUG" />
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern> %d{yyyy-MM-dd HH:mm:ss.SSS} [%level] %msg %n</pattern>
</encoder>
</appender>
@YordanGeorgiev
YordanGeorgiev / convert-kebab-case-to-camel-case.pl
Last active March 24, 2018 17:38
[convert kebap case to camelCase] how-to convert kebab-case strings to camelCase strings in perl #perl # regex #kebab-case #camel-case
# str-kebab-case -> strKebapCase
$str =~ s/(?<=[^\W\-])\-([^\W\-])|([^\W\-]+)|\-/\U$1\L$2/g ;
@YordanGeorgiev
YordanGeorgiev / get-bash-script-full-file-path-universal.sh
Created March 24, 2018 16:30
[get-bash-script-full-file-path-universal] how-to get the full file path of a bash script universally #bash #perl #Linux #Unix #MacOS
# works on allmost any OS with perl ... because ... perl rulez !!!
script_dir=$(perl -e 'use File::Basename; use Cwd "abs_path"; print dirname(abs_path(@ARGV[0]));' -- "$0")