Skip to content

Instantly share code, notes, and snippets.

View gagimilicevic's full-sized avatar

Milicevic Dragan gagimilicevic

View GitHub Profile
@gagimilicevic
gagimilicevic / vimeo.php
Created March 24, 2020 17:01
Vimeo video - get duration
https://stackoverflow.com/questions/7772825/how-to-get-length-of-a-vimeo-video
echo vimeoVideoDuration('https://vimeo.com/115134273');
// output: 63 (video duration in seconds)
/**
* Vimeo video duration in seconds
*
* @param $video_url
* @return integer|null Duration in seconds or null on error
@gagimilicevic
gagimilicevic / custom_robots.php
Created February 28, 2020 14:38 — forked from amboutwe/wordpress_robots_custom.php
Filters and example code for Yoast SEO robots or WP robots.txt
<?php
/********* DO NOT COPY THE PARTS ABOVE THIS LINE *********/
/*
* Replace Disallow with Allow Generated Robots.txt
* Credit: Unknown
* Last Tested: Unknown
*/
add_filter('robots_txt','custom_robots');
@gagimilicevic
gagimilicevic / custom.js
Last active January 20, 2020 10:11
Detect page/tab close jQuery
$(window).on("beforeunload", function() {
return confirm("Do you really want to close?");
})
let formChanged = false;
myForm.addEventListener('change', () => formChanged = true);
window.addEventListener('beforeunload', (event) => {
if (formChanged) {
event.returnValue = 'You have unfinished changes!';
@gagimilicevic
gagimilicevic / gist:6b39314cd0cc2700bcb8bf68ca1367e6
Created January 10, 2020 16:23 — forked from zackn9ne/gist:3344158
WordPress if is Default Template
(is_page() && !is_page_template())
@gagimilicevic
gagimilicevic / gist:a72d557a2885f70251cd7624f9056457
Created December 30, 2019 14:10
Import large database to localbyflywheel database
mysql -u root -proot -f local < /app/backup.sql
wp search-replace 'http://yoursite.com' 'http://yourlocalsite.local'
@gagimilicevic
gagimilicevic / dashboard.php
Last active December 17, 2019 14:44
Adding WordPress Dashboard Widget
/**
* Add a widget to the dashboard.
*
* This function is hooked into the 'wp_dashboard_setup' action below.
*/
function dewploy_add_dashboard_widgets() {
// Add function here
wp_add_dashboard_widget(
'dewploy_dashboard_widget', // Widget slug.
esc_html__( 'Holiday Sitters Widget', 'dewploy' ), // Title.
@gagimilicevic
gagimilicevic / sort.php
Created December 4, 2019 10:55
PHP sort associative array
While others have correctly suggested the use of array_multisort(),
for some reason no answer seems to acknowledge the existence of array_column(),
which can greatly simplify the solution. So my suggestion would be:
array_multisort(array_column($inventory, 'price'), SORT_DESC, $inventory);
@gagimilicevic
gagimilicevic / coordinates.php
Created December 3, 2019 14:18
Distance between coordinates
?php
/*::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/
/*:: :*/
/*:: This routine calculates the distance between two points (given the :*/
/*:: latitude/longitude of those points). It is being used to calculate :*/
/*:: the distance between two locations using GeoDataSource(TM) Products :*/
/*:: :*/
/*:: Definitions: :*/
/*:: South latitudes are negative, east longitudes are positive :*/
@gagimilicevic
gagimilicevic / gist:ba71c3556d5ed757fb4f539b84e1e918
Created November 27, 2019 10:43
Local by Flywheel problem on linux
Thanks! That’s very helpful.
Based on the output, Apache appears to be running. Heads-up, if you’re using it for another project, the commands below will temporarily stop Apache.
Can you try the following?
Try running sudo service apache2 stop. If it results in an error, you may need to find a different stop command for Apache from this blog post: http://www.learn4master.com/programming-language/shell/start-restart-and-stop-apache-on-linux
Run netstat -ltnp | grep -w ':80' again after a few seconds and see if Apache stops listening on port 80.
@gagimilicevic
gagimilicevic / script.js
Last active November 15, 2019 12:02
Auto-center map with multiple markers in Google Maps API v3
var markers = [];
var markersListeners = [];
var LatLngList=[];
var infowindow = new google.maps.InfoWindow();
var marker, i;
var locations = $.parseJSON(data);
var bounds = new google.maps.LatLngBounds();
var initial_coordinates = {lat: locations[0]['lat'], lng: locations[0]['lng']};
var map = new google.maps.Map(document.getElementById('small_map_directions'), {