Skip to content

Instantly share code, notes, and snippets.

View ahsankhatri's full-sized avatar

Ahsan Muhammad Yousuf ahsankhatri

View GitHub Profile
@ahsankhatri
ahsankhatri / web.php
Created August 9, 2018 08:30
Preview Mailable in Browser Laravel 5.4
Route::get('/preview-mail', function () {
$mail = (new \App\Mail\ShareItenraryTripStarted())->build();
$mocked = new \ReflectionMethod($mail, 'buildView');
$mocked->setAccessible(true);
return $mocked->invoke($mail)['html'];
});
@ahsankhatri
ahsankhatri / webComposer.php
Created October 2, 2016 19:35
Run composer update/install in browser.
<?php
// This is just a sample code, do not use it on production as this is insecure
// For security, you may use .htaccess IP Access or HTTP Basic Aauthentication
require 'vendor/autoload.php';
$allowedCommands = [
'update',
'install',
'dump-autoload',
@ahsankhatri
ahsankhatri / README.md
Last active February 10, 2022 18:29
Database Driven Routes Laravel 5.2

Database Driven Routes Laravel 5.2

Table: url_alias

+----+-----------------+-------------------------------------------+-----------------+-----------+------------+
| id | slug            | map_to                                    | params          | http_verb | middleware |
+----+-----------------+-------------------------------------------+-----------------+-----------+------------+
| 1  | page/about-us   | Frontend\HomeController@showPage          | a:1:{i:0;i:4;}  | GET       | web        |
| 2  | page/contact-us | Backend\DashboardController@getContactUs  | a:1:{i:0;i:4;}  | GET       | web        |

| 3 | page/contact-us | Backend\DashboardController@postContactUs | | POST | web |

@ahsankhatri
ahsankhatri / powerOfTwo.php
Created February 6, 2017 07:32
Check if number is a power of 2
<?php
function isPowerOfTwo($num)
{
return ($num > 0) && (($num & ($num - 1)) == 0);
}
// var_dump(4);
// var_dump(5);
// var_dump(6);
@ahsankhatri
ahsankhatri / autorun.cmd
Last active March 14, 2019 10:11
Make windows command prompt user-friendly.
@echo off
:: Aliases
DOSKEY reload = %USERPROFILE%\autorun.cmd
DOSKEY editalias = "C:\Program Files\Sublime Text 3\subl.exe" %USERPROFILE%\autorun.cmd
DOSKEY www = cd /d C:\xampp\htdocs
DOSKEY sdf = cd /d D:\Ahsaan\Songs
DOSKEY sbcd = cd /d D:\scripts\python\sevenbridges\sevenbridges
DOSKEY sbenv = D:\scripts\python\sevenbridges\venv\Scripts\activate.bat
:: DOSKEY sbinit = DOSKEY sbcd && DOSKEY sbenv && DOSKEY flask run
@ahsankhatri
ahsankhatri / README.md
Created February 2, 2017 10:12
Install Ruby, Gem & Mailcatcher in Cygwin (Windows)

Install Ruby, Gem & Mailcatcher in Cygwin (Windows)

  1. Install Cygwin (http://www.cygwin.com/)
  • Select the folowing packages: curl, git, nano, openssh, openssl, unzip, util-linux, vim, wget
  1. Install Ruby (https://rubyinstaller.org/downloads/)
  • Download and install ruby.
  • Make sure you've ammend PATH in environment variable
  • Verify in Cygwin by closing and starting cygwin then type: echo $PATH
  • Make sure you got /cygdrive/c/Ruby22/bin (according to your path)
@ahsankhatri
ahsankhatri / README.md
Last active August 14, 2018 03:40
Laravel 5.0~5.4 Webservice Logger. Log all request and response through middleware in wrapped routes

Webservice Logger for Laravel 5.0~5.4 (Haven't tested on 5.5+)

Log all request and response through middleware in api wrapped group routes.

Guide

wrap middleware in api group in app/Http/Kernel.php

    'api' => [
        'throttle:60,1',

\App\Http\Middleware\WebserviceLogger::class,

@ahsankhatri
ahsankhatri / web.php
Created August 9, 2018 09:31
Preview Notifications (Email) in Browser Laravel 5.4
Route::get('/preview-mail', function () {
$user = User::first();
$mail = (new \App\Notifications\Api\Registration($user))->toMail('random@domain.com');
$markdown = new \Illuminate\Mail\Markdown(view(), config('mail.markdown'));
return $markdown->render('vendor.notifications.email', $mail->toArray());
});
@ahsankhatri
ahsankhatri / show_ip.sh
Last active March 6, 2018 20:37
A function to display and parse local or remote ip address (Mac, Linux & Win (cygwin) supported)
# View IP Address
myip() {
if [ -z "$1" ] || [ "$1" == "--help" ]; then
echo "Usage: myip OPTION
OPTIONS:
--remote displays remote (internet) IP Address
--local displays local IP Address(s)
--help display this help and exit
";
@ahsankhatri
ahsankhatri / keybase.md
Created April 17, 2017 23:34
Verifying github profile in keybase. Ignore please :)

Keybase proof

I hereby claim:

  • I am ahsankhatri on github.
  • I am ahsankhatri (https://keybase.io/ahsankhatri) on keybase.
  • I have a public key ASBBH8VLB95fgZnSAwPkChWmRyODSGXcw3N44y2VMk7aDQo

To claim this, I am signing this object: