Skip to content

Instantly share code, notes, and snippets.

@j-thepac
j-thepac / node.js
Last active November 20, 2021 13:27
Node js
/*
Nodejs is javascript engine from Chrome V8 Engine .
Which runs javascript code in the backend
node js is non blocking io module ie., if any lines takes more time , than the cpu does not block other lines and continues execution of other lines
npm - package manager for js .Similar to pip in python
Note: Never push node module dependencies to Git as it is huge
docs: all functions in npm is
- https://nodejs.org/dist/latest-v17.x/docs/api/
- https://nodejs.dev/learn/introduction-to-nodejs
@j-thepac
j-thepac / dataframejson.scla
Created November 11, 2021 04:55
Convert Spark Dataframe Columns to json
import org.apache.spark.sql.SparkSession
import org.apache.spark.sql.functions._
val spark=SparkSession
.builder()
.master("local")
.appName("local")
.getOrCreate()
import spark.implicits._
@j-thepac
j-thepac / scalaDomainPartialFunction.scala
Created November 8, 2021 04:58
scalaDomainPartialFunction
trait Activities
case class PersonWalk(km:Float) extends Activities
case class PersonTalk(words:String) extends Activities
class CompanionPerson {
val perform:PartialFunction[Activities,Unit]= {
case PersonWalk(km) => println(km)
@j-thepac
j-thepac / domaintrait.scala
Created November 8, 2021 04:57
Scala Domain Model using Traits
trait Activities
case class PersonWalk(km:Float) extends Activities
case class PersonTalk(words:String) extends Activities
class CompanionPerson {
def perform(act:Activities)= {
act match{
case PersonWalk(km) => println(km)
case PersonTalk(words) => println(words)
@j-thepac
j-thepac / json.py
Last active November 8, 2021 03:16
Json Marshall in python
class Person:
def __init__(self,name):
self.name=name
import json #yaml
v='{"name":"deepak"}'
j=json.loads(v)
person=Person(**j)