Skip to content

Instantly share code, notes, and snippets.

View kahagon's full-sized avatar

Kenichi Ahagon kahagon

View GitHub Profile
@kahagon
kahagon / bullshit-determinator.php
Created December 10, 2013 17:17
ウンコ判別器
<?php
function isBullshit($object) {
return true;
}
<?php
/**
* この値が true だったら彼女ができる
*/
function datsudou() {
// 悲しみのハードコーディング
return false;
}
@kahagon
kahagon / shingeki-jra.php
Last active December 29, 2015 09:59
これで投票しようぜ!
<?php
$characters = array(
'eren' => 'エレン・イェーガー',
'mikasa' => 'ミカサ・アッカーマン',
'armin' => 'アルミン・アルレルト',
'jean' => 'ジャン・キルシュタイン',
'reiner' => 'ライナー・ブラウン',
'levi' => 'リヴァイ',
'zoe' => 'ハンジ・ゾエ',
'erwin' => 'エルヴィン・スミス',
@kahagon
kahagon / gorilla-basic-usage.php
Last active December 20, 2015 05:09
Basic usage of Gorilla.
<?php
// $device = 'COM4'; // on Windows
$device = '/dev/ttyUSB0'; // on Linux
/*
* create new instance
*/
$port = new SerialPort();
@kahagon
kahagon / hateda-delete.js
Created March 28, 2013 12:21
はてなダイアリーの記事を一括でチェック入れて削除するスクリプト。
var deleteForm = null;
for (var i = 0; i < document.forms.length; i++) {
var action = document.forms[i].getAttribute("action");
if (action && action.match(/delete$/))
deleteForm = document.forms[i];
}
tdList = document.getElementsByClassName("td-checkbox");
for (i = 0; i < tdList.length; i++) {
tdList[i].children[0].checked = true;
@kahagon
kahagon / greeting.php
Last active December 15, 2015 08:19
greeting!
<?php
$greeting = [0xE4BB8A, 0xE697A5, 0xE381AF, 0xE38081, 0xE38184, 0xE3818B, 0xE3818C, 0xE3818A, 0xE38199, 0xE38194, 0xE38197, 0xE381A7, 0xE38197, 0xE38287, 0xE38186, 0xE3818B, 0xEFBC9F];
foreach ($greeting as $v) {
print int2bin($v);
}
print PHP_EOL;
function int2bin($i) {
$byte_array = null;
$byte_len = ceil(bitlen($i)/8);
<?php
function base64_encode_recursively($target) {
if (is_array($target)) {
foreach ($target as $key => $value) {
$target[$key] = base64_encode_recursively($value);
}
return $target;
} else if (is_object($target)) {
$property_list = get_object_vars($target);
foreach ($property_list as $key => $value) {
<?php
$context = null;
$vendor_id = 0x04a9;
$product_id = 0x10d3;
$result_init = usb_init($context);
if ($result_init != USB_SUCCESS) {
die('failed to usb_init(). ' . usb_error_name($result_init));
}
$config_descriptor = null;
@kahagon
kahagon / catch-open-exception.php
Last active December 14, 2015 20:19
$port->open() でのエラー処理について。 https://twitter.com/waseda_fablab/status/311402456552722433
<?php
/* シリアルポートオブジェクトを作ります。
* この段階ではまだ open していません。 */
$port = new SerialPort();
/* open に失敗すると例外がスローされるので
* try catch で例外を補足し、例外処理を適宜行います。 */
try {
/* ここでは仮に存在しないポートを指定してします。*/
@kahagon
kahagon / repl.php
Created February 12, 2013 17:05
PHP REPL script.
#!/usr/bin/env php
<?php
$stdin = fopen('php://stdin', 'r');
$data = '';
while(true) {
print '> ';
$data .= fgets($stdin);
if (preg_match('/\\\\$/', $data)==1) {
$data = trim($data, "\x00..\x1F \x5C");
} else {