Skip to content

Instantly share code, notes, and snippets.

View avosalmon's full-sized avatar

Ryuta Hamasaki avosalmon

View GitHub Profile
<?php
namespace App\Services;
use UnexpectedValueException;
use Firebase\JWT\JWT;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Str;
@avosalmon
avosalmon / firebase_token.rb
Last active June 3, 2024 00:04
Verify Firebase auth JWT token
require 'base64'
require 'httparty'
require 'jwt'
class FirebaseToken
JWT_ALGORITHM = 'RS256'.freeze
PUBLIC_KEY_URL = 'https://www.googleapis.com/robot/v1/metadata/x509/[email protected]'.freeze
def initialize(token)
@token = token
@avosalmon
avosalmon / iTerm2_profiles.plist
Last active June 20, 2019 07:48
Put this file into ~/Library/Application Support/iTerm2/DynamicProfiles
{
"Profiles": [
{
"Working Directory": "/Users/ryuta",
"Prompt Before Closing 2": 0,
"Selected Text Color": {
"Green Component": 0.5648583769798279,
"Blue Component": 0.5636365413665771,
"Red Component": 0.5059919357299805
},
<?php
class OrderServiceProvider extends ServiceProvider
{
public function register()
{
$this->app->bind(OrderProcessor::class, function ($app) {
new OrderProcessor(
[
new OrderHasAmount,
@avosalmon
avosalmon / OrderProcessor_Refactored.php
Created May 6, 2019 23:41
OrderProcessor class after refactoring.
<?php
class OrderProcessor
{
public function __construct(array $validators, OrderNotificationInterface $notification) {
$this->$validators = $validators;
$this->notification = $notification;
}
public function process(Order $order)
<?php
interface OrderValidationInterface
{
public function validate(Order $order) : void;
}
class OrderHasAmount implements OrderValidationInterface
{
public function validate(Order $order) : void
<?php
interface OrderNotificationInterface
{
public function notify(Order $order) : void;
}
class SlackNotification implements OrderNotificationInterface
{
public function __construct(Slack $slack) {
<?php
class OrderProcessor
{
public function __construct(Slack $slack) {
$this->slack = $slack;
}
public function process(Order $order)
{
require 'minitest/autorun'
class Matrix
# @param {Integer[][]} matrix
# @return {Boolean}
def toeplitz?(matrix)
return false if square?(matrix)
matrix.each_with_index do |row, row_index|
@avosalmon
avosalmon / helpers.php
Last active October 20, 2019 15:58
Get CDN asset URL
<?php
if (! function_exists('asset_path')) {
/**
* Get the path to a versioned Mix file.
*
* @param string $path
* @param string $manifestDirectory
* @return \Illuminate\Support\HtmlString|string
*