Skip to content

Instantly share code, notes, and snippets.

View GibsonRuitiari's full-sized avatar
🤯

Ruitiari GibsonRuitiari

🤯
View GitHub Profile
@GibsonRuitiari
GibsonRuitiari / OptimizedScanline.kt
Created April 21, 2025 11:37
Highly Optimized scanline filing algorithm inspired by c way of writing algorithms
package scanlineFilling
/* each edge consists of 4 values: the yMin, yMax, xOfYMin and the slopeInverse thus the total number is 4*/
const val SizeOfVariablesPerEdge = 4
/**
* the values we need to store are recorded in an array, and these are their indices.
* Essentially something like this
```
Index: 0 1 2 3 4 5 6 7 8 9 10 11
@GibsonRuitiari
GibsonRuitiari / Scanline.kt
Created April 19, 2025 13:03
A kotlin implementation of the scanline filling algorithm. The rendering is done on a terminal, but can be adopted to jetpack compose.
package scanlineFilling
/**
* The basic steps of a scan-line filling algorithm: build the edge table; sort the edges; loop through the scan-lines from yMin to the yMaximum,
* update the x coordinate as you move along, then fill up the regions covered by the active edges (successor and pre-decessor)
*/
data class Edge(val yMaximum: Float,
val yMinimum:Float,
var xOfYmin:Float, val slopeInverse:Float)
@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")
}