Skip to content

Instantly share code, notes, and snippets.

@qubyte
qubyte / walker.py
Created September 23, 2012 04:45
Simple quantum random walk
"""
Requires matplotlib for plotting. Tested with python 27. If you want to try this
without plotting, remove the final two lines and the pylab import. The guts only
depends on math and will work with vanilla python.
"""
import math
import pylab
def probabilities(posn):
@leycec
leycec / beartype.py
Last active August 4, 2022 18:22
`@beartype` Decorator and Unit Test Suite Thereof
#!/usr/bin/env python3
'''
`@beartype` decorator, implementing a rudimentary subset of PEP 484-style type
checking based on Python 3.x function annotations.
See Also
----------
https://stackoverflow.com/a/37961120/2809027
Stackoverflow answer introducing the `@beartype` decorator.
@mattn
mattn / README.md
Last active February 14, 2017 15:13
jsonstore vs bolt
c:\dev\go-sandbox\jsonstore>go test -bench . -count 10
goos: windows
goarch: amd64
BenchmarkJsonstore-4        2000            897051 ns/op
BenchmarkJsonstore-4        2000            885050 ns/op
BenchmarkJsonstore-4        2000           1131564 ns/op
BenchmarkJsonstore-4        2000            839048 ns/op
BenchmarkJsonstore-4        2000            919052 ns/op
BenchmarkJsonstore-4        2000            838547 ns/op
@okapies
okapies / mastodon-ostatus.md
Last active September 5, 2021 11:39
Mastodon OStatus API の叩き方

Mastodon が他のインスタンスと情報交換をする OStatus API の使い方。使ってるだけのユーザは知る必要がない裏側の話。

host-meta

Mastodon インスタンスに対して、RFC6415 が規定する /.well-known/host-meta というパスを要求すると以下の XML が返ってくる.

<?xml version="1.0"?>
<XRD xmlns="http://docs.oasis-open.org/ns/xri/xrd-1.0">
  <Link rel="lrdd" type="application/xrd+xml" template="https://[MASTODON_HOST]/.well-known/webfinger?resource={uri}"/>
</XRD>
@matryer
matryer / term_context.go
Last active March 10, 2022 05:23
Making Ctrl+C termination cancel the context.Context
func main() {
ctx := context.Background()
// trap Ctrl+C and call cancel on the context
ctx, cancel := context.WithCancel(ctx)
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt)
defer func() {
signal.Stop(c)
@riocampos
riocampos / らじるらじるm3u8をffmpegで録音する(8放送局)201709以降対応.txt
Last active February 5, 2024 11:54
らじるらじる m3u8 を ffmpeg で録音する(8放送局)2021/4 以降対応
## NHKのネット配信サービスであるらじる★らじる。
# 従来は https://gist.github.com/riocampos/5656450 のように rtmpdump を使う必要がありましたが、
# 2017年9月から m3u8 による配信へ変更になったようです。m3u8 なので10秒単位での録音になります。
# また 2021年4月に更新され、以前の M3U8URL は2022年2月末で廃止されました。
## 録音コマンド(m4a)
ffmpeg -i M3U8URL -c copy outputfilename.m4a
# ファイルサイズ的に m4a が最も小さくなる
# m4a ファイルのときだけ "-c copy" オプションが使える。
@y2q-actionman
y2q-actionman / a_road_to_common_lisp_jp.md
Last active June 19, 2024 16:24
A Road to Common Lisp 翻訳

この文章は、 Steve Losh 氏の記事 "A Road to Common Lisp" の翻訳です。

原文はこちらです: http://stevelosh.com/blog/2018/08/a-road-to-common-lisp/


A Road to Common Lisp (Common Lisp への道)

これまで、「最近のCommon Lispをどう学ぶとよいでしょう?」と助言を求めるメールをたくさん受け取ってきました。そこで私は、これまでメールやソーシャルメディアに投稿した全てのアドバイスを書き下すことにしました。これが誰かに有益ならば幸いです。

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@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).