Skip to content

Instantly share code, notes, and snippets.

View GibsonRuitiari's full-sized avatar
🤯

Ruitiari GibsonRuitiari

🤯
View GitHub Profile
@GibsonRuitiari
GibsonRuitiari / SQLAST.kt
Created February 15, 2025 15:34
Complete Kotlin-classes representation of our SQL Grammar.
sealed class SqlStatement
// Select statement
data class Select(
val selectList: SelectList,
val from: TableReference,
val where: Condition? = null,
val groupBy: GroupBy? = null,
val orderBy: OrderBy? = null,
val limit: Limit? = null
@GibsonRuitiari
GibsonRuitiari / complete_sql.bnf
Created February 15, 2025 14:15
Complete sql grammar rules for the SQL Compiler and Engine KBA series
<sql_statement> ::= <select> | <insert> | <update> | <delete> // the full sql statement
<select> ::= "SELECT" <select_list> "FROM" <table_reference> ["WHERE <condition>"] ["GROUP BY" <column_list>] ["ORDER BY" <order_list> [<order_by_option>]] ["LIMIT" <number>] // select * from users where age > 12 or select name,age from users order by name ASC
<insert> ::= "INSERT INTO" <identifier> "("<column_list>")" "VALUES" "(" <value_list> ")" // insert into users (name,age) values ('John', 12)
<update> ::= "UPDATE" <identifier> "SET" <column_assignment> ["WHERE" <condition>] // update users set name='Alice' where id=1
<delete> ::= "DELETE FROM" <identifier> ["WHERE" <condition>] // delete from users where age=12
<table_reference> ::= <identifier> ["JOIN" <identifier> "ON" <condition>] // items or items JOIN orders ON users.id=orders.user_id
<select_list> ::= "*"| <column_list> // * name or * name,age,gender
<column_list> ::= <identifier>{","<identifier>} // name or name,age or name,age,gender
<order_by_option>::= "AS
sealed class SqlStatement
// SELECT statement
data class Select(
val selectList: SelectList,
val tableReference: TableReference,
val whereCondition: Condition? = null,
val groupBy: ColumnList? = null,
val orderBy: OrderList? = null,
val orderByOption: OrderByOption? = null,
<sql_statement> ::= <select> | <insert> | <update> | <delete> // the full sql statement
<select> ::= "SELECT" <select_list> "FROM" <table_reference> ["WHERE <condition>"] ["GROUP BY" <column_list>] ["ORDER BY" <order_list> [<order_by_option>]] ["LIMIT" <number>] // select * from users where age > 12 or select name,age from users order by name ASC
<insert> ::= "INSERT INTO" <identifier> "("<column_list>")" "VALUES" "(" <value_list> ")" // insert into users (name,age) values ('John', 12)
<update> ::= "UPDATE" <identifier> "SET" <column_assignment> ["WHERE" <condition>] // update users set name='Alice' where id=1
<delete> ::= "DELETE FROM" <identifier> ["WHERE" <condition>] // delete from users where age=12
<table_reference> ::= <identifier> ["JOIN" <identifier> "ON" <condition>] // items or items JOIN orders ON users.id=orders.user_id
<select_list> ::= "*"| <column_list> // * name or * name,age,gender
<column_list> ::= <identifier>{","<identifier>} // name or name,age or name,age,gender
<order_by_option>::= "AS
@GibsonRuitiari
GibsonRuitiari / Main.kt
Created August 1, 2024 08:32
A simple and fast download manager that supports concurrent/spatial downloads
package org.example
import kotlinx.coroutines.*
import okhttp3.*
import okhttp3.HttpUrl.Companion.toHttpUrl
import org.example.DownloadProgress.Companion.calculateDownloadPercentageFromDownloadProgress
import org.example.Utils.ATTEMPT_COUNT
import org.example.Utils.DedicatedBlockingDispatcher
import org.example.Utils.combineSegmentsToFile
import org.example.Utils.copyToOutputStreamAsynchronously
@GibsonRuitiari
GibsonRuitiari / Navigation.kt
Created March 28, 2024 01:29
a simple navigation lib (can hardly be called one), that can work on any platform/application e.g., CLi, Gui apps.
package kotlinplayground
// a simple navigation lib (can hardly be called one), that can work on any platform/application e.g., CLi, Gui apps.
// adaptation to gui applications such as jetpack compose should be fairly simple, given the examples and explanation
// given
/**
* visualize navigation as a tree made up of branches and leaves (the branches can be considered
* as leaves because ultimately a branch must contain a leaf and other leaves)
* So the term branch is used interchangeably with leaf.
@GibsonRuitiari
GibsonRuitiari / MainActivity.kt
Created February 12, 2024 06:00
Shows how to use alarm manager
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
requestNotificationPermission()
val alarmManager = getSystemService(Context.ALARM_SERVICE) as AlarmManager
/* if you use AlarmManager.setRepeating(timeInMillis, timeInterval), note that the system will always delay your
alarm by 5 seconds and the interval must be at least 60 seconds+. However there's virtually no difference between
fun main(){
coroutineScope {
launch { findEvenNumbers(1,10..20) }
launch { findEvenNumbers(2,30..60) }
}
}
private fun findEvenNumbers(workerName:Int,range: IntRange){
for (i in range){
if (i%2==0) println("[$workerName]: even found $i")
}
@GibsonRuitiari
GibsonRuitiari / Main.kt
Created December 8, 2023 20:26
regex html parsing
import com.jakewharton.picnic.BorderStyle
import com.jakewharton.picnic.TextAlignment
import com.jakewharton.picnic.table
import java.net.URL
import kotlin.time.measureTime
fun main(args: Array<String>){
fun String.toHtml() = URL(this).openStream().bufferedReader().use { it.readText() }
val baseUrlHtml ="https://leagueofcomicgeeks.com/comics".toHtml()
// issues based on publisher
@GibsonRuitiari
GibsonRuitiari / PatriciaTrie.kt
Created December 4, 2023 11:01
This is the kotlin implementation of a patricia trie. This implementation is meant to be an accompaniment of the write up that explains the inner workings of patricia trie as described by Knuth. Please see the write for further understanding.
import java.util.Objects
import java.util.concurrent.locks.ReentrantLock
import kotlin.math.max
fun main(args: Array<String>){
val text ="A B C D E F G"
val trie = Trie(text)
println("${" ".repeat(10)}1.START${" ".repeat(10)}")
println(trie.addNodeToTrie(1))