Skip to content

Instantly share code, notes, and snippets.

@satooshi
satooshi / .htaccess
Created September 2, 2012 14:49
mod_rewrite for front controller
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
# skip existent files
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule index.php - [QSA,L,C]
RewriteRule .* - [QSA,L]
# deny access php files
@satooshi
satooshi / parseLineLtsv.php
Last active December 12, 2015 08:59
LTSV line parser for php.
#!/usr/bin/env php
<?php
while (false !== $line = fgets(STDIN)) {
print_r(parse($line));
}
// 68 sec
function parse($line)
{
@satooshi
satooshi / ColorCLI.php
Last active December 12, 2015 09:19 — forked from donatj/ColorCLI.php
<?php
/**
* PHP CLI Colors – PHP Class Command Line Colors (bash)
*
* $str = "This is an example ";
*
* foreach (ColorCLI::$foregroundColors as $fg => $fgCode) {
* echo ColorCLI::$fg($str);
*
@satooshi
satooshi / junit.php
Last active October 4, 2022 06:09
Parse JUnit xml log generated by PHPUnit (phpunit ---log-junit build/logs/junit.xml) and print elapsed time each test case. If you want to color time at certain threshold time, get ColorCLI class (see https://gist.github.com/satooshi/4750401).
<?php
function run($path)
{
$xml = simplexml_load_file($path);
$project = $xml->testsuite;
echo sprintf("total: %s msec", formatMsec($project['time'])) . PHP_EOL;
foreach ($project->testsuite as $testsuite) {
@satooshi
satooshi / pmd.php
Last active November 27, 2018 02:30
Parse pmd.xml generated by PHPMD (phpmd src xml pmd.xml) and print violation messages. If you want to color messages at priority, get ColorCLI class (see https://gist.github.com/satooshi/4750401).
<?php
function run($path)
{
$xml = simplexml_load_file($path);
foreach ($xml->file as $file) {
echo sprintf("file: %s", $file['name']) . PHP_EOL;
foreach ($file->violation as $violation) {
echo " " . printMessage($violation) . PHP_EOL;
@satooshi
satooshi / checkstyle.php
Last active November 27, 2018 02:30
Parse checkstyle.xml generated by PHP_CodeSniffer (phpcs --report=checkstyle --report-file=checkstyle.xml src) and print violation messages. If you want to color messages at severity, get ColorCLI class (see https://gist.github.com/satooshi/4750401).
<?php
function run($path)
{
$xml = simplexml_load_file($path);
foreach ($xml->file as $file) {
echo sprintf("file: %s", $file['name']) . PHP_EOL;
foreach ($file->error as $violation) {
echo " " . printMessage($violation) . PHP_EOL;
@satooshi
satooshi / blog-sample.php
Last active December 13, 2015 20:38
PHP code for blog sample.
<?php
namespace Satooshi;
/**
* Short description.
*
* Long description.
*/
class Test
{
@satooshi
satooshi / tumblr2markdown.php
Last active December 14, 2015 03:48
Convert tumblr v1 xml response to Octopress markdown. See gist 5023226 if you would like to convert body.html to markdown (pandoc required).
<?php
$file = './tumblr.xml';
$xml = simplexml_load_file($file);
$posts = $xml->posts;
$root = "./_posts";
if (!is_dir($root)) {
mkdir($root);
}
@satooshi
satooshi / pandoc.sh
Created February 24, 2013 09:28
Convert tumblr blog html to markdown (pandoc required). See gist 5023141.
#!/bin/sh
cmd_pandoc="pandoc -f html -t markdown body.html -o body.md"
posts=`ls _posts`
root_dir=`pwd`
for post in ${posts}
do
post_dir="_posts/${post}"
echo ${post_dir}
cat categories | awk '{count[$0]++}END{for(i in count)print count[i], i}' | sort -nr