Skip to content

Instantly share code, notes, and snippets.

View polidog's full-sized avatar
🌎

Ryota Mochizuki polidog

🌎
View GitHub Profile
<?php
function recursive_array_search($needle, array $haystack) {
foreach ($haystack as $key => $value) {
if ($value === $needle) {
return $key;
}
if (is_array($value)) {
$chideKey = recursive_array_search($needle, $value);
return [$key, $chideKey];
}
@polidog
polidog / anniversary.coffee
Created April 22, 2016 02:17
nightmare+hubot
Nightmare = require 'nightmare'
request = require 'request'
fs = require 'fs'
Gyazo = require 'gyazo-api'
nightmare = Nightmare()
url = process.env.HATENA_COUNT_URL
filename = "./ss.png"
client = new Gyazo(process.env.GYAZO_TOKEN)
@polidog
polidog / VichUriExtension.php
Created May 26, 2016 00:27
vich uploader bundleのassetの改良版
<?php
/**
* Created by PhpStorm.
* User: polidog
* Date: 2016/05/26
*/
namespace AppBundle\Twig\Excetsion;
@polidog
polidog / invoke_test.php
Created June 2, 2016 09:02
__invoke()が必要場合ってどんなときだろうって考えてみた
<?php
/*
* __invoke()を使う意味がわからなかったけど、よく考えたらcallableな引数渡すときに無名関数じゃなくて、オブジェクト
* そのものを渡したい時に使えそうだと思った。
*/
class Hoge {
public function __invoke(string $output)
{
$this->exec($output);
@polidog
polidog / YahooJpResourceOwner.php
Last active June 14, 2016 10:02
YahooID連携用のResourceOwner
<?php
namespace AppBundle\OAuth\ResourceOwner
use HWI\Bundle\OAuthBundle\OAuth\ResourceOwner\GenericOAuth2ResourceOwner;
use HWI\Bundle\OAuthBundle\Security\Core\Authentication\Token\OAuthToken;
use Symfony\Component\HttpFoundation\Request;
use Buzz\Message\RequestInterface as HttpRequestInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
class YahooJpResourceOwner extends GenericOAuth2ResourceOwner
<?php
namespace AppBundle;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Bundle\Bundle;
use AppBundle\DependencyInjection\Compiler\YahooOAuthCompilerPass;
class AppBundle extends Bundle
{
@polidog
polidog / gulpfile.js
Last active February 19, 2018 12:49
Gulp+PHP CS Fixer
var gulp = require('gulp');
var exec = require('child_process').exec;
gulp.task('watch',function(){
gulp.watch("./src/**/*.php").on('change',function(event){
var command = "php-cs-fixer fix " + event.path + " --config-file=" + __dirname + "/.php_cs"
exec(command);
console.log("execute command: "+command);
})
});
@polidog
polidog / config.toml
Created August 8, 2016 17:08
GORMのMySQL接続のサンプル
[Database]
driver = "mysql"
server = ""
user = "hoge"
password = "fuga"
database = "testgo"
charset = "utf8"
parseTime = "true"
@polidog
polidog / symfony.fish
Created May 8, 2017 12:11
fish completion for symfony
function _symfony_console
php (find . -maxdepth 2 -mindepth 1 -name 'console' -type f | head -n 1)
end
function _symfony_get_command_list
_symfony_console --no-ansi | sed "1,/Available commands/d" | awk '/^ ?[^ ]+ / { print $1 }'
end
complete -f -c "console" -a "(_symfony_get_command_list)"
@polidog
polidog / hogehoge.js
Created June 17, 2017 15:57
このコードが理解できない・・・
var empty = () => {
return (pattern) => {
return pattern.empty()
}
}
var cons = (value, list) => {
return (pattern) => {
return pattern.cons(value,list)
}