Skip to content

Instantly share code, notes, and snippets.

View makenowjust's full-sized avatar
㊗️
The IDOLM@STER MILLION LIVE THE ANIMATION

Hiroya Fujinami makenowjust

㊗️
The IDOLM@STER MILLION LIVE THE ANIMATION
View GitHub Profile
// An implementation of Glushkov's construction in Scala.
//
// See https://en.wikipedia.org/wiki/Glushkov%27s_construction_algorithm.
/** Nfa represents an non-deterministic finite state automaton.
*
* @tparam A
* an alphabet type
* @tparam Q
* a state type
// https://hackage.haskell.org/package/data-reify
import java.util.IdentityHashMap
trait MuRef[T]:
type F[_]
def recurse[U](t: T)(f: T => U): F[U]
trait NuRef[T]:
trait Semigroup[A]:
def combine(x: A, y: A): A
trait Monoid[A] extends Semigroup[A]:
def empty: A
trait Functor[F[_]]:
def map[A, B](fa: F[A])(f: A => B): F[B]
trait Applicative[F[_]] extends Functor[F]:
package rbtree
import scala.annotation.tailrec
// References:
// - https://abhiroop.github.io/Haskell-Red-Black-Tree/
// - https://github.com/Abhiroop/okasaki/blob/b4e8b6261cf9c44b7b273116be3da6efde76232d/src/RedBlackTree.hs
enum Color:
case R, B
# The MIT License
#
# Copyright 2023 Hiroya Fujinami (a.k.a. TSUYUSATO "MakeNowJust" Kitsune)
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the “Software”), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
require 'fileutils'
UNICODE_VERSION = "15.0.0"
BASE_DIR = "#{__dir__}/#{UNICODE_VERSION}"
UCD_DIR = "#{BASE_DIR}/ucd"
BASE_URL = "https://www.unicode.org/Public/#{UNICODE_VERSION}/ucd"
def download_file(file)
dir = "#{BASE_DIR}/#{File.dirname(file)}"
FileUtils.mkdir_p(dir)
@makenowjust
makenowjust / emmental
Created March 14, 2023 11:03
Emmental interpreter and Quine program
#!/usr/bin/env ruby
module Emmental
class Error < StandardError
STACK_UNDERFLOW = 'Stack Underflow'
QUEUE_UNDERFLOW = 'Queue Underflow'
end
class State
def initialize
This file has been truncated, but you can view the full file.
"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __propIsEnum = Object.prototype.propertyIsEnumerable;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __spreadValues = (a, b) => {
for (var prop in b || (b = {}))

Introduce cache-based optimization for Regexp matching

Regexp matching cause time-complexity explosion problem as known as ReDoS (https://en.wikipedia.org/wiki/ReDoS). ReDoS has become serious vulnerability in many places in recent years, and Ruby is no exception. The following are the incomplete list of such vulnerability reports:

These reports have been addressed by fixing the library/software implementation. But, if the language’s Regexp implementation become safe, the vulnerabilty is fundamentally archived.

For a few month, Ruby has implemented a Regexp matching timeout (https://bugs.ruby-lang.org/issues/17837). It is one of the useful methods for preventing ReDoS vulnerability, but it is a problem that setting a

export default (concurrency = 1) => {
let activeConsumerCount = 0;
const queue = [];
const consume = async () => {
if (activeConsumerCount >= concurrency) {
return;
}
activeConsumerCount += 1;