Skip to content

Instantly share code, notes, and snippets.

View shvahabi's full-sized avatar
🎯
Focusing

Shahed shvahabi

🎯
Focusing
  • Earth
View GitHub Profile
@shvahabi
shvahabi / README.md
Created December 13, 2025 06:42 — forked from armamini/README.md
Implement a reliable connection over Websocket via Cloudflare Workers

ساخت با Cloudflare Workers

این راهنما به شما کمک می‌کند تا بدون هزینه و سرور مجازی، یک فیلترشکن شخصی با سرعت بالا و پینگ مناسب روی زیرساخت کلادفلر بسازید. (V2Ray over Websocket)


📋 پیش‌نیازها

  1. اکانت Cloudflare: نیاز به یک ایمیل (شخصی یا موقت) دارید.
  2. کد اسکریپت: کدی که باید در ورکر قرار دهید (موجود در فایل‌های این مخزن).
  3. UUID: یک کد یکتا که به عنوان رمز عبور عمل می‌کند.
@shvahabi
shvahabi / gist:77fbea90b1fae300bb40dc7d89f5e8ae
Last active October 1, 2025 22:07
Lisp-like Programming in Scala
// lambda-calculus-like
((x: Int, y: Int) => (x + y))(2, 3)
// partial application
((x: Int) => (y: Int) => (x + y))(2)(3)
@shvahabi
shvahabi / grpdAvg
Created June 10, 2025 23:47
This script receives a filename which includes a list of numbers then calculates averages of groups of those numbers grouped by the second argumant given as a varargs of numbers
#!/usr/bin/env -S scala-cli shebang
//> using scala 3.7.1
//> using jvm graalvm-java23:23.0.1
//> using toolkit default
import os.*
val fileName = args(args.indexWhere(_ == "--fileName") + 1)
val others = args.filterNot(x => (x == fileName || x == "--fileName"))
val groupings: Array[Int] = others.filterNot(_ == "--groupedBy").map(_.toInt)
@shvahabi
shvahabi / unseq.sc
Created July 16, 2024 12:11
unpacking sequences
val a = Set(List(1, 2, 3)*)
println(a)
// Set(1, 2, 3)
// val a: Set[Int] = Set(1, 2, 3)
val b = List(1, 2, 3).toSet
println(b)
// val b: Set[Int] = Set(1, 2, 3)
assert(a == b)
@shvahabi
shvahabi / stringInterpolationReverseMatching.scala
Created May 2, 2023 00:21
string interpolation reverse matching
case class Person(name: String, age: Int)
val shahed = """{"name": "Shahed", "age": 42}""" match { case s"""{"name": $name, "age": $age}""" => Person(name, age.toInt) }
// val shahed: Person = Person("Shahed",42)
@shvahabi
shvahabi / contextualFunctionExample.scala
Created April 30, 2023 21:15
An example of a contextual function
@main def hello: Unit =
given msg: Int = 123
val greet: Int ?=> String = s"Hello ${summon[Int]}!"
println(greet)
@shvahabi
shvahabi / randomString.scala
Created April 17, 2023 13:04
generate random string of desired length excluding some characters
def randomStringOfLength(length: Int): String =
scala.util.Random(java.time.Instant.now().toEpochMilli)
.alphanumeric
.filterNot("0oO1Il".toList.contains(_))
.take(length)
.mkString
@shvahabi
shvahabi / nested case class pattern matching.scala
Last active September 5, 2022 20:22
Pattern matching on Scala case classes naturally goes deep nested
/**
* https://gist.github.com/shvahabi/c1eb3378bdaef6cc9aacb51897217871
*/
/**
* pattern matching on Scala case classes naturally goes deep nested
*/
case class FirstName(string: String)
case class LastName(string: String)
import java.time._
import java.time.format.DateTimeFormatter
val formatter = DateTimeFormatter.ofPattern("uuuu/MM/dd HH:mm:ss.n X")
val time = Instant.now.atOffset(ZoneOffset.ofHoursMinutes(0, 30)).format(formatter)
println(time)
@main def hello(args: String*) =
println(s"Hello ${args.lift(0).getOrElse("world")}!")