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 / 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 / force-file-download.php
Created September 19, 2013 07:24
Force file download using PHP
<?php
function download_file($file){
$file = $file; //Set File Location
if (file_exists($file)) { // Check if file exists
if(!is_dir($file)){ // Check if it is a directory or a file
// The following files will set the headers to the file download
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename($file));
header('Content-Transfer-Encoding: binary');
@aslamdoctor
aslamdoctor / validate-username.js
Created September 19, 2013 07:25
Validate Username using Javascript
function validateUsername(str) {
var error = "";
var illegalChars = /\W/; // allow letters, numbers, and underscores
if (str == "") {
error = "&bull; Please enter Username<br>";
} else if ((str.length < 5) || (str.length > 15)) {
error = "&bull; Username must have 5-15 characters<br>";
} else if (illegalChars.test(str)) {
error = "&bull; Please enter valid Username. Use only numbers and alphabets<br>";
@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 / bootstrap3-mediaqueries.css
Last active November 26, 2015 11:50
Bootstrap 3 Media Queries
/*==================================================
= Bootstrap 3 Media Queries =
==================================================*/
/*========== Mobile First Method ==========*/
/* Custom, iPhone Retina */
@media only screen and (min-width : 320px) {
/*-- example usage : custom grid spacing --*/
.row{
@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 / 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 / perfectcontroller.php
Created August 19, 2017 03:42
Boilerplate code for HMVC Controller file
<?php if (!defined('BASEPATH')) {
exit('No direct script access allowed');
}
class Perfectcontroller extends MX_Controller
{
function __construct()
{
parent::__construct();