Skip to content

Instantly share code, notes, and snippets.

View Ghostscypher's full-sized avatar

Brian Ngetich Ghostscypher

View GitHub Profile
@Ghostscypher
Ghostscypher / grid_path.php
Created December 24, 2023 06:08
Grid Path problem
<?php
require_once __DIR__ . "/include.php";
// This shows how many ways we can go from the top left corner to the bottom right corner in a M x N grid
function grid_paths($m, $n)
{
// Use memoization to avoid repeated calculations
$memo = [];
@Ghostscypher
Ghostscypher / how_many_ways.php
Last active December 24, 2023 05:27
This get the number of ways you can count an array of integers given the sum
<?php
// This shows how many ways we can arrive at the amount using the given coins
function how_many_ways($m, $coins)
{
// Use memoization to avoid repeated calculations
$memo = [];
$memo[0] = 1;
$chain = [];
@Ghostscypher
Ghostscypher / min_coins.php
Last active December 23, 2023 19:53
This is a quick code for min number of coins problem, solved using dynamic programming.
<?php
function min_coins($m, $coins)
{
// Use memoization to avoid repeated calculations
$memo = [];
$memo[0] = 0;
for($i = 1; $i <= $m; $i++)
{
@Ghostscypher
Ghostscypher / Oauth2ServerProvider.php
Created February 2, 2022 12:28
Socialite provider in Client app
<?php
namespace App\Socialite;
use Laravel\Socialite\Two\AbstractProvider;
use Laravel\Socialite\Two\ProviderInterface;
use Laravel\Socialite\Two\User;
use Illuminate\Support\Arr;
class Oauth2ServerProvider extends AbstractProvider implements ProviderInterface
@Ghostscypher
Ghostscypher / web.php
Created February 2, 2022 12:22
Client app web.php
<?php
use App\Http\Controllers\AuthController;
use Illuminate\Support\Facades\Route;
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
@Ghostscypher
Ghostscypher / register.blade.php
Created February 2, 2022 12:21
Client app register blade
@extends('layout.layout')
@section('content')
<form action="{{route('register.post')}}" method="POST">
@csrf
@error('success')
<div class="success">
{{$message}}
</div>
@Ghostscypher
Ghostscypher / login.blade.php
Created February 2, 2022 12:20
Client app login blade
@extends('layout.layout')
@section('content')
<form action="{{route('login.post')}}" method="POST">
@csrf
@error('success')
<div class="success">
{{$message}}
</div>
<br><br>
@Ghostscypher
Ghostscypher / web.php
Created February 2, 2022 12:17
Oauth2-Server app web.php
<?php
use App\Http\Controllers\AuthController;
use Illuminate\Support\Facades\Route;
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
@Ghostscypher
Ghostscypher / AuthController.php
Created February 2, 2022 12:14
Oauth2-Server app AuthController
<?php
namespace App\Http\Controllers;
use App\Models\User;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Hash;
class AuthController extends Controller
{
@Ghostscypher
Ghostscypher / layout.blade.php
Created February 2, 2022 12:13
Layout blade shared between Oauth2-Server app and the Client app
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>