Skip to content

Instantly share code, notes, and snippets.

@wtnabe
wtnabe / gist:d449994d623288798700
Last active August 29, 2015 14:20
how to require autoload.php from executable file with composer ( including non-symlink-friendly system )
if ( !@include_once(dirname(__FILE__).'/../vendor/autoload.php') ) {
$dir = dirname(dirname(dirname(__FILE__)));
while ( !in_array('composer.json', array_map('basename', glob("{$dir}/*"))) ) {
if ( in_array('autoload.php', array_map('basename', glob("{$dir}/*"))) ) {
include_once($dir.'/autoload.php');
break;
} else {
$dir = dirname($dir);
}
@wtnabe
wtnabe / gist:f90f4211abd92d1df513
Created April 24, 2015 04:34
fputcsvを使ってCSVになった文字列を取得する
$fp = fopen('php://temp', 'r+');
foreach ( array_map(array($this, 'to_array'), $items) as $item ) {
fputcsv($fp, array_values($item));
}
rewind($fp);
$contents = stream_get_contents($fp);
fclose($fp);
return $contents;
@wtnabe
wtnabe / gist:5dbcbf3531f52d6d30b1
Last active August 29, 2015 14:17
ruby debuggers
ruby debugger
1.8 ruby-debug
1.9 debugger
2.0+ byebug

in Gemfile

 if RUBY_VERSION < '1.9'
@wtnabe
wtnabe / test_helper.rb
Created March 5, 2015 03:21
DatebaseRewinder + ActiveSupport::TestCase
DatabaseRewinder.strategy = :truncation
DatabaseRewinder.clean_all
class ActiveSupport::TestCase
# Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical order.
fixtures :all
def setup
DatabaseRewinder.start
end
@wtnabe
wtnabe / gist:4469825d23e919745538
Created March 2, 2015 13:35
Rails' allow_concurrency
def allow_concurrency?
if config.allow_concurrency.nil?
config.cache_classes && config.eager_load
else
config.allow_concurrency
end
end
@wtnabe
wtnabe / gist:bc74acd1ea60a90486ec
Created February 8, 2015 07:33
How to extract pdf from showoff 0.9.10+ with /print path and wkhtmltopdf
wkhtmltopdf -O landscape -s Letter http://localhost:9090/print pdf.pdf
@wtnabe
wtnabe / gist:7f8747f14f8a34d826a9
Created February 1, 2015 00:04
artisan commandに追加しとくとよさげなもの
command:test
system(__DIR__.'/../../vendor/bin/phpunit');
command:untracked
system('git ls-files -o --exclude-per-directory=.gitignore');
@wtnabe
wtnabe / gist:51950ea51c7860569ae3
Last active August 29, 2015 14:11
Kanazawa.rb meetup28 LT大会 演目
ical2gcalがGoogle Calendar API v3対応したよ
AndroidWearドヤぁ
モデリングしてますか?
Riemoh
RubyKaigiとYAPC::Asia
俺とDockerfileとtDiaryとKubernets
Webの歴史をふり返る
EngineYard触ってみた
5分でわかるオブジェクト指向
ライフゲーム最後まで作ってみました
@wtnabe
wtnabe / gulpfile.js
Created September 28, 2014 00:53
gulp task for installing basic cordova plugins ( with gulpfile prepared by Ionic )
gulp.task('cordova-plugin-install', function() {
require('./plugins.json').forEach(function(plugin) {
sh.exec('cordova plugin add ' + plugin, {async: false}, function(code, output) {
console.log(output);
});
});
});
@wtnabe
wtnabe / Rakefile
Last active August 29, 2015 14:06
rake dependencies for starting server outside ruby ( e.g. PythonSimpleHTTPServer ) and cleanup
require "rake/testtask"
Rake::TestTask.new do |t|
t.description = nil
t.pattern = 'spec/**/*_spec.rb'
end
desc 'start server and do spec and cleanup'
task :spec => :test do
Process.kill(:INT, @pid)