Skip to content

Instantly share code, notes, and snippets.

From d05d3e3b95d354f5f59232ace4db24ff859a5bcd Mon Sep 17 00:00:00 2001
From: Masaya TARUI <tarui@prx.jp>
Date: Tue, 4 Mar 2014 20:22:13 +0900
Subject: [PATCH] introduce st_foreach_update, st_foreach_update_check
---
hash.c | 47 ++++++++++------
internal.h | 5 ++
st.c | 177 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 214 insertions(+), 15 deletions(-)
@tarui
tarui / README
Created September 12, 2011 10:55
DevQuiz のSlidingPuzzleを解くためのC++コードです。
(C++といいつつclassでカプセル化と途中での宣言を使っている意外はCですが)
あらかじめproblems.txtを用意し、更にresultsフォルダを作っておく必要あり。
途中で止めて再開出来る機能もあり。
二重ループの値それぞれと、その時に出来てるresultsのNoを指定
(多分コードを読まないと何のことだか分からないだろうけど
アルゴリズムはIDDFSにマンハッタン距離による枝狩りと言う事になるんでしょうか?
Index: thread.c
===================================================================
--- thread.c (revision 38172)
+++ thread.c (working copy)
@@ -4337,6 +4337,19 @@
return Qnil;
}
+static VALUE
+rb_mutex_lock_sure(VALUE self)
# -*- coding: utf-8 -*-
r=:ok
e=Class.new(Exception)
th_s = Thread.current
begin
th = Thread.start{
Thread.async_interrupt_timing(Object => :on_blocking){
begin
Thread.current.raise RuntimeError
sleep
Index: lib/irb/completion.rb
===================================================================
--- lib/irb/completion.rb (revision 38221)
+++ lib/irb/completion.rb (working copy)
@@ -152,9 +152,10 @@
gv = eval("global_variables", bind).collect{|m| m.to_s}
lv = eval("local_variables", bind).collect{|m| m.to_s}
+ iv = eval("instance_variables", bind).collect{|m| m.to_s}
cv = eval("self.class.constants", bind).collect{|m| m.to_s}
$ tail -n2 *.log
==> 193p194_1.log <==
21.601350999999987
31.410000 0.490000 31.900000 ( 31.928621)
==> 193p194_2.log <==
20.781295
29.910000 0.330000 30.240000 ( 30.335949)
==> 193p194_3.log <==
@tarui
tarui / answer2.txt
Last active December 22, 2015 04:08
https://codeiq.jp/ace/yuki_hiroshi/q432 に対する回答(今は問題が読めませんが)
24689222839,0
ENV: Ruby
※締め切り後に調べた内容で解説を再編集しています。
Binary Indexed Treeとか知りませんでした(汗
インデックスの振り方が大変独特ですね。。。
https://twitter.com/debiru/status/374400678182928384
から
プログラミングコンテストでのデータ構造
@tarui
tarui / analyze_vm_exec_core_by_perf.rb
Created October 21, 2017 06:27
analyze_vm_exec_core_by_perf.rb
data=`perf annotate -svm_exec_core --show-total-period --stdio`.split(/\n/)
ins="before"
cnt=Hash.new{0}
total=0
data.each{|line|
case line
when /INSN_ENTRY\((.*)\)/
ins = $1
when /END_INSN/
ins = "none"
@tarui
tarui / before after # feasibility study of Proc#call optimization
Last active October 24, 2017 14:26
feasibility study of Proc#call optimization
require 'benchmark/ips'
f=proc{}
g=proc{|i| i>0 ? g.call(i-1):0 }
N=2000
Benchmark.ips do |x|
x.report("f"){ f.call }
x.report("g"){ g.call(N) }
end
# ====== before =================================
Warming up --------------------------------------
# Copy from https://github.com/docker-library/ruby/blob/752c5f7cf44870ceae77134b346d20093053c370/2.4/Dockerfile
FROM buildpack-deps:jessie
# skip installing gem documentation
RUN mkdir -p /usr/local/etc \
&& { \
echo 'install: --no-document --platform ruby'; \
echo 'update: --no-document'; \
} >> /usr/local/etc/gemrc