Skip to content

Instantly share code, notes, and snippets.

View mame's full-sized avatar

Yusuke Endoh mame

View GitHub Profile
# 0 < A < B < 1 を仮定
lower, upper = 0, 1
loop do
m = Rational(lower.numerator + upper.numerator, lower.denominator + upper.denominator)
case
when m < A then lower = m
when B < m then upper = m
else p [:found, m]; exit
end
end
# 0 < A < B を仮定
lower_num, lower_den = 0, 1
upper_num, upper_den = 1, 0
loop do
m_num = lower_num + upper_num
m_den = lower_den + upper_den
case
when m_num < A * m_den then lower_num, lower_den = m_num, m_den
when B * m_den < m_num then upper_num, upper_den = m_num, m_den
@mame
mame / gist:7393696
Created November 10, 2013 04:13
unbelievable hit a vim bug?
$ wget https://raw.github.com/michaeldv/unbelievable/master/lib/unbelievable/haiku.rb
--2013-11-10 13:11:03-- https://raw.github.com/michaeldv/unbelievable/master/lib/unbelievable/haiku.rb
Resolving raw.github.com (raw.github.com)... 103.245.222.133
Connecting to raw.github.com (raw.github.com)|103.245.222.133|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 3772 (3.7K) [text/plain]
Saving to: 'haiku.rb'
100%[======================================>] 3,772 --.-K/s in 0s
A♦8♥2♦2♠8♥7♦2♠8♥3♦2♠8♥7♦2♠8♥3♦2♠8♥6♦2♠8♥9♦2♠8♥6♦2♠8♥4♦2♠8♥4♦2♠8♥4♦2♠8♥9♦2♠8♥4♦2♠8♥4♦2♠8♥8♦2♠8♥5♦2♠8♥3♦2♠8♥9♦2♠8♥2♦2♠8♥6♦2♠8♥6♦2♠8♥2♦2♠8♥8♦2♠8♥6♦2♠8♥2♦2♠8♥6♦2♠8♥8♦2♠8♥5♦2♠8♥8♦2♠8♥3♦2♠8♥2♦2♠8♥8♦2♠8♥4♦2♠8♥7♦2♠8♥3♦2♠8♥7♦2♠8♥3♦2♠8♥6♦2♠8♥9♦2♠8♥6♦2♠8♥4♦2♠8♥3♦2♠8♥6♦2♠8♥9♦2♠8♥4♦2♠8♥2♦2♠8♥4♦2♠8♥5♦2♠8♥3♦2♠8♥9♦2♠8♥2♦2♠8♥6♦2♠8♥6♦2♠8♥7♦2♠8♥4♦2♠8♥6♦2♠8♥2♦2♠8♥6♦2♠8♥8♦2♠8♥5♦2♠8♥8♦2♠8♥3♦2♠8♥3♦2♠8♥2♦2♠8♥3♦2♠8♥7♦2♠8♥3♦2♠8♥7♦2♠8♥3♦2♠8♥6♦2♠8♥9♦2♠8♥6♦2♠8♥4♦2♠8♥4♦2♠8♥2♦2♠8♥5♦2♠8♥4♦2♠8♥2♦2♠8♥4♦2♠8♥5♦2♠8♥3♦2♠8♥9♦2♠8♥2♦2♠8♥6♦2♠8♥5♦2♠8♥3♦2♠8♥4♦2♠8♥6♦2♠8♥2♦2♠8♥6♦2♠8♥8♦2♠8♥5♦2♠8♥8♦2♠8♥3♦2♠8♥2♦2♠8♥8♦2♠8♥4♦2♠8♥7♦2♠8♥2♦2♠8♥3♦2♠8♥3♦2♠8♥6♦2♠8♥9♦2♠8♥6♦2♠8♥4♦2♠8♥4♦2♠8♥6♦2♠8♥5♦2♠8♥4♦2♠8♥4♦2♠8♥8♦2♠8♥5♦2♠8♥3♦2♠8♥9♦2♠8♥2♦2♠8♥6♦2♠8♥5♦2♠8♥4♦2♠8♥4♦2♠8♥6♦2♠8♥7♦2♠8♥6♦2♠8♥8♦2♠8♥5♦2♠8♥8♦2♠8♥3♦2♠8♥2♦2♠8♥9♦2♠8♥2♦2♠8♥7♦2♠8♥3♦2♠8♥5♦2♠8♥3♦2♠8♥6♦2♠8♥9♦2♠8♥6♦2♠8♥4♦2♠8♥3♦2♠8♥8♦2♠8♥3♦2♠8♥4♦2♠8♥4♦2♠8♥8♦2♠8♥5♦2♠8♥3♦2♠8♥9♦2♠8♥2♦2♠8♥6♦2♠8♥6♦2♠8♥2♦2♠8♥8♦2♠8♥6♦2♠8♥2♦2♠8♥6♦2♠8♥8♦2♠8♥5♦2♠8♥8♦2♠8♥3♦2♠8♥2♦2♠8♥8♦2♠8♥4♦2♠8♥7♦2♠8♥2♦2♠8♥3♦2♠8♥3♦2♠8♥6♦2♠8♥9♦2♠8♥6♦2♠8♥4♦2♠8♥3♦2♠8♥
M1 k1 = (call/cc (M2 k1)) + 3
M2 k1 k2 = if b then (k1 1) else (k2 2)
(call/cc M1) + 4
S1 k1 = (shift (λk2. k2 (S2 k1 k2))) + 3
S2 k1 k2 = if b then (k1 1) else (k2 2)
reset(exit(shift (λk1. k1 (S1 k1)) + 4))
<html><head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.5/require.min.js"></script><meta charset="utf-8" />
<!-- generated by ansi-to-html 0.0.3 https://github.com/uu59/ansi-to-html -->
</head><body style="color:#fff;background-color:#000">
<pre>
{"* malloc_info gen statistics"=>[["0", "29575", "12037320"], ["1", "16031", "2734752"], ["2", "910", "5874816"], ["3", "308", "5510752"], ["4", "8", "15440"], ["5", "12", "116848"], ["6", "4", "1312"], ["7", "177", "5559128"], ["8", "103", "59848"], ["9", "8", "768"], ["10", "15", "1288"], ["11", "11", "1080"], ["12", "14", "4496"], ["13", "18", "30400"], ["14", "1", "72"], ["15", "1", "120"], ["16", "30", "232976"], ["17", "7", "504"], ["18", "0", "0"], ["19", "18", "2224"], ["20", "0", "0"], ["21", "17", "18080"], ["22", "0", "0"], ["23", "0", "0"], ["24", "0", "0"], ["25", "0", "0"], ["26", "0", "0"], ["27", "0", "0"], ["28", "0", "0"], ["29", "0", "0"], ["30", "0", "0"], ["31", "0", "0"], ["32", "0", "0"], ["33", "0", "0"], ["34", "0", "0
@mame
mame / 0001-sfx-support.patch
Created May 10, 2012 13:40
sfx support of ruby
From 552877c780545e8b25ededf8fa2f0042597b6bcb Mon Sep 17 00:00:00 2001
From: Yusuke Endoh <mame@tsg.ne.jp>
Date: Thu, 10 May 2012 22:38:46 +0900
Subject: [PATCH] * sfx support.
---
cygwin/GNUmakefile.in | 11 ++++++---
io.c | 64 +++++++++++++++++++++++++++++++++++++++++++++++++
ruby.c | 16 +++++++++++++
win32/fix-size.rb | 20 ++++++++++++++++
@mame
mame / main.rb
Created November 8, 2015 16:48
eval(v=%(eval((e=*%w'662c3d220
214450800010840000001108420800
2084211000024cf324000000011c40
114a5288001184211c003242643c00
788c1498001194f108007a1c149800
321c9498007 844221000324c94980
032527098000 01e0780004a5e94a
400000e949c0 0421c94b8000006
420c00084e94 9c00000cb618001
148e21000421 2e4 a400308421
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/gh/spiermar/d3-flame-graph@2.0.3/dist/d3-flamegraph.css">
$ ./miniruby -e 'use_symbol = Object.instance_methods[0].is_a?(Symbol)
nummodule = nummethod = 0
mods = []
ObjectSpace.each_object(Module) {|m| mods << m if m.name }
mods = mods.sort_by {|m| m.name }
mods.each {|mod|
nummodule += 1
mc = mod.kind_of?(Class) ? "class" : "module"
puts "#{mc} #{mod.name} #{(mod.ancestors - [mod]).inspect}"
mod.singleton_methods(false).sort.each {|methname|