Skip to content

Instantly share code, notes, and snippets.

@satooshi
satooshi / analytics_popular_posts.html
Created April 5, 2013 09:56
custom/asides/analytics_popular_posts.html
require 'flickraw'
def get_views_in_set(photoset_id)
FlickRaw.api_key = ENV["FLICKR_KEY"]
FlickRaw.shared_secret = ENV["FLICKR_SECRET"]
# flickr.photosets.getPhotos
# http://www.flickr.com/services/api/flickr.photosets.getPhotos.html
# http://www.flickr.com/services/api/explore/flickr.photosets.getPhotos
photos = flickr.photosets.getPhotos(:photoset_id => photoset_id, :extras => "views,original_format,path_alias")
@satooshi
satooshi / hatena_diary2markdown.php
Created February 28, 2013 14:48
Convert movable type text exported from hatena diary to markdown.
<?php
// decoder
function decodePost($data)
{
$lines = explode("\n", $data);
$readMeta = true;
$post = array();
$body = array();
cat categories | awk '{count[$0]++}END{for(i in count)print count[i], i}' | sort -nr
@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}
@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 / 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 / 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 / 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 / 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) {