Skip to content

Instantly share code, notes, and snippets.

View ankitnetwork18's full-sized avatar

ankitnetwork18

View GitHub Profile
@ankitnetwork18
ankitnetwork18 / gist:4508550
Created January 11, 2013 07:00
jQuery: Reload Part of Page without Refresh and also events will work
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$(document).on("click", "a.next_button", function(){
var id = parseInt($(this).attr('id').split('_')[2],10);
var id_to_show = id+1;
$('div.data_div_'+id).hide();
$('div.data_div_'+id_to_show).show();
@ankitnetwork18
ankitnetwork18 / gist:4508564
Created January 11, 2013 07:02
CURL: send curl request to url without any data
function post_curl($url){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
curl_close($ch);
return $output;
}
@ankitnetwork18
ankitnetwork18 / gist:4508638
Created January 11, 2013 07:13
Cookies: cross domain cookie header
header('P3P:CP="IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT"');
@ankitnetwork18
ankitnetwork18 / gist:4508641
Created January 11, 2013 07:14
Cookies: function to setCookie
function setCookie(c_name,value,exdays) {
var exdate=new Date();
exdate.setDate(exdate.getDate() + exdays);
var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
document.cookie=c_name + "=" + c_value;
}
@ankitnetwork18
ankitnetwork18 / gist:4508643
Created January 11, 2013 07:14
Cookies: function to getCookie
function getCookie(c_name) {
var i,x,y,ARRcookies=document.cookie.split(";");
for (i=0;i<ARRcookies.length;i++)
{
x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
x=x.replace(/^\s+|\s+$/g,"");
if (x==c_name)
{
return unescape(y);
@ankitnetwork18
ankitnetwork18 / gist:4508649
Created January 11, 2013 07:15
jQuery: .each method pushing html ids into array
var cities = [];
$('div.weather_wrapper').each(function(idx) {
cities.push($(this).attr('id'));
});
@ankitnetwork18
ankitnetwork18 / gist:4508654
Created January 11, 2013 07:17
javascript: get random values from array
var cities = ['delhi', 'mumbai', 'pune'];
function getRandomCity() {
return cities[Math.floor(Math.random() * cities.length)];
}
@ankitnetwork18
ankitnetwork18 / gist:4508659
Created January 11, 2013 07:17
cookies: showing something based on javascript cookie
//check for cookie and show default city
if( typeof getCookie('city_name') == 'undefined') {
$('div#delhi').show();
} else {
var cookie_city = getCookie('city_name');
$('div#'+cookie_city).show();
}
@ankitnetwork18
ankitnetwork18 / gist:4508683
Created January 11, 2013 07:22
wordpress: api for importing data from text file
<?php
/*
* This is wordpress API for importing data from text file
* http://localhost/sandbox/wordpress/wp-content/plugins/data_import/import_data.php
*/
//load wordpress functions
require_once("../../../wp-load.php");
//path of text file from where posts need to be imported
@ankitnetwork18
ankitnetwork18 / gist:4508687
Created January 11, 2013 07:24
php: functions to read files from directory and filter them
/**
* list all files in a directory & subdirectory
* @param string $directory path to dir
* @param boolean $recursive weather recurisve listing or not
* @return array list of contents in dir
*/
function directoryToArray($directory, $recursive=false) {
$array_items = array();
if ($handle = opendir($directory)) {
while (false !== ($file = readdir($handle))) {