Skip to content

Instantly share code, notes, and snippets.

@kyo-takano
kyo-takano / lexical_search_with_gzip.py
Last active March 11, 2024 03:39
Lexical Search with gzip (gzipによる語彙検索)
import gzip
def gzip_search(query: str, candidate_chunks: list[str], top_k: int=1):
"""
文字列ベースで類似したテキストチャンクを推定するアルゴリズム.
`query`, `chunk`, および`query + " " + chunk`をそれぞれgzipで圧縮し、編集距離のようなものをベースに評価する.
Parameters:
query (str): 検索クエリとして使用する文字列.
top_k (int, optional): 返される類似チャンクの上位k個を指定する (default: 1).
@sasasin
sasasin / epub2mp4.sh
Last active January 9, 2024 01:05
EPUB を mp4 に変換するやつ
#!/bin/bash -ve
set -o pipefail
# EPUB ファイルをチャプター毎の mp4 ファイルに変換するシェルスクリプト
## 依存関係
# brew install w3m が必要
# unzip で、EPUBファイルからコンテンツ抽出
# find, sort で、EPUBファイル内にあるXHTMLファイルをリストアップ
# w3m で、XHTMLファイルからHTMLタグを除去し txt に変換
# say コマンドで txt から mp4 ファイルに変換
#import <Foundation/Foundation.h>
#import <assert.h>
//Compile with `clang -Os -framework Foundation -fno-objc-arc inlinestorage.m -o inline, run with `inline clever` or `inline naive`
/*
NaiveArray implements a simple immutable NSArray-like interface in probably the most obvious way: store a pointer to a C array of objects
*/
@interface NaiveArray : NSObject {
NSUInteger count;
@sylouuu
sylouuu / paths.md
Last active July 16, 2016 07:31
Google Chrome internal favicons

Google Chrome internal favicons

In case you need to use Google Chrome internal favicons.

A note about suffixes:

  • @1x means 16x16 icon size
  • @2x means 32x32 icon size

You'll have to copy/paste these paths.

@uasi
uasi / EXNOnDealloc.h
Created October 18, 2014 04:50
EXNOnDealloc
//
// EXNOnDealloc.h
//
// Copyright (c) 2014 uasi. All rights reserved.
//
#import <libextobjc/metamacros.h>
#define onDeallocOfObject(object) \
autoreleasepool {} \
@sonots
sonots / fluentd_hacking_guide.md
Last active August 30, 2021 05:57
Fluentd ソースコード完全解説 (v0.10向け)

Fluentd ソースコード完全解説

英題:Fluentd Hacking Guide

目次

30分しかないため斜線部分は今回省く

  • Fluentd の起動シーケンスとプラグインの読み込み
  • Fluentd の設定ファイルのパース
  • Input Plugin から Output Plugin にデータが渡る流れ
@akisute
akisute / Promise.swift
Created June 11, 2014 06:05
Promise in Swift, but completely broken in chaining. I can't just simply implement promise chaining X(
import Foundation
enum PromiseState:Int {
case Incomplete = 0
case Rejected = 1
case Resolved = 2
}
class Promise : Hashable {
@nakiwo
nakiwo / isEqual
Last active August 29, 2015 13:56
BOOL isEqual(NSObject *a, NSObject *b)
{
if (a) {
if (b) {
return [a isEqual:b];
}
} else { // a == nil
if (!b) {
return YES;
}
@GOROman
GOROman / UniTwi.cs
Last active March 3, 2018 16:29
Unityから画像付きツイート(update_with_media)をする。WWWクラスでは multipart/form-data が使えないのでTCPを直接叩く
// 断片
TcpClient tc = new TcpClient();
tc.Connect("api.twitter.com", 80);
using (NetworkStream ns = tc.GetStream())
{
System.IO.StreamWriter sw = new System.IO.StreamWriter(ns);
System.IO.StreamReader sr = new System.IO.StreamReader(ns);
// ==UserScript==
// @name Skip Gunosy Cushion Page
// @namespace userjs.com.cosmio.pastak
// @description
// @include http://gunosy.com/g/*
// ==/UserScript==
(function (){
var link = document.querySelector('a.articles-show-click');
location.href = link.href;