Skip to content

Instantly share code, notes, and snippets.

View ahsankhatri's full-sized avatar

Ahsan Muhammad Yousuf ahsankhatri

View GitHub Profile
@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 / 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 / parameters.regex
Created February 18, 2015 09:54
Regular Expression for search CI & Native parameter in files. i.e: _GET _POST _REQUEST input->post() input->get() input->get_post() form_validation set_rules.
(this(?:\s+)?->(?:\s+)?(?:input|form_validation)(?:\s+)?->(?:\s+)?(?:get_post|get|post|set_rules)(?:\s+)?\((?:\s+)?(?:'|\")(?<param>[^'\"]+)(?:'|\")(?:.*?)?(?:\s+)?\)|_(?:REQUEST|GET|POST)(?:\s+)?\[(?:\s+)?(?:'|\")(?J)(?<param>.+?)(?:'|\")(?:\s+)?\])
@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 / file.php
Last active August 1, 2016 07:49
List all declared/defined variables with-in scope.
<?php
print_r( array_diff_key( get_defined_vars(), array_flip(array('_GET','_SERVER','_POST','_COOKIE','_FILES'))) );
@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 / 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
{
"auto_complete_selector": "source, text",
"color_scheme": "Packages/Color Scheme - Default/Monokai.tmTheme",
"font_face": "Monaco",
"font_options": "subpixel_antialias",
"font_size": 10,
"highlight_line": true,
"highlight_modified_tabs": true,
"ignored_packages":
[
@ahsankhatri
ahsankhatri / service_status_code.js
Last active January 11, 2016 10:00
HTTP Code status as a service
var http = require('http');
http.createServer(function (request, response) {
var status = request.url.substr(1);
if ( ! http.STATUS_CODES[status]) {
status = '404';
}
response.writeHead(status, { 'Content-Type': 'text/plain' });
@ahsankhatri
ahsankhatri / css-debug.js
Last active August 29, 2015 14:22
[JS] Find body overflow element..
/*
* Reference: https://css-tricks.com/findingfixing-unintended-body-overflow/
* Uses: Run it on console..
*/
var docWidth = document.documentElement.offsetWidth;
[].forEach.call(
document.querySelectorAll('*'),
function(el) {