Skip to content

Instantly share code, notes, and snippets.

View maynagashev's full-sized avatar
👨‍💻
Go

Evgeniy Maynagashev maynagashev

👨‍💻
Go
View GitHub Profile
@maynagashev
maynagashev / memory_get_peak_usage.php
Created November 25, 2017 20:41
memory_get_peak_usage tracker function
<?php
function mpu($label = '', $real_usage = false){
//return false; // disable
$mpu = round(memory_get_peak_usage($real_usage) / 1024 / 1024, 2);
$text = "{$label} {$mpu} MB";
if (function_exists('dump'))
dump($text);
else
echo "<div style='background-color:black; color:white;padding: 1em;'>{$text}</div>";
}
@maynagashev
maynagashev / select-all.html
Last active November 9, 2017 16:49
Checkbox select all
<script>
// classes: input.select-all, input.select-item, .select-title
document.addEventListener("DOMContentLoaded", function() {
$('input.select-all').click(function(){
var value = ($(this).prop('checked'));
$('input.select-item').each(function(){
$(this).prop('checked', value);
})
});
@maynagashev
maynagashev / ModelWithSlug.php
Created November 9, 2017 11:27
Laravel slug mutator (most basic implementation)
<?php
use Illuminate\Database\Eloquent\Model;
class ModelWithSlug extends Model
{
public function setSlugAttribute($val)
{
$val = trim($val);
$val = str_slug($val);
@maynagashev
maynagashev / form.html
Last active April 30, 2017 18:45
wrapper component with loglevel
<select2 :options="brands" v-model="form.brand_id" class="form-control" id="product_brand" name="product[brand_id]">
<option value="" selected="true" disabled="disabled">Выбeрите бренд из списка</option>
</select2>
@maynagashev
maynagashev / items-list.html
Last active April 25, 2017 13:32
Vue2 pagination component draft
<!-- RAW declaration-->
<div class="vue-render">
<pagination :total.number="55" :current.number="1" :per_page.number="16"></pagination>
</div>
<!-- inside wrapper -->
<div class="vue-render">
<items-list-pages>
<pagination :total.number="55" :current.number="1" :per_page.number="16"></pagination>
</items-list-pages>
@maynagashev
maynagashev / so-active-filter.js
Created April 21, 2017 16:56
Shared Object with History tracking methods
/**
* Created by maynagashev on 21.04.17.
*/
/**
* Shared Object for storing current Active Filter settings, used in:
* @components: moments-list, filter-bar, load-more
*
* + historyAPI (write and read new status)
*
@maynagashev
maynagashev / display_errors.php
Created March 31, 2017 08:15
PHP display errors
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
@maynagashev
maynagashev / __call
Last active March 31, 2017 11:06
Magic methods PHP __get/__set/__call
class pinbaWrapper {
private $pinbaEnabled;
public function __construct() {
$this->pinbaEnabled = extension_loaded('pinba');
}
public function __call($name, $arguments) {
if (!$this->pinbaEnabled) return false;
@maynagashev
maynagashev / list.blade.php
Created March 26, 2017 16:41
Load more jquery function
<div class="wrapper tiles">
@foreach($articles as $d)
{{$d->title}}
<input type="hidden" class="article-id" name="article-id" value="{{$d->id}">
@endforeach
</div>
@maynagashev
maynagashev / SmoothData.php
Created March 13, 2017 06:04
SmoothData slow versions with Laravel collections
// Other versions
/**
* Smooth by Moving Average algorithm with prevData measurements data (optional)
* ----------------------------
* USING COLLECTIONS VERY SLOW!
* ----------------------------
* @param $data
* @param $len