Instantly share code, notes, and snippets.

View random_time.js
<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
}
View not_unique.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;
View bracket_validation.php
<?php
$string = 'This is (ok)';
function bracketValidation($string)
{
$counter = 0;
$openBracket = ['(','{','['];
$closedBracket = [')','}',']'];
View CommondataController.php
<?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
View gist:d0338b43e31e355a8d3b3134aeba4521
public static function boot()
{
parent::boot();
self::deleting(function($model) {
if($model->default == 1)
return false;
});
self::updated(function($model){
View index.php
try {
// send email
}
catch (Swift_TransportException $e) {
// delete email
}
View yii2_search_sphinx.php
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();
View php_decrypt_encrypt.php
$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(
View foreffactory.php
<?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))
View gist:9f93f8de3e6a9ff2afdd
<?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))