Skip to content

Instantly share code, notes, and snippets.

View zonuexe's full-sized avatar
🤓
PHP is a Lisp. Emacs is Web.

USAMI Kenta zonuexe

🤓
PHP is a Lisp. Emacs is Web.
View GitHub Profile
@zonuexe
zonuexe / fn.php
Created August 2, 2019 06:52
Z combinator
<?php
// Short
$fix=fn($f)=>(fn($x)=>$f(fn(...$as)=>($x($x)(...$as))))(fn($x)=>$f(fn(...$as)=>($x($x)(...$as))));
// Long
$fix = fn (callable $f) => call_user_func(
(fn (callable $x) => $f(fn (...$as) => ($x($x)(...$as)))),
(fn (callable $x) => $f(fn (...$as) => ($x($x)(...$as))))
);
@zonuexe
zonuexe / LICENSE
Created July 5, 2019 04:47
シリアライズできる任意の値をキーにできる配列っぽいオブジェクト
Copyright 2019 USAMI Kenta <[email protected]>
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
@zonuexe
zonuexe / lolipop-mc-vuln-challenge.patch
Created June 30, 2019 10:25
PHPカンファレンス福岡2019 PHPアプリケーション脆弱性修正チャレンジの回答だぽ
diff --git a/global/index.php b/global/index.php
index 956a254..e3dd049 100644
--- a/global/index.php
+++ b/global/index.php
@@ -9,8 +9,7 @@
require_once('./auth.php');
$auth = new Auth();
$secret_token = $auth->generateToken();
- extract($_POST);
- $auth->render($token, $secret_token);
@zonuexe
zonuexe / fizzbuzz-loader.php
Created April 9, 2019 16:16
FizzBuzz loader
<?php
trait Fizz { function __toString() { return "Fizz"; } }
trait Buzz { function __toString() { return "Buzz"; } }
trait FizzBuzz { function __toString() { return "FizzBuzz"; } }
trait N { function __toString() { return ltrim(__CLASS__, @_); } }
spl_autoload_register(function ($class) {
$n = ltrim($class, @_);
$trait = null;
<?= implode(PHP_EOL, array_map(function ($n) {
return [0 => 'FizzBuzz', 3 => 'Fizz', 5 => 'Buzz', 6 => 'Fizz',
9 => 'Fizz', 10 => 'Buzz', 12 => 'Fizz'][$n%15] ?? $n;
}, range(0, 100))) . PHP_EOL;
@zonuexe
zonuexe / php-syntax-checker
Created March 29, 2019 20:22
Gitリポジトリ内のPHPの全ファイルを検査するやつ
#!/usr/bin/env php
<?php declare(strict_types=1);
/**
* プロジェクト内の全PHPファイルに対して文法チェックを実施する
*
* @author USAMI Kenta <[email protected]>
* @copyright 2019 USAMI Kenta
* @license https://opensource.org/licenses/MIT MIT
*/
<?php
const X = 100;
const FB = ['FizzBuzz', null, null, 'Fizz', null, 'Buzz', 'Fizz',
null, null, 'Fizz', 'Buzz', null, 'Fizz', null, null];
call_user_func(new class {
function __invoke()
{
if (X-count(debug_backtrace())-1) call_user_func(__METHOD__);
@zonuexe
zonuexe / fib.php
Created March 6, 2019 10:12
PHPでチャーチ数を使ってフィボナッチ数列
<?php declare(strict_types=1);
global $succ;
$succ = function ($n) {
return function ($f) use ($n) {
return function ($x) use ($n, $f) {
// ^n. ^f. ^x. f (n f x)
return $f($n($f)($x));
};
};
@zonuexe
zonuexe / README.md
Created July 21, 2018 19:13
PHPStan Test
@zonuexe
zonuexe / kuso.php
Last active July 5, 2018 10:38
PHPの機能を使って、くそコードを表明します
<?php /** @license WTFPL | by USAMI Kenta */
$クソ関数 = function() {
kuso();
var_dump('うんこ');
};
suppress_kuso();
$クソ関数();