Skip to content

Instantly share code, notes, and snippets.

View aslamdoctor's full-sized avatar
💭
Always working but happy to talk 👍

Aslam Doctor aslamdoctor

💭
Always working but happy to talk 👍
View GitHub Profile
@aslamdoctor
aslamdoctor / generate-csv.php
Created September 19, 2013 07:20
Generate CSV file from Array using PHP
<?php
function generateCsv($data, $delimiter = ',', $enclosure = '"') {
$handle = fopen('php://temp', 'r+');
foreach ($data as $line) {
fputcsv($handle, $line, $delimiter, $enclosure);
}
rewind($handle);
while (!feof($handle)) {
$contents .= fread($handle, 8192);
}
@aslamdoctor
aslamdoctor / crop-image.php
Created September 19, 2013 07:22
Crop Image and Display it using PHP
<?php
$filename= "my_picture.jpg";
list($w, $h, $type, $attr) = getimagesize($filename);
$src_im = imagecreatefromjpeg($filename);
$src_x = '0'; // begin x
$src_y = '0'; // begin y
$src_w = '100'; // width
$src_h = '100'; // height
$dst_x = '0'; // destination x
@aslamdoctor
aslamdoctor / credit-card-validation.js
Created September 19, 2013 07:25
Easy Credit Card validation using Javascript
function isValidCreditCard(type, ccnum) {
if (type == "Visa") {
// Visa: length 16, prefix 4, dashes optional.
var re = /^4\d{3}-?\d{4}-?\d{4}-?\d{4}$/;
} else if (type == "MC") {
// Mastercard: length 16, prefix 51-55, dashes optional.
var re = /^5[1-5]\d{2}-?\d{4}-?\d{4}-?\d{4}$/;
} else if (type == "Disc") {
// Discover: length 16, prefix 6011, dashes optional.
var re = /^6011-?\d{4}-?\d{4}-?\d{4}$/;
@aslamdoctor
aslamdoctor / useful-htaccess-code
Created September 19, 2013 07:44
Set of some useful Htaccess file code
301 Redirects
Redirect 301 /oldpage.html http://www.yoursite.com/newpage.html
Redirect 301 /oldpage2.html http://www.yoursite.com/folder/
-------------------------------------------------------------
Custom Error Pages
ErrorDocument 400 /400.html
@aslamdoctor
aslamdoctor / disable-wordpress-notifications.php
Created October 10, 2013 08:58
Disable update notifications in wordpress
<?php
function hide_update_notice_to_all_but_admin_users()
{
if (!current_user_can('update_core')) {
remove_action( 'admin_notices', 'update_nag', 3 );
}
}
add_action( 'admin_notices', 'hide_update_notice_to_all_but_admin_users', 1 );
?>
@aslamdoctor
aslamdoctor / MY_Loader.php
Created August 19, 2017 02:14
Codeigniter HMVC Fix
<?php (defined('BASEPATH')) OR exit('No direct script access allowed');
/* load the MX_Loader class */
require APPPATH."third_party/MX/Loader.php";
class MY_Loader extends MX_Loader
{
/** Load a module view **/
public function view($view, $vars = array(), $return = FALSE)
{
@aslamdoctor
aslamdoctor / MY_Model.php
Created August 20, 2017 16:21
Base Model for CodeIgniter
<?php if (!defined('BASEPATH')) {
exit('No direct script access allowed');
}
class My_Model extends CI_Model
{
public $tablename;
function __construct()
{
@aslamdoctor
aslamdoctor / mdl_perfectmodel.php
Last active August 20, 2017 16:26
Boilerplate code for HMVC Model file
<?php if (!defined('BASEPATH')) {
exit('No direct script access allowed');
}
class Mdl_perfectmodel extends MY_Model
{
function __construct()
{
parent::__construct();
$this->tablename = 'mytablename';
@aslamdoctor
aslamdoctor / .htaccess
Created August 22, 2017 06:47
Codeigniter .htaccess file
Options +FollowSymLinks
Options -Indexes
DirectoryIndex index.php
RewriteEngine On
RewriteCond $1 !^(index\.php|images|rebots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
@aslamdoctor
aslamdoctor / CI HMVC Setup
Last active August 28, 2017 06:14
Codeigniter HMVS Setup Steps
1. Download CI
2. Download HMVC extension from
https://bitbucket.org/wiredesignz/codeigniter-modular-extensions-hmvc
3. Download MY_Loader.php and place it under 'core' folder as it is a fix for a small bug in HMVC extension.
https://gist.github.com/aslamdoctor/387fa9ef6ba0f74f20e7fad793dafb1f
4. Download MY_Model.php and place it under 'core' folder
https://gist.github.com/aslamdoctor/cf592175987d042de9a667ac49f40f5c