Skip to content

Instantly share code, notes, and snippets.

@masakielastic
masakielastic / test.md
Last active January 11, 2018 02:39
脚注のテスト

タイトル

見出し1

本文。[1]

見出し2

次の文。[2]

1 脚注その1

@masakielastic
masakielastic / test.php
Last active September 19, 2017 16:36
0x0 から 0xff の範囲のバイトに対して mb_convert_encoding が無効なバイトをどのように置き換えるのかを確認します。
<?php
$enc = "cp932";
for ($cp = 0; $cp < 0x100; $cp++) {
$c = chr($cp);
$ret = mb_convert_encoding($c, $enc, $enc);
echo
bin2hex($c), " ",
@masakielastic
masakielastic / diff.rb
Last active October 2, 2017 06:39
ラウンドトリップが保障されない文字を調べます。
def chr_unsafe(cp, enc)
[cp.to_s(16)].pack("H*").force_encoding(enc)
end
enc = 'cp932'
count = 0
count2 = 0
(0x8000..0xffff).each do |cp|
begin
@masakielastic
masakielastic / utf8_ord.php
Created September 1, 2017 21:48
utf8_ord
<?php
function utf8_ord($char) {
$x = ord($char[0]);
if ($x < 0x80) {
return $x;
} else if ($x < 0xE0) {
$y = ord($char[1]);
<?php
$a = chr(0xfa).chr(0x4a);
var_dump(
"fa4a" === bin2hex($a),
"8754" === bin2hex(mb_strtolower($a, "CP932")),
"8754" === bin2hex(mb_strtoupper($a, "CP932"))
);
<?php
$a = chr(0xfa).chr(0x4a);
var_dump(
"fa4a" === bin2hex($a)
);
$a = mb_convert_encoding($a, "UTF-8", "CP932");
$a = mb_convert_encoding($a, "CP932", "UTF-8");
// http://stackoverflow.com/a/14947838/531320
const fromId = document.getElementById.bind(document);
const snabbdom = require('snabbdom');
const patch = snabbdom.init([
require('snabbdom/modules/class'),
require('snabbdom/modules/props'),
require('snabbdom/modules/style'),
require('snabbdom/modules/eventlisteners'),
]);
@masakielastic
masakielastic / benchmark.php
Last active August 29, 2015 14:27
mt_rand vs chr vs string concatenation
<?php
function timer(callable $block) {
$start = microtime(true);
for ($i = 0; $i < 100000; ++$i) {
$block();
}
$end = microtime(true);
return $end - $start;
}
@masakielastic
masakielastic / benchmark.php
Last active February 10, 2022 07:37
random_int vs mt_rand
<?php
function timer(callable $block) {
$start = microtime(true);
for ($i = 0; $i < 100000; ++$i) {
$block();
}
$end = microtime(true);
return $end - $start;
}