Skip to content

Instantly share code, notes, and snippets.

View hanachin's full-sized avatar
🌺
OKA

Seiei Miyagi hanachin

🌺
OKA
View GitHub Profile
@hanachin
hanachin / file0.txt
Last active June 29, 2018 03:35
Rubyで基底文字+結合文字だけ正規化する ref: https://qiita.com/hanachin_/items/c90a3036b5a7dc3e0e19
str = "神" + "Äが".unicode_normalize(:nfd)
# => "神Äが"
str.size
# => 5
str2 = str.each_grapheme_cluster.map {|s| s.size > 1 ? s.unicode_normalize : s }.join
# => "神Äが"
str2.size
# => 3
/* global console */
/* eslint complexity: ["error", 2] */
!function() {
(M => ((f => (p => f(a => (p(p))(a))) (p => f(a => (p(p))(a))))(f => n => (t => n > 0 && t())(() => (() => (str => console.log(str || n))((str => n % 5 ? str : `${str}Buzz`) ((str => n % 3 ? str : `${str}Fizz`)(""))))(f(n - 1)))))(M))(100);
}();
@hanachin
hanachin / fizzbuzz.js
Last active June 8, 2018 01:52
ジェネレーターべんり
function* fizzbuzz() {
let n = 1;
while (true) {
yield n++;
yield n++;
yield "Fizz"; n++;
yield n++;
yield "Buzz"; n++;
yield "Fizz"; n++;
yield n++;
@hanachin
hanachin / entry.rb
Created June 2, 2018 09:00
TRICK 2018 (FINAL)に出したやつ
return hello, world!
BEGIN {
using Module.new {
refine(Object) {
alias hello itself
alias world! itself
}
}
@hanachin
hanachin / file0.txt
Last active June 1, 2018 15:27
Refinementsをブロックの中だけで有効にする ref: https://qiita.com/hanachin_/items/a002558bc9809755d552
$ gem i with_refinements
= RubyVM::AST
(from ruby core)
------------------------------------------------------------------------
= Class methods:
parse, parse_file
@hanachin
hanachin / file0.txt
Last active May 31, 2018 15:24
Refinementsで定義したメソッドをusingより前の行で呼び出すテクニック10選 ref: https://qiita.com/hanachin_/items/d01576d276be3de7cfab
hi
# hi
BEGIN {
using Module.new {
refine(Object) do
def hi
puts "hi"
end
end
$ ruby -e '$~=1'
Traceback (most recent call last):
-e:1:in `<main>': wrong argument type Integer (expected MatchData) (TypeError)
# NilClass = FalseClassで死ぬのでこの解は弱い
# 指摘: https://twitter.com/mametter/status/1001792845961834497
# x.nil? を殺す
def nil.nil?
false
end
# x == nil を殺す
def nil.==(other)
@hanachin
hanachin / and_or1.rb
Created May 23, 2018 02:18
Rubyでand/orのようなものを実装する方法 ref: https://qiita.com/hanachin_/items/dc11e034a75b100f22a6
module AndOr
refine(Object) do
def and(o)
if self
o
else
self
end
end