Skip to content

Instantly share code, notes, and snippets.

View dejurin's full-sized avatar
💭
;-)

YURII D. dejurin

💭
;-)
  • Si-ɑR
  • București, România 🇷🇴
  • 17:49 (UTC +03:00)
View GitHub Profile
@dejurin
dejurin / .htaccess
Last active December 7, 2017 16:52
htaccess: redirect HTTP to HTTPS with without WWW
// without wwww
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteRule ^ https://{HTTP_HOST}%{REQUEST_URI} [L,NE,R=301]
// with www
RewriteCond %{HTTPS} off
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
@dejurin
dejurin / _number_format.php
Created December 11, 2017 17:42
PHP: [number_forma] floating with decimal, with safe zero
<?php
public function _number_format($number, $bs = '', $decimal = 0)
{
if (($e = strrchr($number, 'E')) === false) {
$len = strlen(substr(strstr($number, '.'), 1));
}
else {
$len = -intval(substr($e, 1));
}
@dejurin
dejurin / banch.php
Last active December 18, 2017 07:59
PHP: json_encode vs serialize
<?php
ini_set('display_errors', 1);
error_reporting(E_ALL);
// Make a big, honkin test array
// You may need to adjust this depth to avoid memory limit errors
$testArray = fillArray(0, 5);
// Time json encoding
@dejurin
dejurin / do.sh
Created December 18, 2017 08:24 — forked from loganlinn/do.sh
PHP strcmp+strtolower VS strcasecmp Benchmark
for i in 50 100 250 500; do echo "String length: $i"; php strcmpbench.php $i; php strcasecmpbench.php $i; echo "\n"; done
# Example run:
#
# String length: 50
# ************************
# * strcomp + strtolower *
# ************************
# Time: 0.000082
# Memory: 1456
@dejurin
dejurin / fontFitResize.js
Created December 30, 2017 17:23
Resize font depending on string length
var fontFitResize = function(fit, wrap, step = 0.5) {
var currentSize;
while(fit.offsetWidth < wrap.offsetWidth) {
currentSize = parseFloat(window.getComputedStyle(wrap, null).getPropertyValue('font-size'));
wrap.style.fontSize = (currentSize - step) + 'px';
console.log(wrap.style.fontSize);
}
}
@dejurin
dejurin / vanilla-js-cheatsheet.md
Created January 5, 2018 15:08 — forked from thegitfather/vanilla-js-cheatsheet.md
Vanilla JavaScript Quick Reference / Cheatsheet
@dejurin
dejurin / preg_grep_keys_values.php
Last active January 6, 2018 14:39
How to search in PHP Array, similar to MySQL Like %var% search
<?php
// Example from https://stackoverflow.com/questions/36081298/how-to-search-in-php-array-similar-to-mysql-like-var-search?rq=1
function preg_grep_keys_values($pattern, $input, $flags = 0) {
return array_merge(array_intersect_key($input, array_flip(preg_grep($pattern, array_keys($input), $flags))), preg_grep($pattern, $input, $flags));
}
$a = array(
'mark@test.by.com'=> "Mark Mian lv",
@dejurin
dejurin / Last_modified.php
Created February 27, 2018 23:23
Code Igniter 3 Last modified and E-tag Library
<?php
// Tested by Code Igniter 3.1.7
if (!defined('BASEPATH')) {
exit('No direct script access allowed');
}
class Last_modified
{
@dejurin
dejurin / csv_to_sql.php
Last active July 23, 2018 07:54
csv to sql
<?php
class FileCache {
/**
* The root cache directory.
*
* @var string
*/
private $cache_dir = '/tmp/cache';
/**
* Creates a FileCache object.
server {
listen %ip%:%web_ssl_port% http2;
server_name %domain_idn% %alias_idn%;
root %sdocroot%;
index index.php index.html index.htm;
access_log /var/log/nginx/domains/%domain%.log combined;
access_log /var/log/nginx/domains/%domain%.bytes bytes;
error_log /var/log/nginx/domains/%domain%.error.log error;
ssl on;