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 / 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 / DirectoryStructure
Last active September 26, 2021 20:03
Directory structure of Domain Driven Design application with Symfony2, Doctrine2.
sf2-ddd
├── app
├── bin
├── build
├── lib
├── src
│   └── __VendorPrefix
│   ├── Application
│   │   └── __DomainNameBundle
│   │   ├── Command
@satooshi
satooshi / QueueRunner.rb
Created August 12, 2019 12:29
Run rspec in parallel
#!/usr/bin/env ruby
require 'concurrent'
require 'coverage'
require 'parallel'
require 'rspec/core'
# serializable notifications inter processes
class FailedExampleNotification
require "pg"
DB.open "postgres://postgres:postgres@localhost:5432/blog_development" do |db|
db.transaction do |tx|
conn = tx.connection
pp conn.scalar "select count(*) from articles" # => 5
pp conn.exec "insert into articles (title, url, markdown, created_at, updated_at) values ('title', 'url', 'markdown', now(), now())"
pp db.scalar "select count(*) from articles" # => 5 (because this established another connection)
pp conn.scalar "select count(*) from articles" # => 6
Unhandled exception: (Time::Location::InvalidTZDataError)
from /usr/local/Cellar/crystal/0.27.0/src/time/location/loader.cr:86:5 in 'read_zoneinfo'
from /usr/local/Cellar/crystal/0.27.0/src/crystal/system/unix/time.cr:59:9 in 'load_localtime'
from /usr/local/Cellar/crystal/0.27.0/src/time/location.cr:339:10 in 'load_local'
from /usr/local/Cellar/crystal/0.27.0/src/time/location.cr:320:38 in 'local'
from /usr/local/Cellar/crystal/0.27.0/src/time.cr:367:16 in 'now'
from lib/amber/src/amber/server/server.cr:55:14 in 'start'
from lib/amber/src/amber/server/server.cr:50:9 in 'run'
from lib/amber/src/amber/server/server.cr:17:7 in 'start'
from src/blogway.cr:3:1 in '__crystal_main'
# spec/models/cat_spec.rb
require 'rails_helper.rb'
RSpec.describe Cat, type: :model do
# this is a test target model
let(:cat) { Cat.new(status: status) }
# this block describes Cat#nyan instance method
# when you reference an instance method, write `Class#method`
# and for a class method, write 'Class.method'
@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 / node installation on docker
Last active December 24, 2016 09:36
node installation on docker
# Dockerfile
------------------
FROM library/ubuntu:16.04
RUN apt-get -y update && apt-get install -y build-essential git python libssl-dev curl
# install nodebrew, node
ENV NODEBREW_ROOT=/usr/local/nodebrew
ENV PATH=/usr/local/nodebrew/current/bin:$PATH
RUN export NODE_VERSION=v4.3.2 && curl -L git.io/nodebrew | perl - setup \
&& nodebrew install-binary $NODE_VERSION \