Skip to content

Instantly share code, notes, and snippets.

View kidker's full-sized avatar
🎯
Focusing

kidker kidker

🎯
Focusing
View GitHub Profile
@kidker
kidker / gist:4696f63b748ab77501d32fa21abeb8c0
Created September 30, 2017 11:58 — forked from N-Porsh/gist:7766039
PHP: simple multiple file upload
<?php
$max_file_size = 5*1024*1024; //5MB
$path = "admin/upload/"; // Upload directory
//$count = 0; // nr.successfully uploaded files
$valid_formats = array("rar","zip","7z","pdf","xlsx","xls","docx","doc","txt");
$valid_formats_server = array(
"application/pdf",
"application/octet-stream",
@kidker
kidker / laravel-path.php
Created September 27, 2017 20:27
Laravel get PATH's
<?
// Path to the project's root folder
echo base_path();
// Path to the 'app' folder
echo app_path();
// Path to the 'public' folder
echo public_path();
@kidker
kidker / foldersize.php
Created September 27, 2017 19:02 — forked from eusonlito/foldersize.php
PHP function to get the folder size including subfolders
<?php
function folderSize ($dir)
{
$size = 0;
foreach (glob(rtrim($dir, '/').'/*', GLOB_NOSORT) as $each) {
$size += is_file($each) ? filesize($each) : folderSize($each);
}
@kidker
kidker / php
Created September 20, 2017 11:24
Difference Between Two Timestamps PHP
$ts1 = strtotime($start);
$ts2 = strtotime($end);
$seconds_diff = $ts2 - $ts1;
$time = ($seconds_diff/3600);
@kidker
kidker / flexbox.css
Last active January 31, 2018 00:06
Flexbox CSS MINIMAL
.flex {
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
-moz-box-wrap: nowrap;
-webkit-box-wrap: nowrap;
-webkit-flex-wrap: nowrap;
-ms-flexbox-wrap: nowrap;
-ms-flex-wrap: nowrap;
@kidker
kidker / php
Created June 28, 2017 13:07
Laravel bcrypt native php
$string = "some string that needs to be hashed";
$hash = password_hash($string, PASSWORD_BCRYPT, array('cost' => 10));
@kidker
kidker / javascript
Last active June 24, 2017 09:54
PHP/JS Generate MySQL password [length=32]
function generateRandomString(length) {
var characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$%^&*()-_+=;:,./?\\|`~[]{}';
var randomString = '';
for (var i = 0; i < length; i++) {
randomString += characters[Math.floor(Math.random() * (characters.length - 1))];
}
return randomString;
}
@kidker
kidker / LoadSite.php
Created June 24, 2017 02:27 — forked from davidrushton/LoadSite.php
Laravel multi-tenant multi-database
<?php
//app/Http/Middleware/LoadSite.php
namespace App\Http\Middleware;
use App\Exceptions\SiteNotFoundException;
use App\Sites\SiteRepository;
use App\Sites\SiteService;
use Closure;
@kidker
kidker / mysql
Created May 31, 2017 18:15
Mysql Check Exists
I have made some researches on this subject recently. The way to implement it has to be different if the field is a TEXT field, a non unique field.
I have made some tests with a TEXT field. Considering the fact that we have a table with 1M entries. 37 entries are equal to 'something':
SELECT * FROM test WHERE texte LIKE '%something%' LIMIT 1 with mysql_num_rows() : 0.039061069488525s. (FASTER)
SELECT count(*) as count FROM test WHERE text LIKE '%something% : 16.028197050095s.
SELECT EXISTS(SELECT 1 FROM test WHERE text LIKE '%something%') : 0.87045907974243s.
SELECT EXISTS(SELECT 1 FROM test WHERE text LIKE '%something%'
LIMIT 1) : 0.044898986816406s.
But now, with a BIGINT PK field, only one entry is equal to '321321' :
@kidker
kidker / javascript
Created May 30, 2017 15:47
momentjs convert to timezone from UTC
var test = moment.tz("2017-05-30 13:08:22", "UTC")
test.tz("Europe/Moscow")