Skip to content

Instantly share code, notes, and snippets.

View mihdan's full-sized avatar
:octocat:
Code is poetry

Mikhail Kobzarev mihdan

:octocat:
Code is poetry
View GitHub Profile
@mihdan
mihdan / gist:19a0ddcd0bb49ecaabc5
Created January 23, 2015 22:58
Перевод координат из радиан на JavaScript
// convert radians into latitude
// 90 to -90
function rad2lat(rad) {
// first of all get everthing into the range -2pi to 2pi
rad = rad % (Math.PI*2);
// convert negatives to equivalent positive angle
if (rad < 0)
rad = 2*Math.PI + rad;
@mihdan
mihdan / gist:119741cd8a18f750bca1
Created January 23, 2015 23:16
Haversine formula
var rad = function(x) {
return x * Math.PI / 180;
};
var getDistance = function(p1, p2) {
var R = 6378137; // Earth’s mean radius in meter
var dLat = rad(p2.lat() - p1.lat());
var dLong = rad(p2.lng() - p1.lng());
var a = Math.sin(dLat / 2) * Math.sin(dLat / 2) +
Math.cos(rad(p1.lat())) * Math.cos(rad(p2.lat())) *
@mihdan
mihdan / gist:d2886c8aa112c0a0bc8e
Created January 24, 2015 00:30
Cross Browser Calculation of X & Y Position
function getPosition(e) {
var posx = 0;
var posy = 0;
if (!e) var e = window.event;
if (e.pageX || e.pageY) {
posx = e.pageX;
posy = e.pageY;
}
@mihdan
mihdan / wp-dashboard-close
Last active August 29, 2015 14:14
Закрыть доступ в админку для всех кроме админа
<?php
function ms_users_redirect() {
global $pagenow;
if( defined('DOING_AJAX') && DOING_AJAX ) {
return;
}
$allowed = [
<?php
/*
Plugin Name: Heartbeat API Demo
Plugin URI: http://www.strangerstudios.com/wp/heartbeat-api-demo
Description: Minimal example demonstrating the WordPress Heartbeat API being added in WP version 3.6.
Version: .1
Author: strangerstudios
If logged in as a user and viewing the frontend of your website,
every 15 seconds you should see the following in your Javascript console:
/**
* Plugin Name: Set Heartbeat pulse
*/
! defined( 'ABSPATH' ) and exit;
add_filter( 'heartbeat_settings', 'fb_heartbeat_settings' );
function fb_heartbeat_settings( $settings = array() ) {
$settings['interval'] = 60;
<?php
/*
Plugin Name: Geo Data Store
Plugin URI: http://l3rady.com/projects/geo-data-store/
Description: Stores lng/lat co-ordinates in a better optimized table
Author: Scott Cariss
Version: 2.0.2
Author URI: http://l3rady.com/
*/
set @latitude = xxx; — center latitude
set @longitude = xxx; — center longitude
set @distance = xx; — search distance
select p.ID, p.post_name, ((ACOS(SIN(@latitude * PI() / 180) * SIN(`latitude.meta_value` * PI() / 180) + COS(@latitude * PI() / 180) * COS(`latitude.meta_value` * PI() / 180) * COS((@longitude – `longitude.meta_value`) * PI() / 180)) * 180 / PI()) * 60 * 1.1515) AS distance
from wp_posts p
left join wp_postmeta latitude on latitude.post_id = p.ID and latitude.meta_key = ‘_latitude’
left join wp_postmeta longitude on longitude.post_id = p.ID and longitude.meta_key = ‘_longitude’
having distance < @distance;
@mihdan
mihdan / 0_reuse_code.js
Last active August 29, 2015 14:14
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
function add_subcategories_to_permalink( $category, $categories, $post ) {
return end( $categories );
}
add_filter( 'post_link_category', 'add_subcategories_to_permalink', 10, 3 );