Skip to content

Instantly share code, notes, and snippets.

View grey-dev-0's full-sized avatar

Mohyaddin Alaoddin grey-dev-0

  • Trolley
  • Kuwait
  • 06:33 (UTC +03:00)
View GitHub Profile
@grey-dev-0
grey-dev-0 / reverse_file.php
Created November 3, 2016 06:50
[php] Reversing file lines
<?php
public function getWriteFile($reverse = false){
if(!$reverse){
$file = fopen('storage/test.out', 'a');
fwrite($file, date('Y-m-d h:i:s A')."\n");
fclose($file);
} else{
$unsorted = fopen('storage/test.out', 'r');
$sorted = fopen('storage/test.new', 'a');
$position = 0;
@grey-dev-0
grey-dev-0 / vqmod_create.php
Created March 15, 2017 11:30
vQmod xml creation and merge from git diff output
<?php
// Creates vQmod xml file from git diff output stored in a text file "git.txt"
// NOTE: Works only with SINGLE line changes.
$diffs = fopen('diffs.txt', 'r');
$modifications = "<modification>";
$fileIsOpen = $operationIsOpen = $searchIsOpen = false;
while($line = fgets($diffs)){
if(preg_match('/^diff --git ([^ ]+) ([^ ]+)/', $line, $files)){
if($operationIsOpen){
@grey-dev-0
grey-dev-0 / ratchet_command.php
Created January 25, 2018 10:30
Ratchet Laravel Command Handle
<?php
...
$server = IoServer::factory(
new HttpServer(
new WsServer(
new WebSocketController()
)
),
8090
);
@grey-dev-0
grey-dev-0 / ratchet_server_class.php
Created January 25, 2018 10:32
Ratchet Laravel Server Class
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Ratchet\Server\IoServer;
use Ratchet\Http\HttpServer;
use Ratchet\WebSocket\WsServer;
use App\Http\Controllers\WebSocketController;
class WebSocketServer extends Command
@grey-dev-0
grey-dev-0 / ratchet_controller.php
Created January 25, 2018 10:33
Ratchet Laravel Controller
<?php
namespace App\Http\Controllers;
use Ratchet\MessageComponentInterface;
use Ratchet\ConnectionInterface;
class WebSocketController extends Controller implements MessageComponentInterface{
private $connections = [];
/**
@grey-dev-0
grey-dev-0 / Category.php
Last active March 17, 2022 17:09
Dynamically setting Eloquent Model properties
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Category extends Model{
use DynamicModelProperties;
function subcategories(){
@grey-dev-0
grey-dev-0 / rendering.php
Last active July 24, 2019 07:09
Manually Rendering Laravel Mail Notification
<?php
// routes/web.php
Route::get(‘test-email’, function () {
$notification = new \App\Notifications\AppointmentReserved($notificationParameters);
$user = \App\User::find($userId);
// To run some inner configurations for the notification.
$notification->via($user);
$message = $notification->toMail($user);
// For setting the email template settings and theme.
@grey-dev-0
grey-dev-0 / README.md
Last active June 12, 2021 19:04
Bundling multiple vue components into several javascript files according to module / page schema

Bundling Vue single file components.

The shell script in this gist reads a json file - pages.json - which specifies pages structure of an existing web project, as multiple modules each of which includes several pages.

Each page specifies what vue components it uses, if the filename of a component ends with .js or .vue then it's considered a simple single file component, otherwise it would represent a complex component - which includes multiple components within -, in other words components whose filenames don't end with those extensions will be loaded from resources/components/{component name} directory, while single file components will be loaded as files from resources/components/{component name}.vue file.

The script expects the outputDir or vue's build directory to be set to resources/lib, as it will copy the minified build output from there to resources/bundles/{module name}/{page name}.js for each page specified in the pages.json file then, you can include those javascript files

@grey-dev-0
grey-dev-0 / webpack.mix.js
Created September 22, 2022 12:26
Basic Mix Config file
const mix = require('laravel-mix');
mix.options({
terser: {
extractComments: (astNode, comment) => false,
}
})
const glob = require('glob');
const path = require('path');
@grey-dev-0
grey-dev-0 / packages.json
Last active October 8, 2022 18:29
Basic Package JSON with Mix
{
"private": true,
"scripts": {
"development": "mix",
"watch": "mix watch",
"watch-poll": "mix watch -- --watch-options-poll=1000",
"hot": "mix watch --hot",
"production": "mix --production"
},
"dependencies": {