Skip to content

Instantly share code, notes, and snippets.

View ankitnetwork18's full-sized avatar

ankitnetwork18

View GitHub Profile
@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: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: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: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: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: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:4509887
Created January 11, 2013 11:07
mysql: command to remove all blank spaces from records
UPDATE
accounts_table
INNER JOIN
customers_table ON (accounts_table.user_id = customers_table.user_id)
SET
accountnumber = RTRIM(accountnumber)
WHERE
customers_table.customer_id = 'customer id';
If you do not have many records in accounts_table, and you want to make sure that all the accountnumber values are trimmed, you can simply apply the trim to all the records as follows:
@ankitnetwork18
ankitnetwork18 / gist:4509926
Created January 11, 2013 11:12
mysql: delete all duplicate records from table
DELETE n1 FROM names n1, names n2 WHERE n1.id > n2.id AND n1.name = n2.name
if you want to keep the row with the lowest id value OR
DELETE n1 FROM names n1, names n2 WHERE n1.id < n2.id AND n1.name = n2.name
DELETE FROM table_name
where column_name in(
@ankitnetwork18
ankitnetwork18 / gist:4510118
Created January 11, 2013 11:41
mysql: remove all spaces from values and change it to lower case
UPDATE cities SET city_state = lower(trim(city_state))
@ankitnetwork18
ankitnetwork18 / gist:4516346
Created January 12, 2013 05:58
php: simple template generator based on hash tags
//Demo template
/* <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;">
<title>Insert title here</title>
</head>
<body>
<div id="header">
##header##