Skip to content

Instantly share code, notes, and snippets.

View Neolot's full-sized avatar
🏠
Make the web great again

Yurii Pokhylko Neolot

🏠
Make the web great again
View GitHub Profile
@Neolot
Neolot / gist:3103736
Created July 13, 2012 08:50
Remove UTF-8 BOM
find . -type f \( -name '*.css' -o -name '*.js' -o -name '*.txt' -o -name '*.php' -o -name '*.htm' -o -name '*.html' \) -print0 | xargs -0 grep -l `printf '^\xef\xbb\xbf'`
@Neolot
Neolot / gist:3103760
Created July 13, 2012 08:59
WORDPRESS Registering wp_nav_menu() in 3 locations
<?php
// Function for registering wp_nav_menu() in 3 locations
add_action( 'init', 'register_navmenus' );
function register_navmenus() {
register_nav_menus( array(
'Top' => __( 'Top Navigation' ),
'Header' => __( 'Header Navigation' ),
'Footer' => __( 'Footer Navigation' ),
)
);
@Neolot
Neolot / gist:3105730
Created July 13, 2012 16:11
JQUERY Блоки равной высоты
// Equal height of the blocks
function setEqualHeight(blocks, etalon, correction){
blocks = $(blocks);
if ( blocks.length > 1 ) {
var tallest = 0;
blocks.each(function(){
var height = $(this).outerHeight(true);
if (tallest < height) tallest = height;
});
if (etalon && tallest < etalon) {
@Neolot
Neolot / gist:3105735
Created July 13, 2012 16:12
WORDPRESS Счетчик FeedBurner с кэшированием
<?php
// Счетчик FeedBurner с кэшированием
function nlt_getFeedCounter($feedid='androidbar') {
$output = get_transient('rss_counter'); // Получаем данные из кэша
if ( $output === false || $output == '' ){ // Если кэш сброшен или пустой, то получаем данные
$twodayago = date('Y-m-d', strtotime('-2 days', time()));
$onedayago = date('Y-m-d', strtotime('-1 days', time()));
$today = date('Y-m-d');
@Neolot
Neolot / gist:3105743
Created July 13, 2012 16:13
WORDPRESS Счетчик Twitter с кэшированием
<?php
// Счетчик Twitter с кэшированием
function nlt_getTwitterCounter($userID='androidbar') {
$output = get_transient('twitter_counter');
if ( $output === false || $output == '' ) {
$data = json_decode(@file_get_contents('http://api.twitter.com/users/' . $userID .'.json'));
$output = $data->followers_count;
set_transient( 'twitter_counter', $output, 60*10 );
}
@Neolot
Neolot / getSince
Last active October 8, 2015 01:29
PHP Возвращает годы работы сайта
<?php
function getSince($start){
if ( date('Y') <= $start) {
return $start;
} else {
return $start.'-'.date('Y');
}
}
@Neolot
Neolot / gist:3964353
Created October 27, 2012 11:30
JQUERY Автоочистка поля при фокусе
(function($) {
$(function() {
$('#selector').each(function(){
var text = $(this).val();
$(this)
.focusin(function(){
$(this).addClass('focus');
if ($(this).val() == text) $(this).val('');
})
.focusout(function(){
@Neolot
Neolot / gist:3964361
Created October 27, 2012 11:35
JQUERY Плавная прокрутка по якорям
/* Вешаем событие прокрутки на все якоря (#) на странице */
$('a[href^="#"]').bind('click.smoothscroll', function (e) {
e.preventDefault();
var target = this.hash,
$target = $(target);
$('html, body').stop().animate({
'scrollTop':$target.offset().top
}, 900, 'swing', function () {
window.location.hash = target;
});
@Neolot
Neolot / gist:3964367
Last active October 12, 2015 03:28
PHP Обрезать текст по количеству знаков
function custom_excerpt($string, $limit) {
$string = strip_tags($string);
$count = mb_strlen($string);
if ($count > $limit) {
$string = mb_substr($string, 0, mb_strpos($string, " ", $limit)).' ...';
}
return $string;
}
@Neolot
Neolot / gist:3964373
Last active October 12, 2015 03:28
WORDPRESS Счетчик лайков Facebook Page
function getFacebookCounter($pageID='225279994223146') {
$output = get_transient('facebook_counter');
if ( $output === false || $output == '' ) {
$data = json_decode(@file_get_contents('http://graph.facebook.com/' . $pageID));
$output = $data->likes;
set_transient( 'facebook_counter', $output, 60*10 );
}
echo $output;
}