Skip to content

Instantly share code, notes, and snippets.

View ajaxray's full-sized avatar
🪁
Exploring

Anis uddin Ahmad ajaxray

🪁
Exploring
View GitHub Profile
@ajaxray
ajaxray / MediaPropertyService.php
Last active March 25, 2024 09:01
[Laravel] Sorting Media Collection of Spacie Media Library by a custom property.
<?php
namespace App\Services;
use Illuminate\Support\Collection;
use Spatie\MediaLibrary\HasMedia;
use Spatie\MediaLibrary\MediaCollections\Models\Media;
class MediaPropertyService
{
@ajaxray
ajaxray / ZipDirectory.php
Created March 23, 2024 08:36
Make Zip Archive of a directory (including all files in it recursively) in PHP
<?php
namespace App\Services;
class ZipDirectory
{
public function __construct(
private string $sourcePath,
private ?string $outputPath = null,
)
@ajaxray
ajaxray / dokan.sql
Created November 17, 2023 14:50
[Database Course] Sample schema
CREATE DATABASE `dokan`;
USE `dokan`;
CREATE TABLE customers (
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(100) NOT NULL,
email VARCHAR(100),
phone CHAR(15),
PASSWORD CHAR(32),
created_at DATETIME DEFAULT CURRENT_TIMESTAMP
@ajaxray
ajaxray / php-pecl-linux-mac.md
Last active December 21, 2023 15:47
How to install PHP pecl extensions in Linux and MacOS

Install PHP pecl extensions in Linux and MacOS

Very few easy steps -

  • Download desired package from http://pecl.php.net/packages.php
  • Extract the tar - tar xzf gearman-X.Y.tgz
  • Enter into extracted directory from terminal - cd path/to/gearman-X.Y
  • Run the following commands -
@ajaxray
ajaxray / 1_Typora_Callout.md
Last active December 12, 2023 13:12
Making Notion style callout in Typora using custom CSS

Making Notion style callout in Typora using custom CSS

Do you want this type of callouts in typora? CleanShot 2022-12-03 at 19 02 01@2x

It's simple.

  • Copy the contents of callout.css at the bottom of your user base.user.css file.
    • You'll the find the base.user.css in typora theme folder. (Preference > Appearance > "Open theme folder")
  • If no base.user.css file is found in that folder, create one.
@ajaxray
ajaxray / docker-compose.yml
Created November 15, 2023 08:56
[Database Course] MySQL 8.2 with Adminer
version: '3.7'
services:
db_course_mysql:
image: mysql:8.2
command: --default-authentication-plugin=mysql_native_password
environment:
MYSQL_ROOT_PASSWORD: 123123
ports:
- 3309:3306
volumes:
@ajaxray
ajaxray / REST_with_curl.md
Last active September 6, 2023 18:51
Testing a REST API with curl

Testing REST API using curl

This gist lists only the basic commands to test REST APIs with curl. If you need something more advanced, this book has everything you may need.

Simple GET Requests

Display the response only

@ajaxray
ajaxray / SomeClassTest.php
Last active July 4, 2023 16:30
PHP mocking built-in functions (e,g exec, file_exists etc.) for testing
<?php
/**
* Example of mocking built-in functions for testing
*
* @Author : ajaxray <anis.programmer@gmail.com>
* @Date-Time : 03/05/2017
*
* How it works?
* ----------------
* Simply by redefining the function for target Namespace.
@ajaxray
ajaxray / CreateUser.php
Last active June 11, 2023 15:14
A Laravel Artisan command for creating user with name, email and password
<?php
namespace App\Console\Commands;
use App\Models\User;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Validator;
class CreateUser extends Command
{
@ajaxray
ajaxray / mysqldump_to_mega.sh
Last active May 21, 2023 23:49
Backup MySQL database to MEGA.nz cloud storage
#!/bin/bash
# ----------------------------------------------------
# A Shell script to take MySql database backup
# and upload to MEGA cloud storage using megatools
# ----------------------------------------------------
# REQUIREMENTS : You should have -
# 1. Registered and verified MEGA account - https://mega.nz/
# 2. Installed megatools - https://github.com/megous/megatools
# ----------------------------------------------------