Skip to content

Instantly share code, notes, and snippets.

View ahsankhatri's full-sized avatar

Ahsan Muhammad Yousuf ahsankhatri

View GitHub Profile
@ahsankhatri
ahsankhatri / SkypeChats.php
Created March 28, 2016 22:05
Read your Skype chats with the help of PHP PDO Driver
<?php
// replace ahsanyousuf with your users
$dbPath = '/Users/ahsan/Library/Application Support/Skype/ahsanyousuf/main.db';
$db = new PDO( 'sqlite:' . $dbPath );
$db->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
$query = 'SELECT id, author, dialog_partner, body_xml, timestamp, datetime( timestamp, \'unixepoch\', \'localtime\') as actualTime
FROM Messages
ORDER BY timestamp DESC
@ahsankhatri
ahsankhatri / example.php
Created August 1, 2016 07:34
Simple and elegant way to attach hooks in your application
<?php
// Example 1:
Event::bind('blog.post.create', array(new BlogTriggers, 'onPostCreate'));
// Trigger for Example 1
Event::trigger('blog.post.create', [
'name' => 'My 123rd Post on Blog',
'id' => '123',
]);
@ahsankhatri
ahsankhatri / Example.php
Created August 1, 2016 08:43
Alter/Modify global functions return value as per need without touching your code with just one variable
<?php
namespace {
// This allow us to configure the behavior of the "global mock"
$mockSocketCreate = false;
include_once './SomeClass.php';
/*$dummy = new \My\Nice\Namezpace\SomeClass;
var_dump($dummy->doSomething());*/
@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 / php-magic.php
Last active October 1, 2016 09:11
Analyze called function with non-standard php feature to enhance functionality on expected result by caller-identifier
<?php
echo ''; /* sdfds */ echo ''; ;; ! phpMagic(); // echo $i; ?> <?php
;;; +phpMagic(); // $increment with 1;
@phpMagic(); // $increment with 1;
/* $decrement with 1 ;;; */-phpMagic();// $decrement with 1;
/* comment ;;; */ \phpMagic(); /* another comment ;;; */ \phpMagic(); // $decrement with 1;
function phpMagic() {
$poped = array_pop(debug_backtrace());
$fullLine = file($poped['file'])[$poped['line']-1];
@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 / 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 / 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
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 / 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)