Skip to content

Instantly share code, notes, and snippets.

@kurain
kurain / gist:5858160
Created June 25, 2013 12:43
TAOCP 7.2.1.1
def function_f(tuple, m)
c = [-1, -1, 0]
if tuple.all? {|digit| digit == 0}
return c[0].abs
elsif tuple[0] == 1 and tuple[1..-1].all? {|digit| digit == 0}
return 0
else
sum = 0
tuple.each_index{|i| sum += c[i] * tuple[i] }
return sum % m
@kurain
kurain / compare.rb
Created July 17, 2013 15:27
Comper ruby's log and math.h log
require 'benchmark'
require 'inline'
class Test
include Math
inline do |builder|
builder.include('<math.h>')
builder.c <<-EOF
double
log_c(int i)
#!/bin/bash
if [ -n "$SESSION_NAME" ];then
session=$SESSION_NAME
else
session=multi-ssh-`date +%s`
fi
window=multi-ssh
### tmuxのセッションを作成
@kurain
kurain / thumbturn_detection.py
Created October 17, 2019 11:55
detecting thumbturn status
import io
import picamera
import sys
from time import sleep
from tensorflow.contrib import predictor
from picamera import PiCamera
import signal
import slacker
@kurain
kurain / vector_search.py
Created January 3, 2024 14:34
お手軽ベクトル検索
import mlx.core as mx
import numpy as np
import faiss
import time
class MLXVecSearch():
def __init__(self, stream=mx.gpu):
self._stream = stream