Skip to content

Instantly share code, notes, and snippets.

Aleksandr Beliaev certainlyakey

Block or report user

Report or block certainlyakey

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
@certainlyakey
certainlyakey / enable-trigger-browsersync.php
Created Aug 15, 2019
Activate Browsersync reload on admin actions Wordpress plugin (requires Trigger Browsersync plugin)
View enable-trigger-browsersync.php
<?php
/*
Plugin Name: Activate Browsersync
Plugin URI: https://wordpress.org/plugins/trigger-browsersync/
Description: Activates Browsersync. Doesn't do anything without <a href="https://wordpress.org/plugins/trigger-browsersync/">Trigger Browsersync</a> plugin. This plugin code should be only present in local environment.
Version: 0.0.1
Author: Sami Greenbury
Author URI: https://www.patabugen.co.uk/
*/
@certainlyakey
certainlyakey / _mixins.scss
Last active Jun 11, 2019
A mixin that applies responsive spacing from a map
View _mixins.scss
// A mixin that applies responsive spacing from a map
// Usage: @include u-set-spacing-style('page-spacing');
@mixin u-set-spacing-style($group-name) {
$group: map-get($spacing, $group-name);
@each $property, $value in $group {
$is-breakpoint: variable-exists('breakpoints') and map-has-key($breakpoints, $property) and type-of($value) == 'map';
@include u-set-breakpoint(if($is-breakpoint, $property, null)) {
@if ($is-breakpoint) {
@certainlyakey
certainlyakey / _colors.scss
Last active Jun 11, 2019
A mixin that applies colors from a map
View _colors.scss
$colors-by-name: (
dove-gray: #666666,
mine-shaft: #333333,
denim: #0f6bac,
niagara: #0fb3ac,
// ...
);
$colors-by-function: (
buttons: (
@certainlyakey
certainlyakey / _mixins.scss
Last active Jun 12, 2019
A mixin that applies typographic styles from a map
View _mixins.scss
// A mixin that allows to apply typographic styles from a map
// Supports applying a typographic style responsively, based on a map of media queries in a $breakpoints variable
@mixin u-set-typography($typeface-name: 'body', $style-name: 'regular') {
$this-typeface: map-get($font-styles, $typeface-name);
$this-style: map-get($this-typeface, $style-name);
@if $typeface-name == 'body' {
font-family: $font-body;
}
@certainlyakey
certainlyakey / component-a.scss
Created Dec 19, 2018
Component mixin example
View component-a.scss
@mixin c-component-a($base_class: &) {
// styling for the root tag
color:gray;
// styling for elements and modifiers
// it is contained within @at-root directive to lower specificity
@at-root {
#{$base}__element-a {
width:400px;
@certainlyakey
certainlyakey / positioning.ts
Last active Aug 24, 2018
positionElements utility from ng-bootstrap 3.0.0
View positioning.ts
// from ng-bootstrap. Is not publicly accessible starting from 3.0.0 unfortunately so we have to copy it (also is changed slighly)
export class Positioning {
private getAllStyles(element: HTMLElement) { return window.getComputedStyle(element); }
private getStyle(element: HTMLElement, prop: string): string { return this.getAllStyles(element)[prop]; }
private isStaticPositioned(element: HTMLElement): boolean {
return (this.getStyle(element, 'position') || 'static') === 'static';
}
@certainlyakey
certainlyakey / _utilities.scss
Last active Aug 2, 2018
Last parent selector in SASS (like & but only the last one)
View _utilities.scss
// same as &, but applies the last (closest) parent only
// usage: @include u-direct-parent('.parent'<, ...>) {}
@mixin u-direct-parent($parent-selectors...) {
@each $parent-selector in $parent-selectors {
$current-sequences: &;
$new-sequences: ();
@each $sequence in $current-sequences {
$current-selector: nth($sequence, -1);
$prepended-selector: join($parent-selector, $current-selector);
@certainlyakey
certainlyakey / functions.php
Created Mar 19, 2018
Gravity Forms + Wordpress — retrieve a Gravity form by its class (set in each form settings)
View functions.php
<?php
// Retrieve a Gravity form by class (set in each form settings) 'js-overlay-form'
if ( class_exists( 'GFAPI' ) ) {
$forms = GFAPI::get_forms();
$class_key = 'cssClass';
$contactform_class = 'js-overlay-form';
foreach ($forms as $form) {
if (array_key_exists($class_key, $form) && $form[$class_key] == $contactform_class) {
$contactform_id = $form['id'];
break;
@certainlyakey
certainlyakey / functions.php
Created Mar 16, 2018
Remove current post from relationship fields which refer to the same post type (Wordpress + ACF)
View functions.php
<?php
// Remove current post from relationship fields which refer to the same post type
function remove_current_post_from_self_relationships($args, $field, $post_id) {
$args['post__not_in'] = array($post_id);
return $args;
}
$self_relationship_fields = array('relation_cases_cases');
foreach ($self_relationship_fields as $key => $field_name) {
@certainlyakey
certainlyakey / functions.php
Created Mar 16, 2018
Add a hint on the media upload screen in admin (Wordpress)
View functions.php
<?php
function upload_hint() {
global $common_config;
$adminscreen = get_current_screen();
echo '<p>';
_e('Consider uploading images of at least 1050 pixels in width.','site');
echo '</p>';
You can’t perform that action at this time.