This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <canvas width="1600" height="1600" style="background:black"></canvas> | |
| <script> | |
| const canvas = document.querySelector('canvas') | |
| const ctx = canvas.getContext('2d') | |
| const outer = [...new Array(30)].map((_, i) => { | |
| const rot = 0.00 | |
| const th1 = Math.PI * 2 * (i - i % 6) / 30 + rot | |
| const th2 = th1 + Math.PI * 2 / 5 | |
| const th = th1 + [0, 0.335, 0.34, 0.5, 0.66, 0.665][i % 6] * (th2 - th1) | |
| const r = [1, 0.71, 0.62, 0.65, 0.62, 0.71][i % 6] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'prism' | |
| require 'irb' | |
| # Collect syntax-valid code snippets from the given directory | |
| def each_snippet(dir, max_size) | |
| files = Dir.glob("#{dir.delete_suffix('/')}/**/*.rb") | |
| snippets = Set.new | |
| handle_snippet = ->(code) { | |
| return if snippets.include?(code) | |
| snippets << code |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Found inconsistencies | |
| # a b do end.() | |
| # begin a => a: end; a in a: if 1; case a; in a: end | |
| # def a = a b do 1 end | |
| # a rescue b = *c | |
| # p(not a) | |
| # x = a b and c | |
| # def x = a b and c | |
| # a(a 1 do end) | |
| # a.(a 1 do end) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # log(10): [[(1/8), 10], [(1/15), 13], [(1/24), 7]] | |
| # log(2): [[(1/8), 3], [(1/15), 4], [(1/24), 2]] | |
| def print_logn_params(base) | |
| value_factors = {} | |
| (8..30).each do |n| | |
| num = (1+1r/n) | |
| (0..30).each do |exp| | |
| v = num ** exp | |
| break if v > 2 * base |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def exp_bs(x, prec) | |
| # Taylor series of exp can be converted to continued fraction as: | |
| # exp(x)-1 = x*(1+x/2*(1+x/3*(1+x/4*(1+x/5*(1+...))))) | |
| # Binary splitting can be applied to this continued fraction as: | |
| # (1 + a0/a1 + x/a1 * (1 + b0/b1 + x/b1 * rest)) | |
| # (1 + ((a0+x)*b1+x*b0)/(a1*b1) + (x*x)/(a1*b1) * rest) | |
| x = BigDecimal(x) | |
| step = (1..).bsearch { |k| Math.lgamma(k)[0] / Math.log(10) - k * x.exponent > prec } | |
| ms = (1..step).map { [0, BigDecimal(it)] } | |
| while ms.size > 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module YARD | |
| class Parser; end | |
| class TagHandler; end | |
| class ParseResult; end | |
| def self.process(comment, code_object) | |
| result = Parser.parse(comment) | |
| tag_handler = TagHandler.new(code_object) | |
| result.tags.each do |name, arg| | |
| tag_handler.handle(name, arg) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def sqrt(x, prec) | |
| y = BigDecimal(Math.sqrt(x.to_f)) | |
| yinv = BigDecimal(1 / y.to_f) | |
| (0..prec.bit_length).reverse_each do |i| | |
| p = [[(prec >> i) + 2, BigDecimal.double_fig].max, prec].min | |
| yinv = yinv.mult(BigDecimal(2).sub(y * yinv, p / 2), p / 2) | |
| yinv = yinv.mult(BigDecimal(2).sub(y * yinv, p), p) | |
| y = (y + x * yinv).div(2, p) | |
| end | |
| y |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| RackOnRactors::Minitra::Routes.draw do | |
| before do | |
| @foo = rand(1000) | |
| end | |
| get "/longlonglong" do | |
| raise if Ractor.main? | |
| "hello! " * @foo + request_header.inspect | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Reference: https://qiita.com/AngrySadEight/items/0dfde26060daaf6a2fda | |
| BASES = [29, 26, 24] | |
| SHIFT = 27 | |
| class NTT | |
| attr_reader :p | |
| def initialize(base, shift) | |
| @base = base |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <body> | |
| <script> | |
| const canvas = document.createElement('canvas') | |
| document.body.appendChild(canvas) | |
| const size = canvas.width = canvas.height = 800 | |
| const ctx = canvas.getContext('2d') | |
| const circles = [ | |
| { x: 0.2, y: 0.6, r: 0.1 }, | |
| { x: 0.7, y: 0.3, r: 0.07 }, |
NewerOlder