Skip to content

Instantly share code, notes, and snippets.

View ankitnetwork18's full-sized avatar

ankitnetwork18

View GitHub Profile
@ankitnetwork18
ankitnetwork18 / gist:4509792
Created January 11, 2013 10:56
mysql: dump of indian cities and states
-- phpMyAdmin SQL Dump
-- version 2.11.6
-- http://www.phpmyadmin.net
--
-- Host: localhost:3306
-- Generation Time: Jan 11, 2013 at 04:24 PM
-- Server version: 5.0.51
-- PHP Version: 5.2.5
SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
@ankitnetwork18
ankitnetwork18 / gist:4508704
Created January 11, 2013 07:29
wordpress: add custom fields to post editor
/*
Plugin Name: Patti
Description: Modify Wordpress Add New Post for Adding Patti Data
Version: 1.0
Author: Ankit Agrawal
*/
/****************************************************************************/
/************************* ADD PATTI CUSTOM FIELDS *************************/
add_action( 'admin_init', 'patti_admin' );
@ankitnetwork18
ankitnetwork18 / gist:4508701
Created January 11, 2013 07:28
wordpress: modify admin panel post section items
/*
Plugin Name: Admin mods
Description: This plugin removes unwanted items from wordpress admin panel
Version: 1.0
Author: Ankit Agrawal
*/
//function to add custom coloumns
add_filter( 'manage_edit-post_columns', 'my_columns_filter', 10, 1 );
add_action( 'manage_posts_custom_column', 'my_column_action', 10, 1 );
@ankitnetwork18
ankitnetwork18 / gist:4508696
Created January 11, 2013 07:26
wordpress: import data into wordpress from rss/xml data
/*
* This is wordpress API for importing latest news from cnn ibn
* http://localhost/Sandbox/wordpress/wp-content/plugins/data_import/import_news18_images.php
*/
//load wordpress functions
require_once("../../../wp-load.php");
include 'functions.php';
/**
@ankitnetwork18
ankitnetwork18 / gist:4508694
Created January 11, 2013 07:25
wordpress: function to get wordpress date from any date string
/*
* function to get wordpress date
*/
function get_wp_date($date) {
return date('Y-m-d H:m:i', strtotime($date));
}
@ankitnetwork18
ankitnetwork18 / gist:4508692
Created January 11, 2013 07:24
curl: php function to post curl request to url with post data
/**
* This functions Sends Post curl request
* @param string $url url where posts request is send
* @param array $post_data array containing post data with key value pairs
* @return string
*/
function post_curl($url, $post_data){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
@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))) {
@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: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: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)];
}