Skip to content

Instantly share code, notes, and snippets.

View ParadoxV5's full-sized avatar
🈺

ParadoxV5

🈺
View GitHub Profile
@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) {
@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 / 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 / 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 / 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 / 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 / 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:
# frozen_string_literal: true
# Assuming `PascalCase` only. Also possible: `English Case`, `Snake_Case`, …
DIGITS_CASES = %w[
zero
one
two
three
four
five
@ParadoxV5
ParadoxV5 / My insights on a Pipeline Operator for Ruby.md
Last active October 1, 2024 20:31
a follow-up miniblog to ParadoxV5/ruby-pipeline

According to https://bugs.ruby-lang.org/issues/17353#note-1, there were (if not still are) consistent posts requesting adding Elixir’s Pipeline Operator |> to Ruby.

However, unlike Lisp-1 languages like Python or JavaScript, Lisp-2s like Ruby face the additional challenge of namespace disambiguation. In addition to rightward calling, the Pipeline Operator would also change the call of the RHS to include the LHS. Therefore, its syntax is incompatible with the traditional designs for message passing programming and introduces a never-before-seen mental load.

魔塔游戏,在英文社区应该叫什么?就用粉丝们草拟的Magic Tower

我带着这个问题,打开了[原始魔塔《Tower of the Sorcerer》的公认主页][英文网页])。

玩过英文版或访问过这个网站的盆友们都注意得到,作者的英文水平特别……小学生,强烈暗示游戏的英文是从某其它语言(粗糙)翻译来的。 而这个原语言极有可能是日文——网页左上角有个去日文版网页的链接,且俩版本都托管于同一个.jp顶级域的日文网站。 聪明好奇的我想到在日文网页上转转。如果猜想属实,作者的日文原文绝对比用英文写得清。

游戏的日文正名为《魔法の塔》。 嗯,正同中文取名《魔塔》,不知是洞若观火还是异曲同工。