Skip to content

Instantly share code, notes, and snippets.

@rambuvn
rambuvn / gist:2650827
Created May 10, 2012 03:20
Time stamp ago function like facebook comment, post,...
function time_stamp($from){
$cmt_date = $from;
$from = strtotime($from);
if ( empty($to) )
$to = time();
$diff = (int) abs($to - $from);
if($diff <= 1){
$since = '1 second';
} else if($diff <= 60 ){
$since = sprintf(_n('%s second', '%s seconds', $diff), $diff);
@rambuvn
rambuvn / gist:2650837
Created May 10, 2012 03:23
set cursor to end point when focus or change value of input text field
function SetEnd(txt) {
if (txt.createTextRange) {
//IE
var FieldRange = txt.createTextRange();
FieldRange.moveStart('character', txt.value.length);
FieldRange.collapse();
FieldRange.select();
}
else {
//Firefox and Opera
@rambuvn
rambuvn / gist:2761421
Created May 21, 2012 09:12
Checking password complexity This regular expression will tests if the input consists of 6 or more letters, digits, underscores and hyphens. The input must contain at least one upper case letter, one lower case letter and one digit.
$password_regular = 'A(?=[-_a-zA-Z0-9]*?[A-Z])(?=[-_a-zA-Z0-9]*?[a-z])(?=[-_a-zA-Z0-9]*?[0-9])[-_a-zA-Z0-9]{6,}z'
@rambuvn
rambuvn / gist:2794734
Created May 26, 2012 17:35
a simple slider by jquery, get all img in a container then make slider with this. How to perfect it, please!
(function($){
$.fn.rb_slider = function(i) {
if( i ){
this.rb_slider_zoom_in(!i);
}else{
this.rb_slider_zoom_out(!i);
}
}
@rambuvn
rambuvn / gist:2843990
Created May 31, 2012 15:02
Wordpress get next, preivous attachment
function rb_get_next_attachment( $post_id, $previous = false ){
global $wpdb;
$post = get_post($post_id);
$current_post_date = $post->post_date;
if( $previous ){
$order = 'DESC';
$where = "p.post_date < '$current_post_date'";
}else{
$order = 'ASC';
@rambuvn
rambuvn / gist:2953035
Created June 19, 2012 08:35
I have a script to process submit, How to recode it (my meand is shorter)
/* facebook */
if( isset($_POST['facebook_create_item_wpnonce']) ){
if( wp_verify_nonce($_POST['facebook_create_item_wpnonce'], 'facebook_create_item') ){
$twitter_user = isset( $_POST['facebook_user'] ) ? $_POST['facebook_user'] : '';
if( $twitter_user ){
$wall_social_feed_options['facebook'][$twitter_user] = array(
'category' => 1,
'limit' => 20,
@rambuvn
rambuvn / gist:2953416
Created June 19, 2012 10:25
js tab submit form
setInterval(function(){
var activetab = new String(window.location.hash);
activetab = activetab.substring(1);
if($('#tab-'+activetab).hasClass('active')|| activetab=="") return;
$('#tab-'+activetab).click();
},100)
@rambuvn
rambuvn / gist:3162918
Created July 23, 2012 10:00
Grayscale effect for html5 but still not check cross browsers
// On window load. This waits until images have loaded which is essential
jQuery(window).load(function(){
// Fade in images so there isn't a color "pop" document load and then on window load
jQuery(".wedding-page .album-cover img").fadeIn(500);
// clone image
jQuery('.wedding-page .album-cover img').each(function(){
var el = jQuery(this);
el.css({"position":"absolute"}).wrap("<div class='img_wrapper' style='display: inline-block'>").clone().addClass('img_grayscale').css({"position":"absolute","z-index":"998","opacity":"0"}).insertBefore(el).queue(function(){
@rambuvn
rambuvn / gist:3176413
Created July 25, 2012 14:16
Images Loaded
// $('img.photo',this).imagesLoaded(myFunction)
// execute a callback when all images have loaded.
// needed because .load() doesn't work on cached images
// Modified with a two-pass approach to changing image
// src. First, the proxy imagedata is set, which leads
// to the first callback being triggered, which resets
// imagedata to the original src, which fires the final,
// user defined callback.
@rambuvn
rambuvn / gist:3411400
Created August 21, 2012 04:03
pagination of wordpress
function wallpress_pagenavi( $the_query ) {
global $wp_query, $wp_rewrite;
//User wordpress function paginate_links to create pagination, see codex.wordpress.org/Function_reference/paginate_links
if ( $the_query ) $wp_query = $the_query;
$pages = '';
$max = $wp_query->max_num_pages;
if ( !$current = get_query_var( 'paged' ) ) $current = 1;
$a['base'] = ( $wp_rewrite->using_permalinks() ) ? user_trailingslashit( trailingslashit( remove_query_arg( 's', get_pagenum_link( 1 ) ) ) . 'page/%#%/', 'paged' ) : @add_query_arg( 'paged', '%#%' );