Skip to content

Instantly share code, notes, and snippets.

View ahsankhatri's full-sized avatar

Ahsan Muhammad Yousuf ahsankhatri

View GitHub Profile
@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 / 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 / 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 / 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:

@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 / 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
Created December 7, 2016 09:45
Cygwin Custom Prompt (virtualenv supported)

Step 1

  • Edit ~/.bash_profile and overwrite the variable
export PS1="\[\e]0;\w\a\]\n> \[\e[32m\]\u \e\e[0m\]in \[\e[33m\]\w\[\e[0m\] » \[\e[36m\]\@\n\e[m\$ "

Step 2 (Optional)

  • Edit virtualenv/Scripts/activate
@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 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 / 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 |