Skip to content

Instantly share code, notes, and snippets.

@lomboboo
lomboboo / get browser php
Created February 23, 2017 08:42
getting information about browser from php
function getBrowser()
{
$u_agent = $_SERVER['HTTP_USER_AGENT'];
$bname = 'Unknown';
$platform = 'Unknown';
$version= "";
//First get the platform?
if (preg_match('/linux/i', $u_agent)) {
$platform = 'linux';
RewriteEngine On
RewriteRule ^single/([0-9]*)$ single.php?id=$1 [L] // first part is nice formatted - second part i actual link
@lomboboo
lomboboo / Less for loop
Created December 17, 2016 12:19
Adding to LESS for loop with example
// ............................................................
// .for
.for(@i, @n) {.-each(@i)}
.for(@n) when (isnumber(@n)) {.for(1, @n)}
.for(@i, @n) when not (@i = @n) {
.for((@i + (@n - @i) / abs(@n - @i)), @n);
}
// ............................................................
@lomboboo
lomboboo / functions.php
Last active December 6, 2016 10:35
Creating custom menu template with registering location
//Usage: creating custom menu in Wordpress panel with name as $menu_name value
// Next: calling right_custom_menu function where custom menu is needed as follows =>> if (function_exists(right_custom_menu())) right_custom_menu();
function right_menu_position() {
register_nav_menu('nav_right',__( 'Prawe menu' ));
}
add_action( 'init', 'right_menu_position' );
function right_custom_menu() {
$menu_name = 'nav_right'; // specify custom menu slug
@lomboboo
lomboboo / polish_date.php
Last active April 28, 2017 10:15
Przeformatowanie daty na polską, z poprawną odmianą dni i mieśiące
<?php
date_default_timezone_set('Europe/Warsaw');
function dateToPolishFormat($format,$timestamp=null){
$to_convert = array(
'l'=>array('dat'=>'N','str'=>array('Poniedziałek','Wtorek','Środa','Czwartek','Piątek','Sobota','Niedziela')),
'F'=>array('dat'=>'n','str'=>array('styczeń','luty','marzec','kwiecień','maj','czerwiec','lipiec','sierpień','wrzesień','październik','listopad','grudzień')),
'f'=>array('dat'=>'n','str'=>array('stycznia','lutego','marca','kwietnia','maja','czerwca','lipca','sierpnia','września','października','listopada','grudnia'))
);
@lomboboo
lomboboo / enqueue scripts with passing vars
Created October 20, 2016 12:46
Wordpress functions.php adding scripts with passing variables
function custom_scripts()
{
wp_deregister_script('jquery');
wp_enqueue_script('jquery', 'https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js', array(), '1.0.0', false);
wp_enqueue_script('jquery-ui', '//code.jquery.com/ui/1.11.4/jquery-ui.js', array(), '1.0.0', true);
wp_enqueue_script('custom-script', get_template_directory_uri() . '/assets/js/script.js', array(), '1.0.0', true);
$map_pin_url = array(
'url' => get_template_directory_uri() . '/assets/img/map-pin.png',
);
@lomboboo
lomboboo / file size
Created October 20, 2016 08:18
function to return file size in GB MB KB bytes
function file_size2($url){
$size = filesize($url);
if($size >= 1073741824){
$fileSize = round($size/1024/1024/1024,1) . 'GB';
}elseif($size >= 1048576){
$fileSize = round($size/1024/1024,1) . 'MB';
}elseif($size >= 1024){
$fileSize = round($size/1024,1) . 'KB';
}else{
$fileSize = $size . ' bytes';