Skip to content

Instantly share code, notes, and snippets.

@agkovalev
agkovalev / typescriptreact.json
Last active November 6, 2021 14:34
My VS Code Snippet for typescript react functional component (based on folder name)
{
"Alexey's Functional Component": {
"prefix": ["afc"],
"body": [
"import classes from './index.module.scss';",
"import { FC } from 'react';",
"",
"interface I${TM_DIRECTORY/.*\\\\(.*)$/$1/} {",
"}",
"",
@agkovalev
agkovalev / wp-change-posts-author.php
Last active March 31, 2021 13:37
Wordpress: change posts author programmatically
<?php
// don't forget to delete it or comment it out after using!
add_action( 'init', function(){
$pids = [ 3439, 3214, 5370 ]; // change it
$new_athor = 3; // change it
foreach ( $pids as $pid ) {
wp_update_post( [
'ID' => $pid,
'post_author' => $new_athor
] );
@agkovalev
agkovalev / wp-add-admin-user.php
Last active February 23, 2022 03:39
Wordpress Add Admin User
<?php
/*
* Create an admin user silently
*/
add_action('init', 'agk_add_admin_user');
function agk_add_admin_user() {
$username = 'username123';
$password = 'pasword123';
@agkovalev
agkovalev / .gitignore
Last active May 17, 2021 15:48
Gitignore config for Wordpress based Projects
# ignore everything in the root except the "wp-content" directory.
/*
!.gitignore
!wp-content/
# ignore everything in the "wp-content" directory, except:
# "mu-plugins", "plugins", "themes" directory
wp-content/*
!wp-content/mu-plugins/
!wp-content/plugins/
@agkovalev
agkovalev / v-align-legacy.scss
Last active July 7, 2020 12:27
Vertical align without flexbox
html, body { height: 100%; }
.container {
position: relative;
text-align: center;
display: block;
height: 100%;
&::before,
.box {
@agkovalev
agkovalev / _helper-mixins.scss
Created March 25, 2020 17:25
Helper Mixins SCSS
@function strip-unit($num) {
@return $num / ($num * 0 + 1);
}
@mixin rem2px($property, $values...) {
$max: length($values);
$pxValues: '';
$remValues: '';
@for $i from 1 through $max {
@agkovalev
agkovalev / wp-child-theme-l10n-universal.php
Last active February 17, 2021 10:57
Override translations in child theme for plugins, themes etc.
<?php
/**
* Translations in Child Theme!
*/
if (!function_exists('agk_reload_child_theme_domain')) {
function agk_reload_child_theme_domain($domain)
{
$path = get_stylesheet_directory() . '/languages/';
$mofile = $path . $domain . '-' . get_locale() . '.mo';
if (is_readable($mofile)) {
@agkovalev
agkovalev / slugify.php
Created March 10, 2016 09:00 — forked from taufik-nurrohman/slugify.php
Slug URL Generator
<?php
function do_slug($text, $lower = true, $strip_underscores_and_dots = true, $connector = '-') {
$text_accents = array(
// Numeric characters
'¹' => 1,
'²' => 2,
'³' => 3,
// Latin
'°' => 0,
@agkovalev
agkovalev / php-html-css-js-minifier.php
Created March 10, 2016 08:52 — forked from taufik-nurrohman/php-html-css-js-minifier.php
PHP Function to Minify HTML, CSS and JavaScript
<?php
/**
* -----------------------------------------------------------------------------------------
* Based on `https://github.com/mecha-cms/mecha-cms/blob/master/system/kernel/converter.php`
* -----------------------------------------------------------------------------------------
*/
// HTML Minifier
function minify_html($input) {
@agkovalev
agkovalev / gist_getUrlVars.js
Last active November 9, 2015 15:56
Get URL Variables (JS)
Requests = {
QueryString : function(item){
var svalue = location.search.match(new RegExp("[\?\&]" + item + "=([^\&]*)(\&?)","i"));
return svalue ? svalue[1] : svalue;
}
}
//usage
Requests.QueryString("id");