Thursday, September 30, 2021

Scala - Requests

Scala - Requests 


link:

https://index.scala-lang.org/com-lihaoyi/requests-scala/requests/0.6.9?target=_3.x


"com.lihaoyi" %% "requests" % "0.6.5" // sbt
compile "com.lihaoyi:requests_2.12:0.6.5" //gradle
val r = requests.get("https://api.github.com/users/lihaoyi")

r.statusCode
// 200

r.headers("content-type")

Saturday, September 11, 2021

Scala -Java : Convert String to Json

Scala -Java : Convert String to Json 

Code (Maven / https://mvnrepository.com/artifact/com.google.code.gson/gson):

import com.google.gson.{Gson, JsonParser}
val json="""{"hello": "world", "age": 42}"""
 val parser:JsonParser= new JsonParser();
val res= parser.parse(json).getAsJsonObject()
println(res.get("hello")) // world

//read from file
//val path="/path/file.json"
//val lines = scala.io.Source.fromFile(path, "utf-8").getLines.mkString

Code 2 (Requires Lift Web - Maven):

import net.liftweb.json._
import net.liftweb.Serialiazation.write
case class Address(city:String,Country:String)
case class Person(name:String ,address:Address)
implicits def formats=DefaultFormats
print(write(Person("Sam",Address("NY","US"))

python : Setup VS Code

 python : Setup VS Code

Steps:

  • Make sure VS code is installed
  • Install python extension from Microsoft
  • run this in shell

import sys 

for pth in sys.path:print(pth)

  • Goto > Preferences>Settings >users 
  • Search for Python  > Python Path >add path "/usr/lib/python39/python.exe"
  • At the bottom you should see the interpreter name

Pylint

  • Ctrl+shift+P
  • Search for Python:Select Linter
  • Choose pylint and enable