Skip to content

Instantly share code, notes, and snippets.

@dimd13
dimd13 / DateTimeRu.php
Created October 22, 2020 15:38 — forked from Aleksandr-ru/DateTimeRu.php
Русскоязычный DateTime с дополнениями
<?php
/**
* Русскоязычный DateTime с дополнениями
*
* @author Aleksandr <aleksandr@aleksandr.ru>
* @link http://www.aleksandr.ru author's website
*/
class DateTimeRu extends DateTime
{
protected static $FN = array(1=>"Январь", "Февраль", "Март", "Апрель", "Май", "Июнь", "Июль", "Август", "Сентябрь", "Октябрь", "Ноябрь", "Декабрь");
@dimd13
dimd13 / difference.js
Created January 21, 2020 13:43 — forked from Yimiprod/difference.js
Deep diff between two object, using lodash
/**
* Deep diff between two object, using lodash
* @param {Object} object Object compared
* @param {Object} base Object to compare with
* @return {Object} Return a new object who represent the diff
*/
function difference(object, base) {
function changes(object, base) {
return _.transform(object, function(result, value, key) {
if (!_.isEqual(value, base[key])) {
@dimd13
dimd13 / tokens.md
Created June 19, 2019 10:19 — forked from zmts/tokens.md
Про токены, JSON Web Tokens (JWT), аутентификацию и авторизацию. Token-Based Authentication

Про токены, JSON Web Tokens (JWT), аутентификацию и авторизацию. Token-Based Authentication

Основы:

Аутентификация(authentication, от греч. αὐθεντικός [authentikos] – реальный, подлинный; от αὐθέντης [authentes] – автор) - это процесс проверки учётных данных пользователя (логин/пароль). Проверка подлинности пользователя путём сравнения введённого им логина/пароля с данными сохранёнными в базе данных.

Авторизация(authorization — разрешение, уполномочивание) - это проверка прав пользователя на доступ к определенным ресурсам.

Например после аутентификации юзер sasha получает право обращатся и получать от ресурса "super.com/vip" некие данные. Во время обращения юзера sasha к ресурсу vip система авторизации проверит имеет ли право юзер обращатся к этому ресурсу (проще говоря переходить по неким разрешенным ссылкам)

<?php
add_action( 'admin_menu', 'register_my_settings_page' );
function register_my_settings_page() {
add_submenu_page( 'edit.php?post_type=gallery', 'Media Selector', 'Media Selector', 'manage_options', 'gallery-settings', 'media_selector_settings_page_callback' );
//add_submenu_page( '<PARENT SLUG>', '<PAGE TITLE>', '<MENU TITLE>', '<ROLE>', '<MENU SLUG>', '<CALLBACK NAME>' );
}
function media_selector_settings_page_callback() {
@dimd13
dimd13 / bulma_walker_nav_menu.php
Created April 28, 2018 12:33 — forked from moabi/bulma_walker_nav_menu.php
A wordpress walker for Bulma Nav component
<?php
/**
* Will add classes to create bulma menu in wordpress
* http://bulma.io/documentation/components/nav/
* Usage
* wp_nav_menu(array(
* 'theme_location' => 'primary',
* 'items_wrap' => '%3$s',
* 'container_class' => 'nav-right nav-menu',
* 'walker' => new bulma_walker_nav_menu
@dimd13
dimd13 / get_current_git_commit.php
Created February 6, 2018 06:35 — forked from stevegrunwell/get_current_git_commit.php
Get current git HEAD using PHP
<?php
/**
* Get the hash of the current git HEAD
* @param str $branch The git branch to check
* @return mixed Either the hash or a boolean false
*/
function get_current_git_commit( $branch='master' ) {
if ( $hash = file_get_contents( sprintf( '.git/refs/heads/%s', $branch ) ) ) {
return $hash;
} else {
@dimd13
dimd13 / list.html.twig
Created April 4, 2017 11:16 — forked from tentacode/list.html.twig
Twig recursive macro
{% macro recursiveCategory(category) %}
<li>
<h4><a href="{{ path(category.route, category.routeParams) }}">{{ category }}</a></h4>
{% if category.children|length %}
<ul>
{% for child in category.children %}
{{ _self.recursiveCategory(child) }}
{% endfor %}
</ul>
@dimd13
dimd13 / phone_type.sql
Last active March 4, 2016 08:47
PostgesSQL
CREATE DOMAIN phone_number_type AS VARCHAR(16) CHECK( VALUE ~ '^([\+])\d{11,15}$' );