Skip to content

Instantly share code, notes, and snippets.

View kdes70's full-sized avatar
🏠
Working from home

Dmitriy Krivoshein kdes70

🏠
Working from home
View GitHub Profile
@kdes70
kdes70 / docker-compose.yml
Created March 4, 2019 08:30 — forked from li0nel/docker-compose.yml
Docker Compose
version: '2'
networks:
network:
driver: bridge
services:
app:
build:
context: .
@kdes70
kdes70 / helper.php
Last active February 14, 2019 09:43
Helpers functions
<?php
// Simple way of masking emails
function mask_email($email ) {
$char_shown = 2;
$mail_parts = explode("@", $email);
$username = $mail_parts[0];
$len = strlen( $username );
@kdes70
kdes70 / gist:36cd197956d928e6a68716449882ae36
Created October 25, 2018 10:30
Вычислить дистанцию
<?php
function calculate_distance($cord1, $cord2){
$rad = 6372795;
$lat1 = (float)$cord1[0]*M_PI/180;
$long1 = (float)$cord1[1]*M_PI/180;
$lat2 = (float)$cord2[0]*M_PI/180;
$long2 = (float)$cord2[1]*M_PI/180;
@kdes70
kdes70 / AppServiceProvider.php
Created July 25, 2018 16:26 — forked from simonhamp/AppServiceProvider.php
A pageable Collection implementation for Laravel
<?php
namespace App\Providers;
use Illuminate\Support\Collection;
use Illuminate\Pagination\LengthAwarePaginator;
class AppServiceProvider extends ServiceProvider
{
public function boot()
@kdes70
kdes70 / cartesian.php
Created July 12, 2018 02:52
декартова произведения
function cartesian(array $input)
{
$result = [[]];
foreach ($input as $key => $values) {
$append = [];
foreach ($values as $value) {
foreach ($result as $data) {
$append[] = $data + [$key => $value];
}
}
<?
function cartesian($input) {
$result = array();
while (list($key, $values) = each($input)) {
// If a sub-array is empty, it doesn't affect the cartesian product
if (empty($values)) {
continue;
}
@kdes70
kdes70 / laravel whereHas
Created April 27, 2018 04:43
#laravel #whereHas
// result WHERE foreignKey = X AND (first_name = Y OR last_name = Z)
bookings=$bookings->whereHas('client',function($q) use ($client_name){
$q->where( function ($q) use ($client_name) {
$q->where('first_name','LIKE',$client_name)
->orWhere('last_name','LIKE',$client_name);
});
});
@kdes70
kdes70 / slugify.php
Created February 28, 2018 08:39 — forked from james2doyle/slugify.php
Simple slugify function for PHP. Creates a slug for the passed string, taking into account international characters as well.
<?php
function slugify($string, $replace = array(), $delimiter = '-') {
// https://github.com/phalcon/incubator/blob/master/Library/Phalcon/Utils/Slug.php
if (!extension_loaded('iconv')) {
throw new Exception('iconv module not loaded');
}
// Save the old locale and set the new locale to UTF-8
$oldLocale = setlocale(LC_ALL, '0');
setlocale(LC_ALL, 'en_US.UTF-8');
$clean = iconv('UTF-8', 'ASCII//TRANSLIT', $string);
@kdes70
kdes70 / README.md
Created April 6, 2017 11:48 — forked from icqparty/README.md
Debug PHP in Docker with PHPStorm and Xdebug

Отладка PHP-приложение c Xdebug в Docker-контейнере через редактор Intellij/PHPStorm

  1. Создайте в локальной дирриктори вашего проекта файл сборки Dockerfile со следующим содержанием:
FROM php:5

RUN yes | pecl install xdebug \
    && echo "zend_extension=$(find /usr/local/lib/php/extensions/ -name xdebug.so)" > /usr/local/etc/php/conf.d/xdebug.ini \
&amp;&amp; echo "xdebug.remote_enable=on" &gt;&gt; /usr/local/etc/php/conf.d/xdebug.ini \
@kdes70
kdes70 / YandexMap.vue
Created January 15, 2017 08:40 — forked from reg2005/YandexMap.vue
YandexMap wrapper for VueJS 2
<template>
<div class="col-xs-12" style="padding:0;">
<div class="panel panel-default" style="margin:0;">
<div class="panel-body" style="padding:0;">
<div v-if="maps.length" :style="{height: height + 'px'}" id="map"></div>
<h3 v-else class="text-center">Нет точек</h3>
</div>
</div>
</div>
</template>