Skip to content

Instantly share code, notes, and snippets.

@rsky
rsky / ctor_named_args.php
Created April 4, 2024 06:58
PHP名前付き引数を配列から展開してみる
<?php
interface Instantiatable
{
}
class Instantiator
{
/**
* @template T
@rsky
rsky / index.ts
Created May 14, 2020 20:34
RxJSでthrottlingの練習。ついでにTsyringeも。
import "reflect-metadata";
import { EventEmitter } from "events";
import { fromEvent, interval, Observable, Subject, Subscription } from "rxjs";
import { take, throttle } from "rxjs/operators";
import { container, instanceCachingFactory } from "tsyringe";
class Throttling<T> {
private subscription: Subscription;
private subject: Subject<T>;
@rsky
rsky / japanese-era.php
Created April 1, 2019 07:08
新元号(令和)のために予約されているコードポイントからの変換ルールはまだない。
<?php
$s = "\u{337E} \u{337D} \u{337C} \u{337B} \u{32FF}\n";
echo $s;
echo Normalizer::normalize($s, Normalizer::FORM_KC);
@rsky
rsky / clock.go
Created March 15, 2019 10:51
clock for testing
package clock
import (
"flag"
"time"
)
type NowFunc func() time.Time
var nowFunc NowFunc
@rsky
rsky / manifest.json
Last active November 9, 2020 21:47
Tiny Proxy Configurator
{
"name": "Tiny Proxy Configurator",
"version": "1.0",
"description": "A tiny and simple proxy configurator.",
"permissions": [
"proxy"
],
"background": {
"scripts": [
"pac.js"
@rsky
rsky / Calculator.java
Last active September 20, 2017 14:34
戦果係数を自動で検出する試み
import java.math.BigInteger;
import java.util.*;
import java.util.stream.Collectors;
public class Calculator {
private static final int[] RANKING_RATE_MAGIC_NUMBERS =
{8931, 1201, 1156, 5061, 4569, 4732, 3779, 4568, 5695, 4619, 4912, 5669, 6586};
public static int detectRateCoefficient(Map<Integer, Long> source) {
Set<BigInteger> set = new HashSet<>();
@rsky
rsky / memo.md
Created May 14, 2017 15:02
OSX+航海日誌で動画キャプチャする設定
  • {path} はダブルクォートしてはいけない。
  • -i 0:none0(ビデオデバイスのインデックス)は環境によって1等に変更する
  • Retinaディスプレイのキャプチャはうまくいかない(キャプチャ全体に倍率設定が必要?)
The following ports are currently installed:
apache-ant @1.9.7_0 (active)
autoconf @2.69_5 (active)
automake @1.15_1 (active)
bison @3.0.4_1 (active)
bison-runtime @3.0.4_0 (active)
bzip2 @1.0.6_0 (active)
cctools @886_6+llvm38 (active)
cmake @3.7.1_0 (active)
colordiff @1.0.16_0 (active)
@rsky
rsky / aggr.php
Created September 29, 2016 16:04
航海日誌 (logbook/logbook-kai) の資材ログを日付ごとにまとめるスクリプト
#!/usr/bin/env php
<?php
/**
* Usage:
* php aggr.php < 資材ログ.csv > out.csv
* nkf -Ws -Lw out.csv > 資材ログ.csv
*/
$src = 'php://filter/read=convert.iconv.cp932%2Futf-8/resource=php://stdin';
$file = new SplFileObject($src);
@rsky
rsky / change_fill_color.php
Last active June 6, 2016 03:37
透明チャンネルをそのままに塗り潰し色を変える
<?php
// usage: php change_fill_color.php '#cafe00' < in.png > out.png
$color = $_SERVER['argv'][1];
$in = new Imagick();
$in->readImageFile(STDIN);
$size = $in->getImageGeometry();
$out = new Imagick();
$out->newImage($size['width'], $size['height'], $color);