Skip to content

Instantly share code, notes, and snippets.

View msamgan's full-sized avatar
🏠
Working from home

Mohammed Samgan Khan msamgan

🏠
Working from home
View GitHub Profile
@msamgan
msamgan / SlugBehavior.php
Created February 21, 2019 10:18
Slug creating behavior CakePhp 3.x
<?php
namespace App\Model\Behavior;
use Cake\Datasource\EntityInterface;
use Cake\Event\Event;
use Cake\ORM\Behavior;
use Cake\Utility\Inflector;
use Cake\ORM\Table;
/**
@msamgan
msamgan / LoggerBehavior.php
Created February 21, 2019 10:21
Log data at event, behaviour CakePhp3.x
<?php
namespace App\Model\Behavior;
use Cake\Datasource\EntityInterface;
use Cake\Event\Event;
use Cake\Log\Log;
use Cake\ORM\Behavior;
use Cake\ORM\Table;
/**
@msamgan
msamgan / import.php
Last active September 1, 2019 07:59
CSV Importer in PHP ( run via terminal)
<?php
/**
* importer for CSV in MySQL DB.
* pleas keep tje CSV file in the same directory and run :
*
* > php ./import.php
*/
$host = "localhost"; // Host name.
$db_user = "root"; //mysql user
@msamgan
msamgan / change.js
Created June 8, 2022 06:20
write a program that will be used in a vending machine to return change
/**
* Problem Statement:
*
* A vending machine has the following denominations: 1c, 5c, 10c, 25c, 50c, and $1.
* Your task is to write a program that will be used in a vending machine to return change.
* Assume that the vending machine will always want to return the least number of coins or notes.
* Devise a function getChange (M, P)
* where M is how much money was inserted into the machine and P the price of the item selected,
* that returns an array of integers representing the number of each denomination to return.
*
<?php
/**
* * Problem Statement:
* * passing a floating point number to a function, the function will round the number to
* * the nearest point five and return the result.
*
* * Example:
* * roundUpToNextFive(3.7) // returns 4.0
* * roundUpToNextFive(3.3) // returns 3.5
@msamgan
msamgan / EditorJs.php
Created July 10, 2024 22:20
Efficiently parse and handle Editor.js content in your PHP applications with this Editor JS Parser Class. Easily convert JSON data into structured HTML
class EditorJs
{
/*
* third party plugins:
* - youtubeEmbed (https://github.com/yuanwei92/editorjs-youtube-embed)
* - inline image (https://www.npmjs.com/package/editorjs-inline-image)
* */
public function parse($content): string
{