Skip to content

Instantly share code, notes, and snippets.

@n1215
n1215 / Procfile
Last active June 15, 2023 03:50
build a Laravel app container image using Google Cloud's Buildpacks
web: pid1 --nginxBinaryPath nginx --nginxConfigPath /layers/google.php.webconfig/webconfig/nginx.conf --serverConfigPath /workspace/nginxserver.conf --nginxErrLogFilePath /layers/google.php.webconfig/webconfig/nginx.log --customAppCmd "php-fpm -R --nodaemonize --fpm-config /layers/google.php.webconfig/webconfig/php-fpm.conf" --pid1LogFilePath /layers/google.php.webconfig/webconfig/pid1.log --mimeTypesPath /layers/google.utils.nginx/nginx/conf/mime.types --customAppSocket /layers/google.php.webconfig/webconfig/app.sock
@n1215
n1215 / Procfile
Last active September 13, 2023 15:29
build settings for Laravel + Heroku Buildpacks on AWS App Runner/Google Cloud Run
web: heroku-php-nginx -C nginx.conf public
@n1215
n1215 / UserRepositoryInterface.ts
Last active April 21, 2021 06:49
TypeScript classless DI container design
export type User = {
id: number
name: string
}
export interface UserRepositoryInterface {
list(): User[]
}
@n1215
n1215 / cakephperize.php
Last active April 1, 2021 01:37
cakephperize
<?php
declare(strict_types=1);
/**
* (experimental)
* cakephperize your icons
*
* usage)
* $ php cakephperize.php {file_url} {threshold}
<?php
// EloquentのEager Loadを無理やり使うバージョン
/** @var \Illuminate\Support\Collection<\stdClass> $userAndPoints */
$userAndPoints = Status::query()
->with('user.userDetail')
->select('user_id')
->selectRaw('sum(point) As point')
->groupBy('user_id')
@n1215
n1215 / Main.elm
Last active January 18, 2020 01:20
timer event sourcing elm
module Main exposing (main)
import Browser
import Browser.Events exposing (onAnimationFrame)
import Html exposing (Html, button, div, p, table, tbody, td, text, th, thead, tr)
import Html.Events exposing (onClick)
import List
import Task
import Time
import Tuple
@n1215
n1215 / TimeTravel.php
Created November 21, 2019 06:21
Laravel Middleware for time travel debugging
<?php
declare(strict_types=1);
namespace App\Http\Middleware;
use Carbon\Carbon;
use Closure;
use Exception;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Cookie;
#!/usr/bin/env bash
# コンテナを起動
function up {
docker-compose up -d
}
# コンテナ停止
function down {
docker-compose down
@n1215
n1215 / StrBuilder.php
Created October 17, 2019 06:17
str builder
<?php
declare(strict_types=1);
namespace App\Support;
use Illuminate\Support\Str;
class StrBuilder
{
/**
@n1215
n1215 / lazyChunk.php
Last active October 16, 2019 14:11
BuildsQueries::lazyChunk()
<?php
// usage
/** @var \Illuminate\Support\LazyCollection<Post> $lazyPosts */
$lazyPosts = Post::query()
->lazyChunk(100)
->tapEach(function (Collection $posts) {
$posts->load('author');
})
->collapse();