Skip to content

Instantly share code, notes, and snippets.

View jovialcore's full-sized avatar
👨‍🍳
cooking

Chidiebere Chukwudi jovialcore

👨‍🍳
cooking
View GitHub Profile
@jovialcore
jovialcore / lengdary_way_laravel_authenticates_spa.php
Last active May 6, 2024 18:35
legendary way laravel authenticates SPAs expecially with sanctum
<?php
namespace Illuminate\Foundation\Http\Middleware;
//legendary way laravel authenticates SPAs expecially with sanctum
// compare the hash_equals of the server session token (session value generated by hashing the user's password) with the cookie sent to the frontend
class VerifyCsrfToken
{
/**
@jovialcore
jovialcore / number_props_tip.vue
Last active April 29, 2024 11:13
Number props tip in vuejs
<script setup>
//So in vuejs 3, to declare an integer prop, ideally, you should declare an object passing the prop as an object key and the expected dataype as value for that key
const props = defineProps({ totalPages : Number})
//another tip: when in the parent component, to pass the value for that integer prop, vuejs expects it to be a dynamic prop binding
</script>
<template>
<!--- inside parent component -->
@jovialcore
jovialcore / apiResponseTrait.php
Created March 25, 2024 20:41
A reusable trait I use for returning api response.
<?php
namespace App\Traits;
use Illuminate\Http\JsonResponse;
trait ApiResponse
{
protected function success(array|object $data = [], string $message = '', int $code = 200): JsonResponse
@jovialcore
jovialcore / upload_media_to_azure_and_retrieve_blob_url.php
Created March 23, 2024 14:14
Upload media to azure blob storage and generate a media url
<?php
public function uploadToAzureCloud($request)
{
try {
$storageAccountName = config('services.azure_storage.account_name');
$containerName = config('services.azure_storage.container');
$accessKey = config('services.azure_storage.key');
<?php
// Function to create a shared access signature (SAS) token
private function getSasToken($accountName, $accountKey, $containerName)
{
$sasExpiry = time() + 3600; // Token expires in 1 hour
$sasResource = "https://$accountName.blob.core.windows.net/$containerName";
$sasString = utf8_encode(urlencode($sasResource) . "\n$sasExpiry");
$sig = base64_encode(hash_hmac('sha256', $sasString, base64_decode($accountKey), true));
@jovialcore
jovialcore / azure_setup_2.php
Last active March 22, 2024 09:51
Simple Azure Rest API code to upload to azure services
<?php
// Learn more : https://learn.microsoft.com/en-gb/archive/blogs/ptsblog/how-to-upload-a-blob-to-azure-storage-by-rest-api
try {
// Replace with your Azure storage account details
$accountName = 'your account name';
$accountKey = "Your Azure Storage account key
$containerName = 'Your container name';
$blobName = 'blob name'; // image.png
@jovialcore
jovialcore / Authcontroller.php
Last active March 17, 2024 18:55
my Login api controller setup for laravel 11
<?php
namespace App\Http\Controllers\Api;
use App\Http\Controllers\Controller;
use App\Models\User;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Hash;
@jovialcore
jovialcore / time_conversion.php
Created May 28, 2023 15:28
time conversion in 24 hrs hacker rank test
<?php
/*
* Complete the 'timeConversion' function below.
*
* The function is expected to return a STRING.
* The function accepts STRING s as parameter.
*/
function timeConversion($s) {
@jovialcore
jovialcore / php_post_curl_wrapper_class.php
Last active April 13, 2023 09:47
A php curl wrapper class that lets you make a post curl operation in a more elegant style.
<?php
class culrpost
{
protected $url;
protected $curl;
public $result;
@jovialcore
jovialcore / dependencyinjectionwithinterface.php
Last active March 7, 2023 14:43
dependency injection with interface
<?php
declare(strict_types=1);
namespace DemoPhpframework;
/**
* Dependency Injection from a bible Base Creation Example
*
* First what is Dependency Injection: