Skip to content

Instantly share code, notes, and snippets.

View GibsonRuitiari's full-sized avatar
🤯

Ruitiari GibsonRuitiari

🤯
View GitHub Profile
@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) {
@GibsonRuitiari
GibsonRuitiari / App.kt
Created June 17, 2023 15:12
thompson algorithm implementation in kotlin. Acts a proof of concept for a custom regex engine
import java.util.*
import kotlin.random.Random
fun makeRange(start: Char, end: Char): List<Char> {
val out = mutableListOf('(')
for (s in start until end) {
out.add(s)
out.add('|')
package me.gibsoncodes.myapplication
import android.os.Build
import android.os.FileObserver
import android.os.Handler
import android.os.HandlerThread
import android.os.Looper
import android.os.Message
import android.util.Log
import androidx.lifecycle.DefaultLifecycleObserver
package me.gibsoncodes.myapplication
import android.os.Handler
import android.os.Looper
import android.os.Message
import android.util.Log
import java.util.concurrent.CountDownLatch
/*