Skip to content

Instantly share code, notes, and snippets.

View ankitnetwork18's full-sized avatar

ankitnetwork18

View GitHub Profile
@ankitnetwork18
ankitnetwork18 / gist:4544984
Created January 16, 2013 05:54
wordpress custom url rewrites
<?php
/***********************************************************************************************************/
/********************* WRITE OUR CUSTOM REWRITE RULES IN WORDPRESS *****************************************/
/***********************************************************************************************************/
add_action( 'init', 'add_custom_rewrite_rules' );
function add_custom_rewrite_rules() {
global $wp_rewrite;
$new_rules = array(
"blog/city/([^/]+)/([^/]+)/?" => "index.php?city_tags=\$matches[2]"
);
@ankitnetwork18
ankitnetwork18 / gist:4516808
Created January 12, 2013 08:46
jquery: image upload with jquery form
//handle change event of browse button {
$('input#file').change(function(){
var validated = true;
var error_msg = '';
if( $('input#file').val().length > 0 ) {
var file_name = $('input#file').val();
var file_name_parts = file_name.split('.');
var file_name_size = file_name_parts.length;
var last_elem = file_name_size-1;
var ext = file_name_parts[last_elem];
@ankitnetwork18
ankitnetwork18 / gist:4516793
Created January 12, 2013 08:42
jquery: jquery templating demo
<html>
<head>
<title>jQuery templating</title>
<script src="jquery.js"></script>
<script src="jquery-templating.js"></script>
<script>
jQuery(function($){
//create array or object of values to append in html
var movies = [
@ankitnetwork18
ankitnetwork18 / gist:4516755
Created January 12, 2013 08:26
jquery: jquery library version 1.4.2
/*!
* jQuery JavaScript Library v1.4.2
* http://jquery.com/
*
* Copyright 2010, John Resig
* Dual licensed under the MIT or GPL Version 2 licenses.
* http://jquery.org/license
*
* Includes Sizzle.js
* http://sizzlejs.com/
@ankitnetwork18
ankitnetwork18 / gist:4516685
Created January 12, 2013 08:07
jquery: jquery version 1.8
/*! jQuery v1.8.3 jquery.com | jquery.org/license */
(function(e,t){function _(e){var t=M[e]={};return v.each(e.split(y),function(e,n){t[n]=!0}),t}function H(e,n,r){if(r===t&&e.nodeType===1){var i="data-"+n.replace(P,"-$1").toLowerCase();r=e.getAttribute(i);if(typeof r=="string"){try{r=r==="true"?!0:r==="false"?!1:r==="null"?null:+r+""===r?+r:D.test(r)?v.parseJSON(r):r}catch(s){}v.data(e,n,r)}else r=t}return r}function B(e){var t;for(t in e){if(t==="data"&&v.isEmptyObject(e[t]))continue;if(t!=="toJSON")return!1}return!0}function et(){return!1}function tt(){return!0}function ut(e){return!e||!e.parentNode||e.parentNode.nodeType===11}function at(e,t){do e=e[t];while(e&&e.nodeType!==1);return e}function ft(e,t,n){t=t||0;if(v.isFunction(t))return v.grep(e,function(e,r){var i=!!t.call(e,r,e);return i===n});if(t.nodeType)return v.grep(e,function(e,r){return e===t===n});if(typeof t=="string"){var r=v.grep(e,function(e){return e.nodeType===1});if(it.test(t))return v.filter(t,r,!n);t=v.filter(t,r)}return v.grep(e,funct
@ankitnetwork18
ankitnetwork18 / gist:4516679
Created January 12, 2013 08:05
jquery: jquery templating plugin
/*
* jQuery Templates Plugin 1.0.0pre
* http://github.com/jquery/jquery-tmpl
* Requires jQuery 1.4.2
*
* Copyright 2011, Software Freedom Conservancy, Inc.
* Dual licensed under the MIT or GPL Version 2 licenses.
* http://jquery.org/license
*/
(function(a){var r=a.fn.domManip,d="_tmplitem",q=/^[^<]*(<[\w\W]+>)[^>]*$|\{\{\! /,b={},f={},e,p={key:0,data:{}},i=0,c=0,l=[];function g(g,d,h,e){var c={data:e||(e===0||e===false)?e:d?d.data:{},_wrap:d?d._wrap:null,tmpl:null,parent:d||null,nodes:[],calls:u,nest:w,wrap:x,html:v,update:t};g&&a.extend(c,g,{nodes:[],parent:d});if(h){c.tmpl=h;c._ctnt=c._ctnt||c.tmpl(a,c);c.key=++i;(l.length?f:b)[i]=c}return c}a.each({appendTo:"append",prependTo:"prepend",insertBefore:"before",insertAfter:"after",replaceAll:"replaceWith"},function(f,d){a.fn[f]=function(n){var g=[],i=a(n),k,h,m,l,j=this.length===1&&this[0].parentNode;e=b||{};if(j&&j.nodeType===11&&j.childNodes.length===1&&i.length===1){i[d](this[0]);g=this}else{for(h=0,m=i.length;h<m;h++){c=h;k=(h>0?this.clone(true):this).get(
@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##
@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: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: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: