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 / 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 / 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 / pbkdf2.php
Last active September 19, 2019 05:04
A hash_pbkdf2() implementation for PHP versions 5.3 and 5.4.
<?php
/**
* Generate a PBKDF2 key derivation of a supplied password
*
* This is a hash_pbkdf2() implementation for PHP versions 5.3 and 5.4.
* @link http://www.php.net/manual/en/function.hash-pbkdf2.php
*
* @param string $algo
* @param string $password
@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 / 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 / cli-do-not-echo-password.php
Created January 23, 2011 23:07
PHPのコマンドラインツールでパスワードを要求するときの定番コード
<?php
// STDOUT or STDERR は場合に応じて
fwrite(STDERR, 'Password: ');
if (strncasecmp(PHP_OS, 'WIN', 3) === 0) {
// WindowsではエコーバックをOFFにできない?
@flock(STDIN, LOCK_EX);
$password = fgets(STDIN);
@flock(STDIN, LOCK_UN);
} else {
system('stty -echo'); // エコーバックをOFFにする
@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)