Skip to content

Instantly share code, notes, and snippets.

🎯
Focusing

Eugene Ilyin eugene-ilyin

🎯
Focusing
Block or report user

Report or block eugene-ilyin

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@eugene-ilyin
eugene-ilyin / Angular get active route path
Created Jun 14, 2019
This snippet returns a path of active route in Angular
View Angular get active route path
constructor(private router: Router,
private actRoute: ActivatedRoute) { }
...
this.router.events.filter(event => event instanceof NavigationEnd).subscribe((event) => {
const getActiveRoutePath = (routeSnapshot: ActivatedRouteSnapshot) => {
if (routeSnapshot.routeConfig) {
// Check top level route.
return routeSnapshot.routeConfig.path;
} else {
View Angular ViewChildren
import {Component, Directive, ElementRef, QueryList, ViewChildren} from "@angular/core";
// DON'T FORGET TO DECLARE A DIRECTIVE IN YOUR MODULE.
// Selector by class
@Directive({selector: '.live-screen__user-microphone'})
export class microphoneIconSelector {
// Define a property to make it available in object, returned by directive.
nativeElement: any;
constructor(private element: ElementRef) {
this.nativeElement = element.nativeElement;
@eugene-ilyin
eugene-ilyin / login.php
Created Aug 3, 2015
Login programmatically
View login.php
<?php
/**
* Drupal 7.
*/
$user_obj = user_load(1);
$form_state = array();
$form_state['uid'] = $user_obj->uid;
user_login_submit(array(), $form_state);
@eugene-ilyin
eugene-ilyin / request_is_ajax.php
Last active Jan 28, 2016
Check that request is AJAX
View request_is_ajax.php
/**
* Check if current request is AJAX.
*/
function MODULE_NAME_is_ajax() {
$http_request = isset($_SERVER['HTTP_X_REQUESTED_WITH'])
&& strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest';
// Check ajax in IE.
$request_uri = isset($_SERVER['REQUEST_URI'])
&& strtolower($_SERVER['REQUEST_URI']) == '/system/ajax';
@eugene-ilyin
eugene-ilyin / drupal_check_that_url_is_really_external.php
Created Oct 27, 2014
Drupal check that url is really external
View drupal_check_that_url_is_really_external.php
/**
* Check url for external property.
*/
function module_url_is_external($path) {
global $base_url;
$url_host = parse_url($path);
if (empty($url_host['host']) && empty($url_host['scheme'])) {
return FALSE;
} else {
if ($url_host['scheme'] . '://' . $url_host['host'] === substr($base_url, 0, strlen($url_host['scheme'] . '://' . $url_host['host']))) {
@eugene-ilyin
eugene-ilyin / cookie.js
Created Oct 21, 2014
Work with cookies in native Javascript
View cookie.js
@eugene-ilyin
eugene-ilyin / render_menu.php
Last active Oct 26, 2017
Render menu programmatically in Drupal 7
View render_menu.php
// One level menu.
$menu = menu_tree('main-menu');
$menu_items = render($menu);
// Menu with many levels.
menu_tree_all_data('main-menu');
$menu = menu_build_tree('main-menu');
$menu_items = render(menu_tree_output($menu));
You can’t perform that action at this time.