Skip to content

Instantly share code, notes, and snippets.

View alexx855's full-sized avatar
🔵
Stay safe and stay optimistic

Alex Pedersen alexx855

🔵
Stay safe and stay optimistic
View GitHub Profile
@alexx855
alexx855 / README.md
Last active October 7, 2026 11:19
Windows-style window shortcuts on Mac with Hammerspoon (Control and arrow keys)

Windows-style window shortcuts on my Mac

I wanted Windows-style window shortcuts on my Mac. This Hammerspoon Lua script lets me snap windows, fill the usable screen area, restore their size and move them between displays with Control and the arrow keys.

Install Hammerspoon and save window-management.lua in ~/.hammerspoon/. Add this line to your existing ~/.hammerspoon/init.lua:

dofile(hs.configdir .. "/window-management.lua")
@alexx855
alexx855 / README.md
Created October 3, 2026 13:53
Chrome new tab to the right on Mac with Hammerspoon (Cmd-T)

Chrome new tab to the right on Mac

Use Hammerspoon to make Cmd-T open and select a tab immediately after the active tab in Google Chrome. The shortcut is enabled only while Chrome is active. The + button keeps its usual behavior.

With B selected:

Before: A | B | C
Cmd-T:  A | B | New | C
@alexx855
alexx855 / mysql_query.sql
Last active October 19, 2022 14:19
WooCommerce, select users with completed orders by user role
-- ALL SUBSCRIBERS WITH AN ORDER COMPLETED
SELECT
u.ID, um.meta_value AS user_role, COALESCE(COUNT(p.ID), 0) AS completed_orders
FROM wp_users AS u JOIN wp_usermeta AS um ON u.ID = um.user_id
LEFT JOIN wp_postmeta AS pm ON pm.meta_value = um.user_id
LEFT JOIN wp_posts AS p ON p.ID = pm.post_id
WHERE um.meta_key = 'wp_capabilities'
AND um.meta_value LIKE '%subscriber%'
AND um.meta_value NOT LIKE '%administrator%'
AND pm.meta_key = '_customer_user'
@alexx855
alexx855 / images_opt.md
Last active October 19, 2022 14:24
png jpeg images batch optimization with jpegoptim and optipng

install deps

sudo apt-get install jpegoptim
sudo apt-get install optipng

change ./ for your images folder

find ./ -type f -iname *.png -print0 | xargs -0 optipng -nc -nb -o7
find ./ -type f -iname *.jpeg -exec jpegoptim --max=70 --all-progressive -p {} \;
@alexx855
alexx855 / gist:a30420897de02bb55062290b13ba1cf3
Last active August 24, 2022 12:32
Google Form Script, send email with attachment from drive on submit
function onFormSubmit( e ) {
const values = e.namedValues;
//e.values is an array of form values
const fecha = e.values[ 0 ];
const email = e.values[ 1 ];
//file is the template file, and you get it by ID
const file = DriveApp.getFileById(
'FILE_ID'
@alexx855
alexx855 / columns.php
Created June 15, 2018 17:49
Adding custom columns to custom post types
<?php
// Add the custom columns to the book post type:
add_filter( 'manage_book_posts_columns', 'set_custom_edit_book_columns' );
function set_custom_edit_book_columns($columns) {
unset( $columns['author'] );
$columns['book_author'] = __( 'Author', 'your_text_domain' );
$columns['publisher'] = __( 'Publisher', 'your_text_domain' );
return $columns;
@alexx855
alexx855 / functions.php
Created February 28, 2018 21:48
Wordpress AJAX resquest example
<?php
add_action( 'wp_enqueue_scripts', function() {
// Register the script
wp_register_script('ajax-script', get_template_directory_uri() . '/js/my-ajax-script.js', ['jquery']);
// Localize the script with new data
wp_localize_script('ajax-script', 'my_ajax_object', ['ajax_url' => admin_url( 'admin-ajax.php' )]);
// Enqueued script with localized data.
wp_enqueue_script('ajax-script');
});
@alexx855
alexx855 / parent-template-inherit.php
Created May 21, 2017 19:43
Wordpress parent template inherit
<?php
function switch_page_template() {
global $post;
// Checks if current post type is a page, rather than a post
if (is_page())
{
// Checks if page is parent, if yes, return
if ($post->post_parent == 0)
@alexx855
alexx855 / crud-taxonomy-meta-wordpress.php
Created May 19, 2017 00:22
CRUD custom taxonomy meta wordpress
<?php
add_action( '{taxonomy}_add_form_fields', 'add_feature_group_field', 10, 2 );
function add_feature_group_field($taxonomy) {
global $meta_name;
?>
<div class="form-field">
<label for="meta_name">Meta Name</label>
<input name="meta_name" id="meta_name" type="text" value="<?php echo $meta_name; ?>" size="40" aria-required="true">
@alexx855
alexx855 / custom-menu-items.php
Created April 26, 2017 14:09
How to Add Custom Items to Specific WordPress Menus
<?php
add_filter( 'wp_nav_menu_items', 'your_custom_menu_item', 10, 2 );
function your_custom_menu_item ( $items, $args ) {
if (is_single() && $args->theme_location == 'primary') {
$items .= '<li>Show whatever</li>';
}
return $items;
}