Skip to content

Instantly share code, notes, and snippets.

View GibsonRuitiari's full-sized avatar
🤯

Ruitiari GibsonRuitiari

🤯
View GitHub Profile
@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))
@GibsonRuitiari
GibsonRuitiari / grammar.ebnf
Created July 26, 2023 09:07
grammar used for regex exp Parser
Regex ::= StartOfStringAnchor? Expression
Expression ::= Subexpression ("|" Expression)?
/* Anything that can be on one side of the alternation. */
Subexpression ::= SubexpressionItem+
SubexpressionItem
::= Match
| Group
| Anchor
@GibsonRuitiari
GibsonRuitiari / Main.kt
Last active August 3, 2023 07:00
LLR Parser for regex exp
/* a fully fledged parser than parses regex expressions into AST on the fly
* note the parser is an LL(1), and the grammar used is context-free
* right recursive.
* Also, the parser does not tokenize the inputs thus making it a little
* faster than those that tokenize their inputs.
* Currently, it parses all regexes apart from those having
* back-references & Zero-Width Positive Lookahead Assertions '?='
* For reference see: https://en.wikipedia.org/wiki/Compilers:_Principles,_Techniques,_and_Tools
* */
package kotlinplayground
import java.io.IOException
import java.net.URI
import kotlin.system.measureTimeMillis
fun main(vararg args:String) {
val url = "https://rest.coinapi.io/v1/assets?apikey=14CCAB31-C529-424C-9407-F9CC89F4C055"
val bufferSize = 4096
/*
@GibsonRuitiari
GibsonRuitiari / App.kt
Created June 17, 2023 15:59
Thompson algorithm implementation in kotlin
import java.util.*
import kotlin.random.Random
// for references see https://swtch.com/~rsc/regexp/regexp-bytecode.c.txt
// https://swtch.com/~rsc/regexp/regexp1.html
fun makeRange(start: Char, end: Char): List<Char> {
val out = mutableListOf('(')
for (s in start until end) {
import java.util.*
import kotlin.random.Random
// for references see https://swtch.com/~rsc/regexp/regexp-bytecode.c.txt
// https://swtch.com/~rsc/regexp/regexp1.html
fun makeRange(start: Char, end: Char): List<Char> {
val out = mutableListOf('(')
for (s in start until end) {