Skip to content

Instantly share code, notes, and snippets.

View ParadoxV5's full-sized avatar
🎮

ParadoxV5

🎮
View GitHub Profile
# frozen_string_literal: true
# Assuming `PascalCase` only. Also possible: `English Case`, `Snake_Case`, …
DIGITS_CASES = %w[
zero
one
two
three
four
five
@ParadoxV5
ParadoxV5 / ruby-configure.txt
Last active January 2, 2024 21:22
Options for building Ruby 3.3 (apply to `./configure`)
`configure' configures this package to adapt to many kinds of systems.
Usage: ./configure [OPTION]... [VAR=VALUE]...
To assign environment variables (e.g., CC, CFLAGS...), specify them as
VAR=VALUE. See below for descriptions of some of the useful variables.
Defaults for the options are specified in brackets.
Configuration:
@ParadoxV5
ParadoxV5 / CollectionSearch.java
Last active November 11, 2022 05:23
Strategies to search the element(s) in a Java Collection that the given non-`null` item `equals` while not necessarily be the same object (i.e. equal by `==`) (returns `null` for single-search and empty collection for “all”-search) [WTFPL License]
package xyz.paradoxv5.java;
import java.util.*;
import org.jetbrains.annotations.*;
/**
For {@code List}s, there is also {@link List#indexOf(Object)} + {@link List#get}.
For <b>sorted</b> Arrays and {@code List}s, Java has
{@link Arrays#binarySearch(Object[], Object)} and
{@link Collections#binarySearch(List, Object) respectively}
@ParadoxV5
ParadoxV5 / hello, world.rb
Created November 7, 2022 23:23
[MRI only] Hello World in Ruby – the wrong way (Ruby Fiddle study with a brief touch on MRI C API)
# frozen_string_literal: true
require 'fiddle'
include Fiddle
GREETINGS = 'hello, world'
Handle.new.then do |lib|
Function.new(
lib['rb_eval_string'],
[TYPE_CONST_STRING],
@ParadoxV5
ParadoxV5 / Proc vs. Lambda.rb
Created November 7, 2022 19:11
study script for comparing Ruby’s non-Lambda Procs and Lambda Procs
# Proc and lambda share the same class {Proc}.
# {Proc#lambda?} queries if a Proc is a lambda or not.
#
# You can create a proc with {Proc.new} or {Kernel#proc}.
# You can create a lambda with the `->(){}` syntax or {Kernel#lambda}.
#
# `&blk` converts block `blk` to proc (when receiving args)
# or procs or lambda to block (when passing args).
#
# Invoke a proc or lambda with {Proc#call}
@ParadoxV5
ParadoxV5 / REST.md
Created September 5, 2022 03:10
REST study notes

REpresentational State Transfer

a fancy name for the CRUD support of a (web) server

  • for the client-server model
    • implemented by typically web servers though HTTP(S), with data formatted in HTML, JSON or etc.
  • treats server resources as OOP-style objects that can be CRUDed
    • a resource object can be a single item or a collection (as in OOP)
    • use client-side cache and server-side resources, not suspensive states (as with a “State Diagram”)
@ParadoxV5
ParadoxV5 / OverlappedRepeat.java
Created July 12, 2022 23:27
Repeat, but zipping the copies (i.e. repeat at each element of the sequence) instead of concatenating entire repetition copies.
import java.util.*;
import java.util.stream.Stream;
public interface OverlappedRepeat<E> extends Collection<E> {
static <E> Stream<E> overlappedRepeat(Stream<E> stream, int count) {
return stream.flatMap(e -> Stream.generate(()->e).limit(count));
}
static <E> Stream<E> overlappedRepeat(Collection<E> collection, int count) {
return overlappedRepeat(collection.parallelStream(), count);
@ParadoxV5
ParadoxV5 / GetStackTraceString.java
Created May 14, 2021 09:44
String form of `Throwable#getStackTrace()`
import java.io.PrintWriter;
/** Wrapper class for {@link #of()} */
public final class GetStackTraceString {
/**
@param e the {@link Throwable}
@return
a {@link String} form of this {@code Throwable}’s {@link Throwable#getStackTrace() stack trace}
using {@link Throwable#printStackTrace(PrintWriter)}
*/
public static String of(Throwable e) {