Skip to content

Instantly share code, notes, and snippets.

View damianwajer's full-sized avatar

Damian Wajer damianwajer

View GitHub Profile
@damianwajer
damianwajer / wp-update-tested-up-to.sh
Last active June 2, 2022 20:50
[WordPress] Update "tested up to" value for WordPress plugin with SVN | https://www.damianwajer.com/blog/update-tested-up-to-wordpress-plugin-svn/
# Check out a working copy from a repository
svn co http://plugins.svn.wordpress.org/[plugin-slug]/
# Bring changes from the repository into the working copy (use the command below for existing repo)
svn up
# Update "Tested up to" value with a new version number (using Vim or change `vi` to your editor of choice, e.g. `nano`)
vi trunk/readme.txt
# Copy readme.txt to the tag with the newest version of the plugin
@damianwajer
damianwajer / bash-inline-loop.sh
Created January 5, 2021 12:37
[Bash] Loop through strings in one line.
# Inline for loop
for i in "item1" "item2"; do echo "$i"; done
# Alternative syntax
for i in {"item1","item2"}; do echo "$i"; done
@damianwajer
damianwajer / shuffleArray.js
Last active December 15, 2020 13:02
[JavaScript] Shuffle an array using the modern Fisher–Yates shuffle algorithm | https://www.damianwajer.com/blog/random-array-the-modern-fisher-yates-shuffle-algorithm/
/**
* Shuffle an array using the modern Fisher–Yates shuffle algorithm.
*
* https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle#The_modern_algorithm
*
* @param {array} array
* @returns {array}
*/
function shuffleArray(array) {
let currentIndex = array.length;
@damianwajer
damianwajer / findDeepData.js
Created July 20, 2020 09:30
[JavaScript] Find deep data in an object.
/**
* Find deep data in an object.
*
* @param {object} data
* @param {string} path
* @return {*}
*/
function findDeepData(data, path) {
const keysArr = path.split(".");
@damianwajer
damianwajer / swipeToClose.js
Last active July 20, 2020 09:29
[JavaScript][jQuery] Close the navigation with swipe gestures.
/**
* Get navigation position.
*
* @param {jQuery} $nav Navigation element.
* @returns {string} Navigation position (left, right or fullwidth).
*/
function getNavigationMode($nav) {
let offset = $nav.offset();
let distanceLeft = Math.round(offset.left - $(document).scrollLeft());
let distanceRight = Math.round($(window).width() - distanceLeft - $nav.width());
@damianwajer
damianwajer / external-links.css
Created November 10, 2019 14:37
[CSS] Show a little arrow glyph after 'target="_blank"' anchors
@damianwajer
damianwajer / git-snippets.sh
Last active August 29, 2023 07:35
[Git] Snippets
# Git apply diff
pbpaste | git apply
# Nice Git log with tags
git log --oneline --decorate
# Show commit difference between two branches
git log --oneline --decorate master..HEAD
# Log after specific date
// Set of functions to ensure safe colors.
// Inspired by:
// - https://pressupinc.com/blog/2014/06/preserving-readability-variable-text-background-colors-sass/
// - http://blog.benjamincharity.com/generate-safe-text-colors-with-sass/
$lightness-bound: 70 !default;
$hue-bound-bottom: 40 !default;
$hue-bound-top: 200 !default;
$brightness-diff-bound: 40% !default;
@damianwajer
damianwajer / wp-media-categories.php
Created March 19, 2016 14:06
[WordPress] How to add media categories
<?php
/**
* Taxonomy for media files.
*/
function init_media_categories() {
register_taxonomy( 'media_cat', 'attachment', array(
'label' => __( 'Categories' ),
'hierarchical' => true,
'public' => false,
'show_ui' => true,
@damianwajer
damianwajer / .maintenance
Last active December 12, 2020 14:58
WordPress Maintenance mode with .maintenance file in root directory (temporary solution). Better option is to use something like: https://wordpress.stackexchange.com/questions/169600/redirect-visitors-to-a-temporary-maintenance-page/169610#169610
<?php $upgrading = time();