Skip to content

Instantly share code, notes, and snippets.

View genki's full-sized avatar

Genki Takiuchi genki

View GitHub Profile
@genki
genki / chatgpt.rb
Created December 5, 2022 06:38
Talk with ChatGPT from CLI.
#!/usr/bin/ruby
require 'bundler/inline'
gemfile do
source 'https://rubygems.org'
gem 'shellwords'
end
CHATGPT_URI = "https://chat.openai.com/chat"
def get_page_info
@genki
genki / indent_for_many_args.c
Created November 2, 2022 05:32
My preference is style-2.
// style-1
scanner->sis = grn_scan_info_build(ctx,
scanner->expr,
&(scanner->n_sis),
op,
record_exist);
// style-2
scanner->sis =
grn_scan_info_build
@genki
genki / find_unused.js
Created July 3, 2022 00:09
Find unused indexes out of mongodb
db.<collections>.aggregate({$indexStats:{}})._batch.reduce((h,i) => {h[i.spec.name] = i.accesses.ops; return h}, {})
require "em-synchrony"
def foo
fiber = Fiber.current
EM::Timer.new 3 do
fiber.resume "foo"
end
Fiber.yield
end
@genki
genki / gist:bdeef7a59f389f1dbd03e6c4e6ea28d3
Created February 15, 2018 03:03
strace result of a busy ruby process
% time seconds usecs/call calls errors syscall
------ ----------- ----------- --------- --------- ----------------
26.90 0.257079 6 41582 rt_sigprocmask
16.05 0.153354 7 20767 write
14.84 0.141774 7 20773 getsockopt
13.86 0.132456 6 20768 sched_yield
13.30 0.127114 18 6885 select
9.32 0.089066 6 13834 clock_gettime
5.53 0.052820 8 6986 50 read
0.09 0.000887 29 31 writev
@genki
genki / grn check
Created July 25, 2017 08:43
Groonga DBでトラブル。どのobjectなんだろ。情報足りない...
# grndb check /data/groonga/production
[query_log_flags_get] Can't open object. It's broken. Re-create the object or the database.
[query_log_flags_set] Can't open object. It's broken. Re-create the object or the database.
[query_log_flags_add] Can't open object. It's broken. Re-create the object or the database.
[query_log_flags_remove] Can't open object. It's broken. Re-create the object or the database.
@genki
genki / d
Created February 20, 2017 12:32
#!/bin/sh
while [ "`echo $1 | cut -c1`" = "-" ]; do
OPT="$OPT $1"
shift
done
IMG_TAG=`echo $1 | awk -F\@ '{print $1}'`
CMD=`echo $1 | awk -F\@ '{print $2}'`
IMG=`echo $IMG_TAG | awk -F: '{print $1}'`
TAG=`echo $IMG_TAG | awk -F: '{print $2}'`
if [ -z "$CMD" ]; then
@genki
genki / log.go
Last active February 7, 2017 04:29
Simple golang logger that has 2 different log levels for stdout and stderr.
package main
import (
"fmt"
"os"
"sync"
)
type LogLevel int
#0 __lll_lock_wait_private ()
at ../sysdeps/unix/sysv/linux/x86_64/lowlevellock.S:95
#1 0x00007f07b472e67a in __GI___libc_malloc (bytes=139671072336672)
at malloc.c:2909
#2 0x00007f07b4f10567 in ?? () from target:/lib64/ld-linux-x86-64.so.2
#3 0x00007f07b4f17412 in ?? () from target:/lib64/ld-linux-x86-64.so.2
#4 0x00007f07b4f12394 in ?? () from target:/lib64/ld-linux-x86-64.so.2
#5 0x00007f07b4f16bd9 in ?? () from target:/lib64/ld-linux-x86-64.so.2
#6 0x00007f07b47ed9bd in do_dlopen (ptr=0x161f640) at dl-libc.c:87
#7 0x00007f07b4f12394 in ?? () from target:/lib64/ld-linux-x86-64.so.2
@genki
genki / gist:3599a506ff605d6e1a037fb098eb0cee
Created February 1, 2017 19:44
なんか最近ruby2.3/glibc周りのクラッシュ増えた気が
*** Error in `ruby2.3': free(): invalid pointer: 0x000000000415b9f0 ***
======= Backtrace: =========
/lib/x86_64-linux-gnu/libc.so.6(+0x777e5)[0x7fe58e2da7e5]
/lib/x86_64-linux-gnu/libc.so.6(+0x7fe0a)[0x7fe58e2e2e0a]
/lib/x86_64-linux-gnu/libc.so.6(cfree+0x4c)[0x7fe58e2e698c]
/usr/lib/x86_64-linux-gnu/libruby-2.3.so.2.3(+0x8fcfd)[0x7fe58e6bbcfd]