Skip to content

Instantly share code, notes, and snippets.

View bepatrickdavid's full-sized avatar

bepatrickdavid bepatrickdavid

View GitHub Profile
@bepatrickdavid
bepatrickdavid / .htaccess
Created September 21, 2016 09:15 — forked from ScottPhillips/.htaccess
Common .htaccess Redirects
#301 Redirects for .htaccess
#Redirect a single page:
Redirect 301 /pagename.php http://www.domain.com/pagename.html
#Redirect an entire site:
Redirect 301 / http://www.domain.com/
#Redirect an entire site to a sub folder
Redirect 301 / http://www.domain.com/subfolder/
@bepatrickdavid
bepatrickdavid / gist:8d0f8e4994d2e0a72d1dc3150f01ef06
Created August 12, 2016 14:25
PHP: Foreach with key / index
foreach($array as $key => $item){
echo $key . ":" . $item . "<br>";
}
$(function() {
$("#findstore").bind("keydown", function(e) {
if (e.keyCode == 13) {
return false;
}
});
});
@bepatrickdavid
bepatrickdavid / template.php
Created April 14, 2016 08:00
WP: Pagination custom post types
<?php
$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
$the_query = new WP_Query( array (
'post_type' => 'offer',
'post_status' => 'publish',
'orderby' => 'date',
'order' => 'DESC',
'paged' => $paged
) );
@bepatrickdavid
bepatrickdavid / funtions.php
Created April 1, 2016 08:09
WP: Add character counter excerpt Riassunto limitazione caratteri
function excerpt_count_js(){
if ('page' != get_post_type()) {
echo '<script>jQuery(document).ready(function(){
jQuery("#postexcerpt .handlediv").after("<div style=\"position:absolute;top:12px;right:34px;color:#666;\"><small>Excerpt length: </small><span id=\"excerpt_counter\"></span><span style=\"font-weight:bold; padding-left:7px;\">/ 500</span><small><span style=\"font-weight:bold; padding-left:7px;\">character(s).</span></small></div>");
jQuery("span#excerpt_counter").text(jQuery("#excerpt").val().length);
jQuery("#excerpt").keyup( function() {
if(jQuery(this).val().length > 500){
jQuery(this).val(jQuery(this).val().substr(0, 500));
@bepatrickdavid
bepatrickdavid / gist:34a7d7808b9a389cbb1b
Created March 7, 2016 15:35
WordPress Asking for Local FTP Credentials on XAMPP
cd /Applications/XAMPP/xamppfiles/
This will get you to the XAMPP file directory. Now we’re going to modify your htdocs directory:
sudo chown -R daemon htdocs
Enter your root password when prompted, then finish it out with a chmod call:
sudo chmod -R g+w htdocs
And you’re done!
//esempio
$("#findstore").autocomplete({
minLength:3,
source: function(request, response) {
var matches = $.map( availableTags, function(tag) {
if ( tag.toUpperCase().indexOf(request.term.toUpperCase()) === 0 ) {
return tag;
}
});
@bepatrickdavid
bepatrickdavid / gist:9ba398d27ca7c9b7ae84
Created March 2, 2016 09:57
jQuery: nascondere tastiera ios hide keyboard
//se si preme enter
$(document).on("keyup", "input", function(event) {
// If enter is pressed then hide keyboard.
if(event.keyCode == 13) {
$("input").blur();
}
});
//nasconde
$("input").blur();
@bepatrickdavid
bepatrickdavid / gist:30b8ec65d6450fe03caf
Created February 5, 2016 07:54
htaccess: Remove query string from static resources
//wordpress function.php
function _remove_script_version( $src ){
$parts = explode( '?', $src );
return $parts[0];
}
add_filter( 'script_loader_src', '_remove_script_version', 15, 1 );
add_filter( 'style_loader_src', '_remove_script_version', 15, 1 );
@bepatrickdavid
bepatrickdavid / gist:4c4d49943756e8a56392
Created November 18, 2015 08:47
Calculate distance between two points on a globe
//PHP
function getDistance($latitude1, $longitude1, $latitude2, $longitude2) {
$earth_radius = 6371;
$dLat = deg2rad($latitude2 - $latitude1);
$dLon = deg2rad($longitude2 - $longitude1);
$a = sin($dLat/2) * sin($dLat/2) + cos(deg2rad($latitude1)) * cos(deg2rad($latitude2)) * sin($dLon/2) * sin($dLon/2);
$c = 2 * asin(sqrt($a));
$d = $earth_radius * $c;