Skip to content

Instantly share code, notes, and snippets.

@amuradyan
amuradyan / filter_working_urls.py
Created November 19, 2023 11:43
FIltering broken links
import requests
def filter_working_urls(input_file_path, output_file_path):
"""
Reads URLs from a file, checks if they are working, and writes the working URLs into another file.
Also counts the number of working and broken URLs.
:param input_file_path: Path to the file containing the URLs.
:param output_file_path: Path to the file where working URLs will be written.
:return: Tuple (number of working URLs, number of broken URLs)
// See also: http://blog.higher-order.com/assets/trampolines.pdf
// Not stack-safe
def fib(n: Int): Int =
if n <= 1 then n
else fib(n - 1) + fib(n - 2)
fib(10)
// res0: Int = 55
// see: http://tpolecat.github.io/2015/04/29/f-bounds.html
// Inheritance
trait Pet:
def name: String
def renamed(newName: String): Pet
// This workds
const mitq = "Արժի մի հատ պռոեկտ սարքել, սաղ հայերեն տեքստերը վերցնել, վերջավորությունները ըղձական ապառնու փոխել ու տպել"
const poxac_mitq = mitq
.split(" ")
.reduce((masnaki_poxac_mitq, bar) => {
const poxac_bar = bar.replace("ել", "ած")
return `${masnaki_poxac_mitq} ${poxac_bar}`
})

weatherapi, among other things, provides a REST API for historical weather data. You need to look into the historical data of five days for a given city from a given date and calculate the average wind speed in meters per second, the average humidity and the average temperature in kelvins for each of these days.

Your application should provide and HTTP GET endpoint named stats, that should accept two parameters: the date in the format YYYY-MM-DD and the city name. The communication should be done via JSON.

For the HTTP server, you should use Akka HTTP. For the json parsing, you should use play-json. sbt should be used to build the application and scalatest to test it.

@amuradyan
amuradyan / ParserCombinators.worksheet.sc
Created May 2, 2022 21:53
Some code from "Parser Combinators: A Type-Driven Approach To Input ProcessiEOF by Bastien Louërat"
// https://www.signifytechnology.com/blog/2019/01/parser-combinators-a-type-driven-approach-to-input-processieof-by-bastien-louerat?source=google.com
sealed trait Parser[A]
case class Exactly(char: Char) extends Parser[Char]
val parserOfA: Parser[Char] = Exactly('a')
val parserOfB: Parser[Char] = Exactly('b')
sealed trait Error
// How to Write Controllable Futures in Scala | Rock the JVM
// https://www.youtube.com/watch?v=72kurKY7fX8
import scala.concurrent.Future
import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.Promise
val aFuture = Future {
42
}
@amuradyan
amuradyan / ChurchEncodings.worksheet.sc
Last active May 24, 2022 18:22
Some Church encodings
type Boolian = (Any, Any) => Any
val troo = (a: Any, _: Any) => a
val fols = (_: Any, b: Any) => b
// Logic
val not = (b: Boolian) => b(fols, troo)
not(troo) == fols
@amuradyan
amuradyan / BasicScala.sc
Last active November 6, 2021 10:31
Գրադարան Քեմփ - Ստեփանավան
// Purpose: show scala basic features in terms of grammar, readability, shortness, easy translation from human to machine
// How many of you know a programming language?
// Opening with the fizzbuzz
for (i <- Range.inclusive(1, 16)) {
println(
if (i % 3 == 0 && i % 5 == 0) "FizzBuzz"
else if (i % 3 == 0) "Fizz"
else if (i % 5 == 0) "Buzz"
else i
import scala.collection.mutable.Stack
class Peg(val disks: Stack[Int], val name: String)
def solveHanoi_1(n: Int): Unit = {
val A = Peg(Stack[Int](1 to n: _*), "A")
val B = Peg(Stack[Int](), "B")
val C = Peg(Stack[Int](), "C")
val evenSeq = Seq((A, B), (A, C), (B, C))