Skip to content

Instantly share code, notes, and snippets.

View buhii's full-sized avatar

Takahiro Kamatani buhii

View GitHub Profile
@buhii
buhii / merge_vector_indices.py
Created April 30, 2023 15:26
Merges multiple instances of GPTSimpleVectorIndex
from llama_index.vector_stores.simple import SimpleVectorStoreData, SimpleVectorStore
from llama_index.indices.vector_store import GPTVectorStoreIndex
from llama_index.data_structs.data_structs_v2 import SimpleIndexDict
from llama_index.docstore.simple_docstore import SimpleDocumentStore
def merge_vector_indices(vector_indices):
"""
Merges multiple instances of GPTSimpleVectorIndex from
the LlamaIndex (0.5.27) library into a single GPTVectorStoreIndex instance.
@buhii
buhii / DPLL.ipynb
Created January 10, 2021 13:51
DPLL.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
import png
f = open('icon.png', 'wb')
w = png.Writer(1, 1, greyscale=True)
w.write(f, [[240]])
f.close()
@buhii
buhii / packer.py
Created October 3, 2015 19:30
Simple 2D packing for PlotDevice
# -*- coding: utf-8 -*-
"""
Simple 2D packing for PlotDevice by Takahiro Kamatani
Based on https://pypi.python.org/pypi/ortoolpy by Saito Tsutomu
License: Python Software Foundation License
"""
class Cut(object):
V = True
H = False
@buhii
buhii / event_usage.py
Last active December 20, 2022 08:07
elasticsearch scripted metric aggregation
def event_usage(self, task_id, since, until, interval="1m"):
interval_ms = 60000 # 1 minute
quantize = lambda t: (t // interval_ms) * interval_ms
q_since, q_until = quantize(since), quantize(until)
# --- scripts ---
quantize_closure = "quantize = { it.intdiv(interval_ms) * interval_ms }\n"
script = {}
script['init'] = """
#!/bin/bash
mecab="mecab-0.996"
mecab_python="mecab-python-0.996"
mecab_googlecode="https://mecab.googlecode.com/files/"
if ! type curl > /dev/null; then
downloader='wget '
else
downloader='curl -O '
#!/bin/bash
# requirement: mecab
crfpp="CRF++-0.58"
crfpp_googlecode="https://crfpp.googlecode.com/files/"
cabocha="cabocha-0.68"
cabocha_googlecode="https://cabocha.googlecode.com/files/"
// Satoh's shoe rack OpenSCAD file
shoe_rack_height = 780 - 200;
support_width = 45;
support_thick = 15;
module shoe_rack_support(x, y) {
translate([x, y, 0]) {
cube([support_width, support_thick, shoe_rack_height]);
}
from collections import Counter
from random import sample
def try_boy():
result = []
child = sample(("Boy", "Girl"), 1)[0]
result.append(child)
if child == 'Girl':
result.extend(try_boy())
# -*- coding: utf-8 -*-
import codecs
import HTMLParser
import sys
import re
import bz2
DEBUG = False