Skip to content

Instantly share code, notes, and snippets.

View digvijay1985's full-sized avatar

Digvijay G digvijay1985

  • Lucknow, U.P. India
View GitHub Profile
@digvijay1985
digvijay1985 / force-download.php
Created December 15, 2016 06:27
Force Download
<?php
// grab the requested file's name
$file_name = $_GET['file'];
// make sure it's a file before doing anything!
if(strpos($file_name, '.pdf')) {
// required for IE
if(ini_get('zlib.output_compression')) { ini_set('zlib.output_compression', 'Off'); }
@digvijay1985
digvijay1985 / create-log-using-php.php
Created June 17, 2016 10:50
Create Readable Log using PHP
function _logFile($filename,$heading,$array)
{
$file=fopen($filename, "a+");
if(count(file($filename))==0)
{
$string=implode("\t | \t",array_keys($array));
fwrite($file,"\n".$heading);
fwrite($file,"\n".str_repeat("-",strlen($string)+62));
fwrite($file,"\n".$string);
fwrite($file,"\n".str_repeat("-",strlen($string)+62));
@digvijay1985
digvijay1985 / jquery-element-exits-or-not.js
Created June 17, 2016 10:43
jQuery validate element exist or not
function _isset(fieldName)
{
return jQuery("[name='"+fieldName+"']").length==1 && jQuery("[name='"+fieldName+"']").val()!="";
}
// For Input,Textarea,Select
function _issetDate(fieldName)
{
return jQuery("[name='"+fieldName+"']:eq(1)").length==1 && jQuery("[name='"+fieldName+"']:eq(1)").val()!="";
}
@digvijay1985
digvijay1985 / wp-child-pages-widget.php
Created June 17, 2016 10:34
Wordpress Child Pages List Widget
<?php
add_action( 'widgets_init', array ( 'CPP_Widget', 'register' ) );
class CPP_Widget extends WP_Widget
{
/**
* Constructor.
*/
public function __construct()
{
<?php
class DBManager {
private $selectables = array();
private $table;
private $whereClause;
private $limit;
public function select(){
$this->selectables = func_get_args();
return $this;
@digvijay1985
digvijay1985 / slide-remove-add.html
Last active May 23, 2016 16:34
JQuery Slide Item and Remove Item and Append Item
<body>
<script type="text/javascript" src="https://code.jquery.com/jquery-1.12.4.min.js" integrity="sha256-ZosEbRLbNQzLpnKIkEdrPv7lOy9C27hHQ+Xp8a4MxAQ=" crossorigin="anonymous"></script>
<style type="text/css">
#userlist {overflow: hidden; height: 40px; background: orange;}
#userlist li{display: block; background:white; height: 40px; margin: 1px 0px;}
</style>
<ul id="userlist">
<li>Item 1</li>
<li>Item 2</li>
</ul>
@digvijay1985
digvijay1985 / slide-and-remove.html
Last active May 23, 2016 16:31
jQuery Slide and Remove Items one by one
<script type="text/javascript" src="https://code.jquery.com/jquery-1.12.4.min.js" integrity="sha256-ZosEbRLbNQzLpnKIkEdrPv7lOy9C27hHQ+Xp8a4MxAQ=" crossorigin="anonymous"></script>
<style type="text/css">
#userlist {overflow: hidden; height: 40px; background: orange;}
#userlist li{display: block; background:white; height: 40px; margin: 1px 0px;}
</style>
<ul id="userlist">
<li>Item 1</li>
<li>Item 2</li>
</ul>
<!--button id="myButton">Button</button-->
@digvijay1985
digvijay1985 / static-map-with-jquery.js
Last active May 21, 2016 14:57
Static Google Map with JQuery
function mapImage(lat,lng,element,icon,fa)
{
var width=parseInt(parseInt(jQuery('#'+element).css('width'))/2);
var height=parseInt(parseInt(jQuery('#'+element).css('height'))/2);
var imgURL='https://maps.googleapis.com/maps/api/staticmap?center='+lat+','+lng+'&zoom=14&maptype=roadmap&markers=icon:'+icon+'&scale=2&size='+width+'x'+height+'&key=';
//console.log(imgURL);
jQuery('#'+element).css('background-image',"url('"+imgURL+"')");
jQuery('#'+element).css('background-repeat',"no-repeat");
jQuery('#'+element).css('background-position',"center center");
jQuery('#'+element).css('background-size',"cover");
@digvijay1985
digvijay1985 / zipcode-validation-for-countries.php
Created April 2, 2015 18:32
Postal Code or ZIP Code Validation for different countries.
<?php
$country_code="US";
$zip_postal="11111";
$ZIPREG=array(
"US"=>"^\d{5}([\-]?\d{4})?$",
"UK"=>"^(GIR|[A-Z]\d[A-Z\d]??|[A-Z]{2}\d[A-Z\d]??)[ ]??(\d[A-Z]{2})$",
"DE"=>"\b((?:0[1-46-9]\d{3})|(?:[1-357-9]\d{4})|(?:[4][0-24-9]\d{3})|(?:[6][013-9]\d{3}))\b",
"CA"=>"^([ABCEGHJKLMNPRSTVXY]\d[ABCEGHJKLMNPRSTVWXYZ])\ {0,1}(\d[ABCEGHJKLMNPRSTVWXYZ]\d)$",
@digvijay1985
digvijay1985 / date-array-with-function.php
Last active August 29, 2015 14:18
using function to manipulate array original values
<?php
echo "<pre>";
$post=array('dob'=>'28-04-2015','doj'=>'4th Feb 2015','dos'=>'January 5th 2018','doh'=>'Next Month');
print_r($post);
function toDate(&$date)
{
$date=date('Y-m-d',strtotime($date));
}
foreach($post as &$r)
{