Skip to content

Instantly share code, notes, and snippets.

View k-tsj's full-sized avatar

Kazuki Tsujimoto k-tsj

View GitHub Profile
@k-tsj
k-tsj / parallel.rb
Created September 19, 2020 15:57
Enumerator::Parallel
END {
8.times.parallel(n: 2).each { p _1 }
}
class Enumerator
class Parallel
def initialize(enum, n:)
@enum = enum
@n = n
end
@k-tsj
k-tsj / gist:25c6da431c109c1879c11dc326b0614e
Last active September 19, 2020 09:47
Pattern matching with R-assign
diff --git a/parse.y b/parse.y
index 93bc2ef9ff..81db9a660d 100644
--- a/parse.y
+++ b/parse.y
@@ -1539,33 +1539,23 @@ stmt : keyword_alias fitem {SET_LEX_STATE(EXPR_FNAME|EXPR_FITEM);} fitem
| expr
;
-rassign : arg_value tASSOC lhs
+rassign : arg_value tASSOC
@k-tsj
k-tsj / t.rb
Last active April 29, 2023 09:54
calc sp
source = %q{
case 0
in a: 0
end
}
RubyVM::InstructionSequence.compile_option = RubyVM::InstructionSequence.compile_option.transform_values do |v|
(v == true or v == false) ? false : v
end
module Extractor
MATCH_FAILED = []
def MATCH_FAILED.length
-1
end
def ===(obj)
unapply = method(:unapply)
obj.singleton_class.define_method(:deconstruct) do
singleton_class.remove_method(:deconstruct)
@k-tsj
k-tsj / FindInPageByAltNum.uc.js
Last active June 14, 2020 15:31
uc.js for Firefox 77+
// https://gist.github.com/k-tsj/af03233fc023cb9e3280b0bce8c404b5
//
// License: Mozilla Public License 2.0
// Author: k-tsj
(() => {
window.addEventListener("keydown", (aEvent) => {
const keywords = BrowserSearch.searchBar.value.match(/"(?:\\"|\\\\|[^"])*"|\S+/g);
function exec_find() {
gFindBar._findField.value = keywords[aEvent.keyCode - KeyEvent.DOM_VK_1].replace(/^"|"$/g, "");
#0 rb_f_raise (argc=1, argv=0x7ffff7ee20f0) at eval.c:667
#1 0x0000555555742f61 in call_cfunc_m1 (func=0x5555555e91ac <rb_f_raise>, recv=93824997925600, argc=1, argv=0x7ffff7ee20f0) at vm_insnhelper.c:1706
#2 0x0000555555743a4a in vm_call_cfunc_with_frame (th=0x555555a5e620, reg_cfp=0x7ffff7fe1e90, calling=0x7fffffff9b40, ci=0x555555b75350, cc=0x555555b75370) at vm_insnhelper.c:1889
#3 0x0000555555743bd6 in vm_call_cfunc (th=0x555555a5e620, reg_cfp=0x7ffff7fe1e90, calling=0x7fffffff9b40, ci=0x555555b75350, cc=0x555555b75370) at vm_insnhelper.c:1905
#4 0x0000555555744e05 in vm_call_method_each_type (th=0x555555a5e620, cfp=0x7ffff7fe1e90, calling=0x7fffffff9b40, ci=0x555555b75350, cc=0x555555b75370) at vm_insnhelper.c:2203
#5 0x00005555557454fb in vm_call_method (th=0x555555a5e620, cfp=0x7ffff7fe1e90, calling=0x7fffffff9b40, ci=0x555555b75350, cc=0x555555b75370) at vm_insnhelper.c:2334
#6 0x0000555555745649 in vm_call_general (th=0x555555a5e620, reg_cfp=0x7ffff7fe1e90, calling=0x7fffffff9b40, ci=0x555555
@k-tsj
k-tsj / t.rb
Last active July 2, 2017 03:08
$ ruby t.rb
["t.rb:1:in `m1'", "t.rb:7:in `<main>'"]
["t.rb:2:in `m2'", "t.rb:8:in `<main>'"]
["t.rb:9:in `<main>'"]
["t.rb:4:in `block in <main>'", "t.rb:10:in `<main>'"]
@k-tsj
k-tsj / README.md
Last active September 25, 2016 14:06

Syntax

case value
=> pat [if|unless cond]
  ...
=> pat [if|unless cond]
  ...
else
  ...
end
$ bin/ruby -v
ruby 2.4.0dev (2016-09-12 master 56141) [x86_64-linux]
$ bin/ri
ri 5.0.0.beta2
$ bin/ri String
= String < Object
------------------------------------------------------------------------------
module DidYouMean
class MethodNameChecker
prepend Module.new {
PY2RB = {
String => {
lower: %i(downcase)
},
Object => {
len: %i(obj.length)
}