Skip to content

Instantly share code, notes, and snippets.

View j-thepac's full-sized avatar

Deepak j-thepac

View GitHub Profile
@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)
@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 / 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 / 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 / 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 / scala_rules.scala
Created December 15, 2021 16:57
Scala Rules
// They’re an idiomatic way of representing data using “ands” and “ors”. For example:
// a shape is a rectangle or a circle
// a rectangle has a width and a height
// a circle has a radius
// In ADT (Algebraic Data Types (ADTs))terminology, “and” types such as rectangle and circle are products,
// whereas the “or” types such as shape are coproducts.
// In Scala, we typically represent products using case classes and coproducts using sealed traits:
@j-thepac
j-thepac / Monad.scala
Created December 18, 2021 15:16
Monad and Functor
//https://medium.com/beingprofessional/understanding-functor-and-monad-with-a-bag-of-peanuts-8fa702b3f69e
object Monad extends App {
// Functor + unit+ Flatmap = Monad
case class Sugar(weight: Int)
case class Bag[A](content: A) {
def map[B](f: A => B): Bag[B] = Bag(f(content))
def flatMap[B](f: A => Bag[B]): Bag[B] = f(content)
}
@j-thepac
j-thepac / SimpleFunctor.scala
Last active December 18, 2021 15:20
SimpleFunctor
case class Bag[Int](a: Int) {
def map[Double](f: Int => Double): Bag[Double] = Bag(f(a))
}
val f = i:Int => i/1.0
Bag(10).map( i=> f(i))//result =Bag(10.0)
@j-thepac
j-thepac / cosmosapi.py
Created January 3, 2022 12:13
CosmosDB Api
"""
https://docs.microsoft.com/en-us/azure/cosmos-db/sql/create-sql-api-python
https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/cosmos/azure-cosmos/samples/examples.py
Pre-Req:
pip install --pre azure-cosmos
Have a Azure Account with Free Subscribption Enabled
Make sure Cosmosa DB is created along with DB and Container
#Azure portal > Azure Cosmos > ck on Existing Cosmos Db > Settings > Keys

Create Webapp using Flask

Azure App Service

Pre-Req

  • Make Sure u have setup account created for Azure
  • You have enabled Free Subscription
  • You have created a webapp instance manullay example "flaskserverpushparanimptest2"

Setup Env

$brew update && brew install azure-cli

$az upgrade