Skip to content

Instantly share code, notes, and snippets.

@houssenedao
houssenedao / laravel-fastcgi-cache-config.md
Created July 3, 2024 10:19 — forked from murdercode/laravel-fastcgi-cache-config.md
Optimizing Laravel (and Nova) with FastCGI Cache Configuration

Laravel + FastCGI Cache = ❤️

⚠️ Need a more specific guide? See https://medium.com/@murdercode/speed-up-your-laravel-application-up-to-1000x-with-fastcgi-cache-0135b11407e5

Using FastCGI cache allows you to speed up your website up to 1000x. In fact, the FastCGI cache (or Varnish) mechanism consists of putting a server-caching mechanism between a client and your web server. The whole page will be cached as an HTML output, and it will be delivered instead of using the PHP/MySQL/Redis stack, etc. for all users, but only for the first visit (and others after some specified time).

WARNING: This is not a take-away how-to. Please read it carefully and use it at your own risk.

This config is based on the ploi.io stack. We will not cover the FastCGI installation process, so please prepare FastCGI and adapt the next config if you need it.

@houssenedao
houssenedao / license-plate
Created June 19, 2024 21:36
New Côte d'Ivoire license plate regex
^[A-Z]{2}-[0-9]{3}-[A-Z]{2}
@houssenedao
houssenedao / prisma.uow.ts
Created February 13, 2024 15:41
Unit of work pattern with prisma
import { Injectable } from '@nestjs/common';
import { PrismaClient } from '@prisma/client';
import { DefaultArgs, PrismaClientOptions } from '@prisma/client/runtime/library';
import { PrismaService } from '@shared/infrastructure/services';
import { LoggerServicePort, UnitOfWorkPort } from '@shared/infrastructure/ports';
import { ClsService } from 'nestjs-cls';
type TransactionFn = Parameters<PrismaClient['$transaction']>[0];
type TransactionOptions = Parameters<PrismaClient['$transaction']>[1];
@houssenedao
houssenedao / partialMatch.js
Created February 4, 2024 19:28 — forked from stewartmcgown/partialMatch.js
Partial Match properties of Object Array (ES6)
/**
* Are all the values on p present on o
* @param {Object} o object to search
* @param {Object} p object of search values
* @param {Boolean} [c] are loose equality matches ok?
* @return {Boolean} whether there are partial matches
*/
const partialMatch = (o, p, c) =>
Object.keys(p).every(k =>
p[k] && o[k]
@houssenedao
houssenedao / double-entry-accounting.ts
Last active February 13, 2024 15:44
double-entry accounting
class Account {
// The name of the account
name: string;
// The type of the account (e.g. asset, liability, etc.)
type: string;
// The balance of the account
balance: number;
@houssenedao
houssenedao / circuit-breaker.php
Last active February 13, 2024 15:43
Circuit breaker php
<?php
// The circuit breaker class
class CircuitBreaker
{
// The failure threshold
private $failureThreshold;
// The failure count
private $failureCount = 0;
@houssenedao
houssenedao / key-match.ts
Created January 24, 2022 12:57
Retrieve merchant name
function findMerchant(description: string): string | undefined {
const Merchants = {
Facebook: "fcbk,facebook,fb,facebk",
Netflix: "netflix,nl",
Tinder: "tinder,gotinder",
Amazon: "amzn,amazon",
Glovo: "glovo"
};
const merchantsKeys = Object.keys(Merchants);
@houssenedao
houssenedao / regex
Created November 16, 2021 09:18
Cote d'ivoire mobile phone number regex validation
/^\+225\d(?:0|1|5|7)\d{8}$/
@houssenedao
houssenedao / cinetpay.service.ts
Last active November 16, 2021 09:16
Nestjs - CinetPayService
import { Injectable, InternalServerErrorException, Logger } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import { HttpRequestService } from './http-request.service';
interface ICinetpayConfig {
apikey: string;
siteId: string;
lang?: string;
currency?: string;
channels?: PaymentChannel;
@houssenedao
houssenedao / BowValetDriver.php
Last active January 24, 2023 02:30
Laravel valet driver for Bow framework
<?php
class BowValetDriver extends ValetDriver
{
/**
* Determine if the driver serves the request.
*
* @param string $sitePath
* @param string $siteName
* @param string $uri