Skip to content

Instantly share code, notes, and snippets.

@AlexMcowkin
AlexMcowkin / file.js
Last active February 5, 2020 09:13
create seo url from serialize() form
newUrl = generateUserFriendlyUrl($('#filter_form').serialize(), d.start, d.length, d.order[0]['column'], d.order[0]['dir']);
window.history.pushState({id: 'my_report'}, null, "/reports/some_report/" + newUrl);
@AlexMcowkin
AlexMcowkin / random_time.js
Created August 14, 2018 07:10
javascript: get random time between today and yesterday
<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
<script src="https://momentjs.com/downloads/moment.js"></script>
<script>
$(document).ready(function() {
function getRandomMilisecond(min, max)
{
var randomMinute = Math.floor(Math.random() * (max - min + 1)) + min;
return randomMinute * 60000; // 1 min = 60000 mls
}
@AlexMcowkin
AlexMcowkin / not_unique.sql
Created August 8, 2018 14:49
SQL: выбор не уникальных (повторяющихся) значений из таблицы
CREATE TABLE `post` (
`id` int(11) NOT NULL,
`name` varchar(100) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
//----------------------------------------
SELECT id, name FROM post WHERE id IN (SELECT id FROM post GROUP BY id having count(id) > 1) ORDER BY id;
@AlexMcowkin
AlexMcowkin / bracket_validation.php
Created August 7, 2018 11:46
Проверка строки на верное количество скобок на php
<?php
$string = 'This is (ok)';
function bracketValidation($string)
{
$counter = 0;
$openBracket = ['(','{','['];
$closedBracket = [')','}',']'];
@AlexMcowkin
AlexMcowkin / CommondataController.php
Created January 15, 2018 14:55
laravel 5.5: yajrabox datatables add html code
<?php
namespace App\Http\Controllers\Backend;
use App\Http\Controllers\Controller;
use App\Model\Commondata;
use Illuminate\Http\Request;
use App\Http\Requests\CommondataRequest;
class CommondataController extends Controller
@AlexMcowkin
AlexMcowkin / gist:d0338b43e31e355a8d3b3134aeba4521
Created December 19, 2017 14:30
Laravel 5.5 boot() in model
public static function boot()
{
parent::boot();
self::deleting(function($model) {
if($model->default == 1)
return false;
});
self::updated(function($model){
@AlexMcowkin
AlexMcowkin / index.php
Created April 26, 2017 10:41
yii2: check if email exists
try {
// send email
}
catch (Swift_TransportException $e) {
// delete email
}
public function actionSearch()
{
// ---------SphinxSearch----------
if($_SERVER['REQUEST_METHOD'] == 'GET')
{
$searchText = HtmlPurifier::process(Yii::$app->request->get('search'));
$searchText = trim($searchText);
$sphinxQuery = new Query();
$sphinxResult = $sphinxQuery->from('post_index')->match($searchText)->all();
@AlexMcowkin
AlexMcowkin / php_decrypt_encrypt.php
Created August 20, 2015 07:58
способ зашифровать/дешифровать данные БЕЗ md5
$key = 'password to (en/de)crypt';
$string = ' string to be encrypted '; // данные для шифровки/дешифровки
/////////////// Шифрование //////////////////
$iv = mcrypt_create_iv(
mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC),
MCRYPT_DEV_URANDOM
);
$encrypted = base64_encode(
@AlexMcowkin
AlexMcowkin / foreffactory.php
Created August 10, 2015 17:59
forexfactory parce
<?php
include_once('simple_html_dom.php');
// %progdir%\modules\wget\bin\wget.exe -q --no-cache http://forexfactory.loc/forexfactory.php
define ("PATH_TO_FOLDER", "C:/Users/Vadim/AppData/Roaming/MetaQuotes/Terminal/D0E8209F77C8CF37AD8BF550E51FF075/MQL5/Files/");
// define ("PATH_TO_FOLDER", "E:/openserver522/openserver/domains/forexfactory.loc/");
define ("CSV_FILE_NAME", "forexfactoryparce.csv");
if(!file_exists(PATH_TO_FOLDER.CSV_FILE_NAME))