Skip to content

Instantly share code, notes, and snippets.

View iambenkay's full-sized avatar
🚀
Having Fun

Benjamin Chibuzor-Orie iambenkay

🚀
Having Fun
View GitHub Profile
@iambenkay
iambenkay / parser.js
Created June 25, 2023 16:24
Recursive descent parser that supports functions
function Interpreter() {
this.scopeStack = [{}];
this.functions = {};
}
const operators = ['+', '-', '/', '*', '%', '=', '=>', ')'];
Interpreter.prototype.tokenize = function (program) {
if (program === "") return [];
@iambenkay
iambenkay / recursive-descent-parser.js
Created June 25, 2023 07:54
Recursive Descent Parser for simple expression evaluator
function Compiler () {
};
Compiler.prototype.compile = function (program) {
return this.pass3(this.pass2(this.pass1(program)));
};
Compiler.prototype.tokenize = function (program) {
// Turn a program string into an array of tokens. Each token
// is either '[', ']', '(', ')', '+', '-', '*', '/', a variable
@iambenkay
iambenkay / grammar.pest
Last active June 1, 2023 12:01
WASL Parsing Expression Grammar for Pest.rs
ws = _{ " " | "\t" }
wsln = _{ ws | "\n" }
COMMENT = _{ "/*" ~ (!"*/" ~ ANY)* ~ "*/" | "//" ~ (!"\n" ~ ANY)* ~ "\n"+ }
Program = _{ SOI ~ wsln* ~ (Stmt ~ wsln*)* ~ Stmt? ~ EOI }
Stmt = { AssignmentExpr | ForExpr }
Identifier = @{ ASCII_ALPHA ~ (ASCII_ALPHANUMERIC | "_")* }
export function healthCheck(req, res) {
const { runAll,ㅤ} = req.body
const healthCheckScripts = [
"ping mysql-service.com:3306",
"ping google.com",ㅤ
];
// Assume exec is some function that executes commands on the shell
healthCheckScripts.forEach(check => {
@iambenkay
iambenkay / RSA.kt
Last active May 12, 2021 11:52
Perform RSA encryption and decryption in Java
import java.security.KeyFactory
import java.security.spec.PKCS8EncodedKeySpec
import java.security.spec.X509EncodedKeySpec
import java.util.*
import javax.crypto.Cipher
object RSA {
private val encoder = Base64.getEncoder()
private val decoder = Base64.getDecoder()
@iambenkay
iambenkay / AES.kt
Last active May 12, 2021 11:44
Perform AES encryption and decryption using Java
import java.util.*
import javax.crypto.Cipher
import javax.crypto.SecretKeyFactory
import javax.crypto.spec.IvParameterSpec
import javax.crypto.spec.PBEKeySpec
import javax.crypto.spec.SecretKeySpec
object AES {
private val encoder = Base64.getEncoder()
@iambenkay
iambenkay / atoms.js
Created November 7, 2020 19:32
Recoil.js sample code
import { atom } from "recoil";
export const historyState = atom({
key: "historyState",
default: []
});
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
@iambenkay
iambenkay / main.dart
Created March 20, 2020 11:43
Image.network caching problem
import 'package:flutter/material.dart';
final Color darkBlue = Color.fromARGB(255, 18, 32, 47);
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override