Skip to content

Instantly share code, notes, and snippets.

@will83
will83 / gist:5920606
Last active February 13, 2024 15:20
Fonction PHP permettant la conversion de Lambert93 à WGS84 (selon le fichier fourni par l'IGN).
<?php
function lambert93ToWgs84($x, $y){
$x = number_format($x, 10, '.', '');
$y = number_format($y, 10, '.', '');
$b6 = 6378137.0000;
$b7 = 298.257222101;
$b8 = 1/$b7;
$b9 = 2*$b8-$b8*$b8;
$b10 = sqrt($b9);
$b13 = 3.000000000;
@will83
will83 / counter_increment.html
Last active August 29, 2015 13:56
Increment multiple counters each second with jquery (with decimals)
<!-- Don't forget to include jquery -->
<!-- the markup -->
<span class="counter" data-increment-value="0.07" data-increment-time="1000">1000.45</span>
<span class="counter" data-increment-value="0.03" data-increment-time="100">814.73</span>
<!-- the script -->
<script>
$( ".counter" ).each(function() {
// Get initial value (span value) as a number
@will83
will83 / functions.php
Last active August 29, 2015 14:00
Wordpress function.php include function
<?php
if ( ! function_exists( 'get_function_files' ) ) {
function get_function_files($path){
$function_files = glob($folder.$path, GLOB_BRACE);
foreach($function_files as $function_file){
if (substr($function_file, -8) != '-off.php'){
require_once($function_file);
}
}
}
echo '<pre>';
print_r(get_category());
echo '</pre>';
@will83
will83 / get_all_post_custom_fields.php
Created April 3, 2015 17:03
Function to get all custom fields within the $post global
<?php
function get_all_post_custom_fields( $posts ) {
for ( $i = 0; $i < count($posts); $i++ ) {
$custom_fields = get_post_custom( $posts[$i]->ID );
$posts[$i]->custom_fields = $custom_fields;
}
return $posts;
}
add_filter( 'the_posts', 'get_all_post_custom_fields' );
@will83
will83 / rewrite_custom_taxonomies_routes.php
Created July 16, 2015 13:56
Rewrite Custom Taxonomies Routes
<?php
/*
* Replace Taxonomy slug with Post Type slug in url
* Version: 1.1
*/
function ss_fix_portfolio_rewrite($wp_rewrite) {
$rules = array();
// get all custom taxonomies
@will83
will83 / func_object_depth.php
Last active August 29, 2015 14:27
Object depth function
function get_object_depth( $object_id, $object_type ){
$ancestors = get_ancestors( $object_id, $object_type );
return count($ancestors);
// 0 => level 1 (first parent)
// 1 => level 2
// ...
}
@will83
will83 / func_menu_item_has_children.php
Last active September 25, 2015 18:24
Function to know if a menu item has children
<?php
function menu_item_has_children($id){
global $wpdb;
$myrows = $wpdb->get_results( "SELECT * FROM `wp_postmeta` WHERE `meta_key` LIKE '_menu_item_menu_item_parent' AND `meta_value` LIKE ".$id );
if(empty($myrows)) :
return false;
else :
return true;
endif;
@will83
will83 / Autoloader.php
Last active November 2, 2017 22:48
Autoloader OOP
<?php
namespace Namespace;
class Autoloader{
static function register(){
spl_autoload_register(array(__CLASS__, 'autoload'));
}
static function autoload($class){
@will83
will83 / index.php
Last active November 1, 2022 10:21
PHP function to translate WGS84 to GPS coordinates
<?php
$lat = -24.108764;
$lng = 16.500156;
function WGS84toGPS($lat, $lng){
$lat = number_format($lat, 6);
$lng = number_format($lng, 6);
// define latitude coordinate with minutes and seconds
$lat_card = ($lat > 0) ? 'N' : 'S';