Skip to content

Instantly share code, notes, and snippets.

View sberdyug's full-sized avatar

Сергей Бердюг sberdyug

View GitHub Profile
@sberdyug
sberdyug / gen_guid.php
Last active March 2, 2017 21:58
Its easy to make GUIDs in PHP. Below is clean code using windows COM to get GUIDs. When the PHP creates GUIDs or UUIDs they are V4 guids.
<?php function gen_guid()
{
if (function_exists('com_create_guid')) {
return com_create_guid();
} else {
$charid = strtoupper(md5(uniqid(rand(), true)));
$hyphen = chr(45);
$uuid = chr(123)
.substr($charid, 0, 8).$hyphen
<?php function gen_uuid() {
return sprintf( '%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
// 32 bits for "time_low"
mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff ),
// 16 bits for "time_mid"
mt_rand( 0, 0xffff ),
// 16 bits for "time_hi_and_version",
// four most significant bits holds version number 4
<?php function gen_pass($length = 8)
{
$chars = "qazxswedcvfrtgbnhyujmkiolp1234567890QAZXSWEDCVFRTGBNHYUJMKIOLP";
$size = strlen($chars)-1;
$password = null;
for ($i = 0; $i < $length; $i++) {
$key = rand(0, $size);
$password .= $chars[$key];
}
return $password;
CREATE TABLE IF NOT EXISTS Sample (
id INT(10) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY COMMENT 'Identifier',
createdAt TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'Date of create',
updatedAt TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT 'Date of update'
) ENGINE=InnoDB CHARACTER SET utf8 COLLATE utf8_general_ci AUTO_INCREMENT=1001;
# Журнал доступа
CustomLog /var/log/httpd-access.log common //журнал доступа
LogFormat "%h %l %u %t \"%r\" %>s %b" common //формат записи
# Журнал ошибок
ErrorLog /var/log/httpd-error.log notice //журнал ошибок
LogLevel notice //степень отчетности
# Страницы ошибок
ErrorDocument 404 /server/error/pages/401.html
<?php
public function getAllChildren()
{
$allChildren = [];
$parentIds = [$this->id];
do {
$children = self::find()->where(['in', 'parentId', $parentIds])->all();
$parentIds = [];
foreach ($children as $child) {
CREATE TABLE Category (id, name, path, level, left, right, created_at, midifired_at, version, hidden, priority);
CREATE VIEW Categories SELECT id FROM Category;
CREATE TABLE User (id, email, password, name, created_at, confirmed_at, midifired_at, activated_at, version, is_blocked);
CREATE VIEW Users SELECT id FROM Category;
// id, name, path, level, version, created, midifired, sortable, hidden
function buildFlat(elements) {
var html = '';
for (var i in elements) {
html += '<li>';
if (elements[i].url != null) {
html += '<a href="' + elements[i].url + '">' + elements[i].name + '</a>';
}
else {
html += '<span>' + elements[i].name + '</span>';
}
function buildTree (elements, parentId = null) {
var html = '';
elements.forEach(function (element) {
if (element.parentId == parentId) {
html += '<li>';
if (element.url != null) {
html += '<a href="' + element.url + '">' + element.name + '</a>';
}
else {
html += '<span>' + element.name + '</span>';
@sberdyug
sberdyug / MySingleton.js
Created July 27, 2017 14:21 — forked from jasonwyatt/MySingleton.js
Singleton Pattern with Require JS
define(function(){
var instance = null;
function MySingleton(){
if(instance !== null){
throw new Error("Cannot instantiate more than one MySingleton, use MySingleton.getInstance()");
}
this.initialize();
}