Skip to content

Instantly share code, notes, and snippets.

@condor-bird
condor-bird / yandex_api_example_add_counters.php
Created November 14, 2016 12:28
Yandex Api Example add counters
$data = ["counter" => [
"name" => "test8898",
"site" => "ucalc.pro"
]
];
$json = json_encode($data);
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, "https://api-metrika.yandex.ru/management/v1/counters?oauth_token=$token_metric");
curl_setopt($curl, CURLOPT_HTTPHEADER,['Content-Type: application/json']);
@condor-bird
condor-bird / num-letter-latin.js
Created March 8, 2017 10:14
Converting numbers to latin letters, a combination of letters
/**
* Преобразование чисел в латинские буквы, комбинация букв
* @param {integer} num - число для преобразования
* @returns {string} возвращаемое значение буквы
*/
function numLetterLatin(num) {
var num_memo = num, // сколько осталось преобразовать после предыдущего шага
num_tail = num, // сколько останется преобразовать после этого шага
num_now = 0, // какое число преобразуем в букву
count = 0,
@condor-bird
condor-bird / jquery-spoiler.html
Created February 11, 2018 07:34
jQuery spoiler script
<div class="container">
<div class="panel panel-default">
<div class="panel-heading">
<button type="button" class="btn btn-default btn-xs spoiler-trigger" data-toggle="collapse">Toggle Button</button>
</div>
<div class="panel-collapse collapse out">
<div class="panel-body">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Sint, quos, accusamus. Quidem, molestiae. Ipsam consequatur impedit voluptatem, quod qui perferendis fugiat. Eos adipisci dolorem doloremque quos debitis excepturi ex itaque!</p>
</div>
</div>
@condor-bird
condor-bird / laravel-form-check.php
Created February 27, 2018 17:03
Checking the activation of the checkbox in the form of Laravel
{!! Form::hidden('name_field', 0) !!}
{!! Form::checkbox('name_field', 1, $model->name_field == 1 ? true : false) !!}
@condor-bird
condor-bird / yii2-model-dropdown-select-optgroup.php
Created April 13, 2018 16:08
Yii2 dropdown select optgroup
public static function getHierarchy() {
$options = [];
$parents = self::find()->where("parent_id=0")->all();
foreach($parents as $id => $p) {
$children = self::find()->where("parent_id=:parent_id", [":parent_id" => $p->id])->all();
$child_options = [];
foreach($children as $child) {
@condor-bird
condor-bird / php-get-classname-without-namespace.php
Created April 13, 2018 17:04
PHP get class name without namespace
public function getName() {
$path = explode('\\', __CLASS__);
return array_pop($path);
}
@condor-bird
condor-bird / array_diff-json.php
Last active April 13, 2018 17:16
array_diff() with multidimensional arrays
<?php
// Compare all values by a json_encode
$diff = array_diff(array_map('json_encode', $array1), array_map('json_encode', $array2));
// Json decode the result
$diff = array_map('json_decode', $diff);
@condor-bird
condor-bird / laravel-validate-tabs.html
Created April 13, 2018 17:29
Display validation error in tabs using laravel
<li class="error">{ $error }}</li>
@condor-bird
condor-bird / laravel-validate-extended.php
Created April 13, 2018 17:38
Laravel validate exteded max MB
<?php
Validator::extend('max_mb', function($attribute, $value, $parameters, $validator) {
if ( $value instanceof UploadedFile && ! $value->isValid() ) {
return false;
}
// If call getSize()/1024/1024 on $value here it'll be numeric and not
// get divided by 1024 once in the Validator::getSize() method.
$megabytes = $value->getSize() / 1024 / 1024;
return $megabytes <= $parameters[0];
@condor-bird
condor-bird / react-modal.css
Last active April 22, 2018 11:16
React modal popup example
body {
background-color: #1B2B34;
font-size: 62.5%;
font-family: sans-serif;
color: #00273B;
}
.app-cont {
display: flex;
justify-content: center;