Skip to content

Instantly share code, notes, and snippets.

View nikola-wd's full-sized avatar
💭
Available for full-time hire. React or Custom WordPress theme development.

Nikola Ivanov nikola-wd

💭
Available for full-time hire. React or Custom WordPress theme development.
View GitHub Profile
@nikola-wd
nikola-wd / gist:81fa71b8f5973611d65de51b6a5c6e62
Last active February 18, 2024 02:39
Useful .zshrc aliases
alias ll='ls -alF'
alias ls="ls --color -l -h" # add colors to ls
alias grep="grep -n --color" # add line numbers to grep
alias rnm="rm -rf node_modules" # remove node_modules
alias nlg="npm list -g --depth 0" #list global packages installed
alias vc="code"
alias vco="code ." # open current directory in vscode
alias la='ls -A'
alias l='ls -CF'
alias c='clear'
@nikola-wd
nikola-wd / CommentFormProcessing.php
Last active March 12, 2023 20:11
Wordpress AJAX comment form in vanilla JS (es6) + axios (Comment submission without page refresh)
<?php
add_action( 'wp_ajax_ajaxcomments', 'ugwps_submit_ajax_comment' ); // wp_ajax_{action} for registered user
add_action( 'wp_ajax_nopriv_ajaxcomments', 'ugwps_submit_ajax_comment' ); // wp_ajax_nopriv_{action} for not registered users
function ugwps_submit_ajax_comment(){
$comment = wp_handle_comment_submission( wp_unslash( $_POST ) );
if ( is_wp_error( $comment ) ) {
$error_data = intval( $comment->get_error_data() );
if ( ! empty( $error_data ) ) {
wp_die( '<p>' . $comment->get_error_message() . '</p>', __( 'Comment Submission Failure' ), array( 'response' => $error_data, 'back_link' => true ) );
@nikola-wd
nikola-wd / isMobileOrTablet.js
Created November 21, 2021 17:23
Is mobileOrTablet js script
const isMobileOrTablet = () => {
let check = false;
(function (a) {
if (
/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino|android|ipad|playbook|silk/i.test(
a
) ||
/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i23
@nikola-wd
nikola-wd / Visual Studio Code extensions
Last active July 20, 2021 20:05
Visual Studio Code extension list for configuration
abusaidm.html-snippets
akamud.vscode-theme-onedark
alefragnani.Bookmarks
alefragnani.project-manager
Angular.ng-template
anseki.vscode-color
anthonydiametrix.ACF-Snippet
burkeholland.simple-react-snippets
buzatto.ionic-basic-pack
christian-kohler.npm-intellisense
@nikola-wd
nikola-wd / safari_bdrs_fix.css
Created May 31, 2021 18:34
[safari border-radius fix] border radius not working properly on safari fix #css #scss #safari
https://forum.webflow.com/t/overflow-hidden-round-corners-not-working-on-safari/67805
The issue is the combination of overflow, border-radius, and transition
This is the solution:
On the element with overflow:
.transitionfix() {
-webkit-backface-visibility: hidden;
-moz-backface-visibility: hidden;
@nikola-wd
nikola-wd / caseInsensitivePregReplaceAll.js
Created December 6, 2020 18:05
[case-insensitive preg replace all] Replace all substr occurencies no matter the case ("str", <mark>str</mark> #javascript
function matchCase(text, pattern, tag = '') {
var result = '';
for(var i = 0; i < text.length; i++) {
var c = text.charAt(i);
var p = pattern.charCodeAt(i);
if(p >= 65 && p < 65 + 26) {
result += c.toUpperCase();
} else {
@nikola-wd
nikola-wd / debounce.js
Last active December 6, 2020 16:17
[debounce] Useful for not making requests on every key stroke for example #havascript #helper #optimization
// send req after a few seconds have passed since user last wrote in the editor
export default function debounce(a,b,c){
let d,e;
return function(){
function h(){
d=null;
c||(e=a.apply(f,g));
}
let f=this,g=arguments;
return (clearTimeout(d),d=setTimeout(h,b),c&&!d&&(e=a.apply(f,g)),e)
@nikola-wd
nikola-wd / input_number_validation_filter.js
Created September 25, 2020 23:58
[Validation - allow only numbers onKeyPress] #javascript #validation
/**
* @param {event} evt = e (from the element)
* @param {bool} isZIP=false
* @returns {bool}
*/
const validateNumberHelper = (evt, isZIP = false) => {
var theEvent = evt || window.event;
// Handle paste
if (theEvent.type === "paste") {
@nikola-wd
nikola-wd / async_php_promise_all.php
Created September 24, 2020 20:02
[“Async” Promise.all PHP Guzzle version] Guzzle version of Promise.all #PHP, #async, #Guzzle
function ping_app_fetch_counts(WP_REST_Request $request)
{
if (is_request_not_from_the_same_domain()) {
wp_send_json_error( "Not authorized", 401 );
return false;
}
$ping_env_id = get_option('wrwps_ping_env_id');
$base_endpoint = 'https://api.pingone.com/v1/environments/' . $ping_env_id . '/';
$token = get_jwt_token_string();
@nikola-wd
nikola-wd / acf_remove_data_upon_field_deletion.php
Last active July 15, 2020 07:06
[clean ACF data] Removes data upon acf field deletion #wordpress #php
// removes ACF data upon field deletion
// this action is run by ACF whenever a field is deleted
// and is called for every field in a field group when a field group is deleted
add_action('acf/delete_field', 'delete_acf_content_on_delete_field');
function delete_acf_content_on_delete_field($field) {
// runs when acf deletes a field
// find all occurences of the field key in all tables and delete them
// and the custom field associated with them
global $wpdb;