you are here: codestackercodes [RSS]leozera [RSS]

simple jquery table sort

requires jquery.sortElements.js (https://github.com/jamespadolsey/jQuery-Plugins/blob/master/sortElements/jquery.sortElements.js)

via http://stackoverflow.com/questions/3160277/jquery-table-sort

var table = $('table');

$('th').wrapInner('<span title="Sort this column"/>').each(function(){
     var th = $(this), thIndex = th.index(), inverse = false;
     th.click(function(){
         table.find('td').filter(function(){
             return $(this).index() === thIndex;
         }).sortElements(function(a, b){
             return $.text([a]) > $.text([b]) ?
                 inverse ? -1 : 1
                 : inverse ? 1 : -1;
         }, function(){
			return this.parentNode; 
         });
         inverse = !inverse;
     });
});

simple random password method

def random_password(size = 8)
	charset = %w{ 2 3 4 6 7 8 9 A B C D E F G H J K L M N P Q R T V W X Y Z}
	(0...size).map{ charset.to_a[rand(charset.size)] }.join
end

reading rss with google feeds

<script type="text/javascript" src="http://www.google.com/jsapi"></script>
<script type="text/javascript">

google.load("feeds", "1");

function initialize() {
  var feed = new google.feeds.Feed("http://www.digg.com/rss/index.xml");
  feed.load(function(result) {
    if (!result.error) {
      var container = document.getElementById("feed");
      for (var i = 0; i < result.feed.entries.length; i++) {
        var entry = result.feed.entries[i];
        var div = document.createElement("div");
        div.appendChild(document.createTextNode(entry.title));
        container.appendChild(div);
      }
    }
  });
}
google.setOnLoadCallback(initialize);

</script>
<div id="feed"></div>

smooth scrolling

http://snipplr.com/view.php?codeview&id=53669

$(document).ready(function() {
  function filterPath(string) {
  return string
    .replace(/^\//,'')
    .replace(/(index|default).[a-zA-Z]{3,4}$/,'')
    .replace(/\/$/,'');
  }
  var locationPath = filterPath(location.pathname);
  var scrollElem = scrollableElement('html', 'body');

  $('a[href*=#]').each(function() {
    var thisPath = filterPath(this.pathname) || locationPath;
    if (  locationPath == thisPath
    && (location.hostname == this.hostname || !this.hostname)
    && this.hash.replace(/#/,'') ) {
      var $target = $(this.hash), target = this.hash;
      if (target) {
        var targetOffset = $target.offset().top;
        $(this).click(function(event) {
          event.preventDefault();
          $(scrollElem).animate({scrollTop: targetOffset}, 400, function() {
            location.hash = target;
          });
        });
      }
    }
  });

  // use the first element that is "scrollable"

  function scrollableElement(els) {
    for (var i = 0, argLength = arguments.length; i <argLength; i++) {
      var el = arguments[i],
          $scrollElement = $(el);
      if ($scrollElement.scrollTop()> 0) {
        return el;
      } else {
        $scrollElement.scrollTop(1);
        var isScrollable = $scrollElement.scrollTop()> 0;
        $scrollElement.scrollTop(0);
        if (isScrollable) {
          return el;
        }
      }
    }
    return [];
  }

});

simple jquery scroll to top

$(document).ready(function() {
	$('.backtotop').click(function(){
		$('html, body').animate({scrollTop:0}, 'slow');
	});
});

Gerador de CPF, NIT, CNPJ e CEI válidos

<html>
<head>
	<title>Gerador de CPF, CNPJ e NIT Válidos</title>
	<script language="javascript">
		function gera_random(n) {
		    var ranNum = Math.round(Math.random()*n);
		    return ranNum;
		}

		function mod(dividendo,divisor) {
			return Math.round(dividendo - (Math.floor(dividendo/divisor)*divisor));
		}

		function cpf() {
			var n = 9;
			var n1 = gera_random(n);
		 	var n2 = gera_random(n);
		 	var n3 = gera_random(n);
		 	var n4 = gera_random(n);
		 	var n5 = gera_random(n);
		 	var n6 = gera_random(n);
		 	var n7 = gera_random(n);
		 	var n8 = gera_random(n);
		 	var n9 = gera_random(n);
		 	var d1 = n9*2+n8*3+n7*4+n6*5+n5*6+n4*7+n3*8+n2*9+n1*10;
		 	d1 = 11 - (mod(d1,11));
		 	if (d1>=10) d1 = 0;
		 	var d2 = d1*2+n9*3+n8*4+n7*5+n6*6+n5*7+n4*8+n3*9+n2*10+n1*11;
		 	d2 = 11 - (mod(d2,11));
		 	if (d2>=10) d2 = 0;
	
			if (document.form1.mascara.checked)
		 	  return ''+n1+n2+n3+'.'+n4+n5+n6+'.'+n7+n8+n9+'-'+d1+d2;
			else
			  return ''+n1+n2+n3+n4+n5+n6+n7+n8+n9+d1+d2;
		}

		function cnpj() {
			var n = 9;
			var n1  = gera_random(n);
		 	var n2  = gera_random(n);
		 	var n3  = gera_random(n);
		 	var n4  = gera_random(n);
		 	var n5  = gera_random(n);
		 	var n6  = gera_random(n);
		 	var n7  = gera_random(n);
		 	var n8  = gera_random(n);
		 	var n9  = 0;//gera_random(n);

		 	var n10 = 0;//gera_random(n);

		 	var n11 = 0;//gera_random(n);	

		 	var n12 = 1;//gera_random(n);		

			var d1 = n12*2+n11*3+n10*4+n9*5+n8*6+n7*7+n6*8+n5*9+n4*2+n3*3+n2*4+n1*5;
		 	d1 = 11 - ( mod(d1,11) );
		 	if (d1>=10) d1 = 0;
		 	var d2 = d1*2+n12*3+n11*4+n10*5+n9*6+n8*7+n7*8+n6*9+n5*2+n4*3+n3*4+n2*5+n1*6;
		 	d2 = 11 - ( mod(d2,11) );
		 	if (d2>=10) d2 = 0;
	
			if (document.form1.mascara.checked)
				return ''+n1+n2+'.'+n3+n4+n5+'.'+n6+n7+n8+'/'+n9+n10+n11+n12+'-'+d1+d2;
			else
				return ''+n1+n2+n3+n4+n5+n6+n7+n8+n9+n10+n11+n12+d1+d2;
		}

		function nit() {
			var n = 9;
			var n1  = 1;//gera_random(n);

		 	var n2  = gera_random(n);
		 	var n3  = gera_random(n);
		 	var n4  = gera_random(n);
		 	var n5  = gera_random(n);
		 	var n6  = gera_random(n);
		 	var n7  = gera_random(n);
		 	var n8  = gera_random(n);
		 	var n9  = gera_random(n);
		 	var n10 = gera_random(n);
		
			var d1 =  n1*3 + n2*2 + n3*9 + n4*8 + n5*7 + n6*6 + n7*5 + n8*4 + n9*3 + n10*2;
		 	d1 = 11 - ( mod(d1,11) );
		 	if (d1>=10) d1 = 0;
 	
			if (document.form1.mascara.checked)
				return ''+n1+n2+n3+'.'+n4+n5+n6+n7+n8+'.'+n9+n10+'-'+d1;
			else
				return ''+n1+n2+n3+n4+n5+n6+n7+n8+n9+n10+d1;
		}

		function cei() {
			var n = 9;
			var n1  = 2; // deve ser diferente de 0

		 	var n2  = gera_random(n);
		 	var n3  = gera_random(n);
		 	var n4  = gera_random(n);
		 	var n5  = gera_random(n);
		 	var n6  = gera_random(n);
		 	var n7  = gera_random(n);
		 	var n8  = gera_random(n);
		 	var n9  = gera_random(n);
		 	var n10 = gera_random(n);
			var n11 = 8; // atividade 

		
			var aux1 =  n1*7 + n2*4 + n3*1 + n4*8 + n5*5 + n6*2 + n7*1 + n8*6 + n9*3 + n10*7 + n11 * 4;
			var aux2 = aux1 + '';
	
			var aux3 = parseInt(aux2[aux2.length - 1]) + parseInt(aux2[aux2.length - 2]);
			var Soma = parseInt(aux1);	
			var d1 = parseInt((10 - (Soma % 10 + parseInt(Soma / 10)) % 10) % 10);
			d1 = Math.abs(d1);

			if (document.form1.mascara.checked)
		 	  return ''+n1+n2+'.'+n3+n4+n5+'.'+n6+n7+n8+n9+n10+'/'+n11+d1;
			else
			  return ''+n1+n2+n3+n4+n5+n6+n7+n8+n9+n10+n11+d1;
		}

		function gera() {
			if (document.form1.tipo[0].checked)
				document.form1.numero.value = cpf();
			else if (document.form1.tipo[1].checked)
				document.form1.numero.value = cnpj();
			else if (document.form1.tipo[2].checked)
				document.form1.numero.value = nit();
		    else if (document.form1.tipo[3].checked)
				document.form1.numero.value = cei();
		}
	</script>
</head>
<body>
	<h1>Gerador de CPF, NIT, CNPJ, CEI válidos</h1>
	<form name="form1" method="post" action="">		
		<label for="numero">Número:</label> <input name="numero" id="numero" size="20" type="text" /><br/>
		Tipo: 
		<input name="tipo" value="cpf" checked="checked" type="radio"> <label for="cpf">CPF</label> 
		<input name="tipo" value="cnpj" id="cnpj" type="radio" /> <label for="cnpf">CNPJ</label>
		<input name="tipo" value="nit" id="nit" type="radio"> <label for="nit">NIT</label>
		<input name="tipo" value="cei" id="cei" type="radio"> <label for="cei">CEI</label><br/>
		<input name="mascara" value="mascara" id="mascara" type="checkbox"> <label for="mascara">Máscara</label><br/><br/>

		<input name="button" value="Gerar" onclick="gera()" type="button">
	</form>
</body>
</html>

detecting iDevices

if (navigator.userAgent.match(/iP(ad|hone|od)/i)) {
 
// hello!


}

submit a form with a link

<!-- view -->
<%= form_for(@category) do |f| %>
	<!-- fields... -->
	<%= link_to 'Submit', '#', :class => 'submit_me' %>
<% end %>

<!-- javascript --> 
$('.submit_me').click(function() {
  $(this).parent().submit();
  return false;
});

rails 3 validates method

validates :login, :presence => true, :length => {:minimum => 4}, :uniqueness => true, :format => { :with => /[A-Za-z0-9]+/ }

# :presence => true

# :uniqueness => true

# :numericality => true

# :length => { :minimum => 0, maximum => 2000 }

# :format => { :with => /.*/ }

# :format => { :with => /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i } # email format

# :format => { :with => /^(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?$/ix } # url format

# :inclusion => { :in => [1,2,3] }

# :exclusion => { :in => [1,2,3] }

# :acceptance => true

# :confirmation => true

rails 3 money validation

validates :price, :presence => true, :format => { :with => /[0-9\,]*/ }

rails 3 url validation

# paste in your model


validates :url, :presence => true, :format => { :with => /^(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?$/ix }

check domain

check domain availability in one php file
http://github.com/leonardofaria/php-check-domain

<html>
<head>
	<title>whois</title>
</head>
<body>
	<form method="post">
		<label for="domain">Domain:</label>
		<input type="text" id="domain" name="domain" />
		<input type="submit"/>
	</form>

	<?php
		function get_server($domain){
			$whoisservers = array(
			array("ac","whois.nic.ac"),
			array("ac.cn","whois.cnnic.net.cn"),
			array("ac.jp","whois.nic.ad.jp"),
			array("ac.uk","whois.ja.net"),
			array("ad.jp","whois.nic.ad.jp"),
			array("adm.br","whois.nic.br"),
			array("adv.br","whois.nic.br"),
			array("aero","whois.information.aero"),
			array("ag","whois.nic.ag"),
			array("agr.br","whois.nic.br"),
			array("ah.cn","whois.cnnic.net.cn"),
			array("al","whois.ripe.net"),
			array("am.br","whois.nic.br"),
			array("arq.br","whois.nic.br"),
			array("at","whois.nic.at"),
			array("au","whois.aunic.net"),
			array("art.br","whois.nic.br"),
			array("as","whois.nic.as"),
			array("asn.au","whois.aunic.net"),
			array("ato.br","whois.nic.br"),
			array("be","whois.geektools.com"),
			array("bg","whois.digsys.bg"),
			array("bio.br","whois.nic.br"),
			array("biz","whois.biz"),
			array("bj.cn","whois.cnnic.net.cn"),
			array("bmd.br","whois.nic.br"),
			array("br","whois.registro.br"),
			array("ca","whois.cira.ca"),
			array("cc","whois.nic.cc"),
			array("cd","whois.cd"),
			array("ch","whois.nic.ch"),
			array("cim.br","whois.nic.br"),
			array("ck","whois.ck-nic.org.ck"),
			array("cl","whois.nic.cl"),
			array("cn","whois.cnnic.net.cn"),
			array("cng.br","whois.nic.br"),
			array("cnt.br","whois.nic.br"),
			array("com","whois.internic.net"),
			array("com.au","whois.aunic.net"),
			array("com.br","whois.nic.br"),
			array("com.cn","whois.cnnic.net.cn"),
			array("com.eg","whois.ripe.net"),
			array("com.hk","whois.hknic.net.hk"),
			array("com.mx","whois.nic.mx"),
			array("com.ru","whois.ripn.ru"),
			array("com.tw","whois.twnic.net"),
			array("conf.au","whois.aunic.net"),
			array("co.jp","whois.nic.ad.jp"),
			array("co.uk","whois.nic.uk"),
			array("cq.cn","whois.cnnic.net.cn"),
			array("csiro.au","whois.aunic.net"),
			array("cx","whois.nic.cx"),
			array("cz","whois.nic.cz"),
			array("de","whois.denic.de"),
			array("dk","whois.dk-hostmaster.dk"),
			array("ecn.br","whois.nic.br"),
			array("ee","whois.eenet.ee"),
			array("edu","whois.internic.net"),
			array("edu.au","whois.aunic.net"),
			array("edu.br","whois.nic.br"),
			array("eg","whois.ripe.net"),
			array("es","whois.ripe.net"),
			array("esp.br","whois.nic.br"),
			array("etc.br","whois.nic.br"),
			array("eti.br","whois.nic.br"),
			array("eun.eg","whois.ripe.net"),
			array("emu.id.au","whois.aunic.net"),
			array("eng.br","whois.nic.br"),
			array("far.br","whois.nic.br"),
			array("fi","whois.ripe.net"),
			array("fj","whois.usp.ac.fj"),
			array("fj.cn","whois.cnnic.net.cn"),
			array("fm.br","whois.nic.br"),
			array("fnd.br","whois.nic.br"),
			array("fo","whois.ripe.net"),
			array("fot.br","whois.nic.br"),
			array("fst.br","whois.nic.br"),
			array("fr","whois.nic.fr"),
			array("g12.br","whois.nic.br"),
			array("gd.cn","whois.cnnic.net.cn"),
			array("ge","whois.ripe.net"),
			array("ggf.br","whois.nic.br"),
			array("gl","whois.ripe.net"),
			array("gr","whois.ripe.net"),
			array("gr.jp","whois.nic.ad.jp"),
			array("gs","whois.adamsnames.tc"),
			array("gov","whois.nic.gov"),
			array("gs.cn","whois.cnnic.net.cn"),
			array("gov.au","whois.aunic.net"),
			array("gov.br","whois.nic.br"),
			array("gov.cn","whois.cnnic.net.cn"),
			array("gov.hk","whois.hknic.net.hk"),
			array("gob.mx","whois.nic.mx"),
			array("gs","whois.adamsnames.tc"),
			array("gz.cn","whois.cnnic.net.cn"),
			array("gx.cn","whois.cnnic.net.cn"),
			array("he.cn","whois.cnnic.net.cn"),
			array("ha.cn","whois.cnnic.net.cn"),
			array("hb.cn","whois.cnnic.net.cn"),
			array("hi.cn","whois.cnnic.net.cn"),
			array("hl.cn","whois.cnnic.net.cn"),
			array("hn.cn","whois.cnnic.net.cn"),
			array("hm","whois.registry.hm"),
			array("hk","whois.hknic.net.hk"),
			array("hk.cn","whois.cnnic.net.cn"),
			array("hu","whois.ripe.net"),
			array("id.au","whois.aunic.net"),
			array("ie","whois.domainregistry.ie"),
			array("ind.br","whois.nic.br"),
			array("imb.br","whois.nic.br"),
			array("inf.br","whois.nic.br"),
			array("info","whois.afilias.info"),
			array("info.au","whois.aunic.net"),
			array("it","whois.nic.it"),
			array("idv.tw","whois.twnic.net"),
			array("int","whois.iana.org"),
			array("is","whois.isnic.is"),
			array("il","whois.isoc.org.il"),
			array("jl.cn","whois.cnnic.net.cn"),
			array("jor.br","whois.nic.br"),
			array("jp","whois.nic.ad.jp"),
			array("js.cn","whois.cnnic.net.cn"),
			array("jx.cn","whois.cnnic.net.cn"),
			array("kr","whois.krnic.net"),
			array("la","whois.nic.la"),
			array("lel.br","whois.nic.br"),
			array("li","whois.nic.ch"),
			array("lk","whois.nic.lk"),
			array("ln.cn","whois.cnnic.net.cn"),
			array("lt","ns.litnet.lt"),
			array("lu","whois.dns.lu"),
			array("lv","whois.ripe.net"),
			array("ltd.uk","whois.nic.uk"),
			array("mat.br","whois.nic.br"),
			array("mc","whois.ripe.net"),
			array("med.br","whois.nic.br"),
			array("mil","whois.nic.mil"),
			array("mil.br","whois.nic.br"),
			array("mn","whois.nic.mn"),
			array("mo.cn","whois.cnnic.net.cn"),
			array("ms","whois.adamsnames.tc"),
			array("mus.br","whois.nic.br"),
			array("mx","whois.nic.mx"),
			array("name","whois.nic.name"),
			array("ne.jp","whois.nic.ad.jp"),
			array("net","whois.internic.net"),
			array("net.au","whois.aunic.net"),
			array("net.br","whois.nic.br"),
			array("net.cn","whois.cnnic.net.cn"),
			array("net.eg","whois.ripe.net"),
			array("net.hk","whois.hknic.net.hk"),
			array("net.lu","whois.dns.lu"),
			array("net.mx","whois.nic.mx"),
			array("net.uk","whois.nic.uk"),
			array("net.ru","whois.ripn.ru"),
			array("net.tw","whois.twnic.net"),
			array("nl","whois.domain-registry.nl"),
			array("nm.cn","whois.cnnic.net.cn"),
			array("no","whois.norid.no"),
			array("nom.br","whois.nic.br"),
			array("not.br","whois.nic.br"),
			array("ntr.br","whois.nic.br"),
			array("nx.cn","whois.cnnic.net.cn"),
			array("nz","whois.domainz.net.nz"),
			array("plc.uk","whois.nic.uk"),
			array("odo.br","whois.nic.br"),
			array("oop.br","whois.nic.br"),
			array("or.jp","whois.nic.ad.jp"),
			array("org","whois.internic.net"),
			array("org.au","whois.aunic.net"),
			array("org.br","whois.nic.br"),
			array("org.cn","whois.cnnic.net.cn"),
			array("org.hk","whois.hknic.net.hk"),
			array("org.lu","whois.dns.lu"),
			array("org.ru","whois.ripn.ru"),
			array("org.tw","whois.twnic.net"),
			array("org.uk","whois.nic.uk"),
			array("pl","nazgul.nask.waw.pl"),
			array("pp.ru","whois.ripn.ru"),
			array("ppg.br","whois.nic.br"),
			array("pro.br","whois.nic.br"),
			array("psi.br","whois.nic.br"),
			array("psc.br","whois.nic.br"),
			array("pt","whois.ripe.net"),
			array("qh.cn","whois.cnnic.net.cn"),
			array("qsl.br","whois.nic.br"),
			array("rec.br","whois.nic.br"),
			array("ro","whois.rotld.ro"),
			array("ru","whois.ripn.ru"),
			array("sc.cn","whois.cnnic.net.cn"),
			array("sd.cn","whois.cnnic.net.cn"),
			array("se","whois.nic-se.se"),
			array("sg","whois.nic.net.sg"),
			array("sh","whois.nic.sh"),
			array("sh.cn","whois.cnnic.net.cn"),
			array("si","whois.arnes.si"),
			array("sk","whois.ripe.net"),
			array("slg.br","whois.nic.br"),
			array("sm","whois.ripe.net"),
			array("sn.cn","whois.cnnic.net.cn"),
			array("srv.br","whois.nic.br"),
			array("st","whois.nic.st"),
			array("sx.cn","whois.cnnic.net.cn"),
			array("tc","whois.adamsnames.tc"),
			array("th","whois.nic.uk"),
			array("tj.cn","whois.cnnic.net.cn"),
			array("tmp.br","whois.nic.br"),
			array("to","whois.tonic.to"),
			array("tr","whois.ripe.net"),
			array("trd.br","whois.nic.br"),
			array("tur.br","whois.nic.br"),
			array("tv","whois.tv"),
			array("tv.br","whois.nic.br"),
			array("tw","whois.twnic.net"),
			array("tw.cn","whois.cnnic.net.cn"),
			array("uk","whois.thnic.net"),
			array("va","whois.ripe.net"),
			array("vet.br","whois.nic.br"),
			array("vg","whois.adamsnames.tc"),
			array("wattle.id.au","whois.aunic.net"),
			array("ws","whois.worldsite.ws"),
			array("xj.cn","whois.cnnic.net.cn"),
			array("xz.cn","whois.cnnic.net.cn"),
			array("yn.cn","whois.cnnic.net.cn"),
			array("zlg.br","whois.nic.br"),
			array("zj.cn","whois.cnnic.net.cn"),
			array("nu","whois.nic.nu"));

			for ($x=0;$x<count($whoisservers);$x++){
				$artld = $whoisservers[$x][0];
				$tldlen = intval(0 - strlen($artld));
				if (substr($domain, $tldlen) == $artld) { $whosrv = $whoisservers[$x][1]; }
			}
			return $whosrv;
		}
		
		function get_content($dom){
			$lusrv = get_server($dom);
			if (!$lusrv) return "";

			$fp = fsockopen($lusrv,43);
			fputs($fp, "$dom\r\n");
			$string="";
			while(!feof($fp)){
				$string.= fgets($fp,128);
			}
			fclose($fp);
			return $string;
		}
		
		function show_whois($dom){
			$string = get_content($dom);

			$reg = "/Whois Server: (.*?)\n/i";
			preg_match_all($reg, $string, $matches);
			$secondtry = $matches[1][0];

			if ($secondtry){
				$fp = fsockopen($secondtry,43);
				fputs($fp, "$dom\r\n");
				$string="";
				while(!feof($fp)){
					$string.=fgets($fp,128);
				}
				fclose($fp);
			}
			return $string;
		}
		
		function check_availability($dom){
			$string = get_content($dom);

			if (strpos($string, "No match for") > 0) {
				return true;
			} else {
				return false;
			}
		}
	
		if (isset($_POST['domain'])){ 
			if (check_availability($_POST['domain']) == true) { 
				echo $_POST['domain'] . " avaliable!";
			} else {
				echo $_POST['domain'] . " not avaliable!";
			}
			echo "<pre>".show_whois($_POST['domain'])."</pre>"; 
		}
	?>
</body>
</html>

wordpress: posting via php

via http://codex.wordpress.org/Function_Reference/wp_insert_post

<?php

	include "wp-blog-header.php";

	$my_post = array();
	$my_post['post_title'] = 'My post';
	$my_post['post_content'] = 'This is my post.';
	$my_post['post_status'] = 'publish';
	$my_post['post_author'] = 1;
	$my_post['post_category'] = array(13);

	$post_id = wp_insert_post($my_post);

	$post = get_post($post_id);
	wp_redirect($post->guid);

?>

display popular posts (most commented)

<?php $result = $wpdb->get_results("SELECT comment_count,ID,post_title FROM $wpdb->posts ORDER BY comment_count DESC LIMIT 0 , 10");
foreach ($result as $topten) {
$postid = $topten->ID;
$title = $topten->post_title;
$commentcount = $topten->comment_count;
if ($commentcount != 0) { ?>
<li><a href="<?php echo get_permalink($postid); ?>" title="<?php echo $title ?>"><?php echo $title ?></a></li>
<?php } } ?>

display recent updated posts/pages

<?php
	$today = current_time('mysql', 1);
	$howMany = 5; // Number of posts you want to display
	if ( $recentposts = $wpdb->get_results("SELECT ID, post_title FROM $wpdb->posts WHERE post_status = 'publish' AND post_modified_gmt < '$today' ORDER BY post_modified_gmt DESC LIMIT $howMany")):
?>
<ul>
<?php
foreach ($recentposts as $post) {
	if ($post->post_title == '') $post->post_title = sprintf(__('Post #%s'), $post->ID);
	echo "<li><a href='".get_permalink($post->ID)."'>";
	the_title();
	echo '</a></li>';
}
?>
</ul>
<?php endif; ?>

display rss using wordpress

<?php 
	include_once(ABSPATH.WPINC.'/rss.php');
	wp_rss('http://mysite.com/feed', 5); 
?>

display recent posts

<?php query_posts('showposts=5'); ?>
<ul>
<?php while (have_posts()) : the_post(); ?>
<li><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></li>
<?php endwhile;?>
</ul>

count search results

Results for: <?php $allsearch = &new WP_Query("s=$s&showposts=-1"); $key = wp_specialchars($s, 1); $count = $allsearch->post_count; echo $key . ' (' . $count . ')'; wp_reset_query(); ?>

reset wordpress admin password via sql

UPDATE wp_users
SET user_pass = MD5('password')
WHERE user_login = 'login';

disable post revisions

in your /wp-config.php

<?php

define('WP_POST_REVISIONS', false);

?>
Displaying Code 41 - 60 of 270 in total