Skip to content

Instantly share code, notes, and snippets.

View jeremysimmons's full-sized avatar

Jeremy Simmons jeremysimmons

View GitHub Profile
@jeremysimmons
jeremysimmons / multipart.cs
Last active June 20, 2024 17:44 — forked from erkantaylan/multipart.cs
c# download multi part
using System;
using System.Collections.Generic;
using System.IO;
using System.Net.Http;
using System.Threading.Tasks;
namespace TestApp
{
internal class Program
{
@jeremysimmons
jeremysimmons / cdtilde.bat
Created May 21, 2024 19:09
cdtilde recipe
@echo off
:: https://stackoverflow.com/a/52688643/26877
set dirname=""
set dirname=%*
set orig_dirname=%*
:: remove quotes - will re-attach later.
set dirname=%dirname:\"=%
set dirname=%dirname:/"=%
<?php
// https://stackoverflow.com/a/22818089/26877
// wp-content/mu-plugins/buffer.php
/**
* Output Buffering
*
* Buffers the entire WP process, capturing the final output for manipulation.
*/
ob_start();
;with product_types (object_id, product_type) as (
select tr.object_id, t.name
from wp_term_relationships tr
join wp_term_taxonomy tax on tr.term_taxonomy_id = tax.term_taxonomy_id and tax.taxonomy = 'product_type'
join wp_terms t on t.term_id = tax.term_id
)
select
p.ID
,p.post_parent
,p.post_status
@jeremysimmons
jeremysimmons / upgrader_process_complete_example.php
Created January 2, 2024 18:33
wordpress upgrader_process_complete example
function my_plugins_update_completed( $upgrader_object, $options ) {
// If an update has taken place and the updated type is plugins and the plugins element exists
if ( $options['action'] == 'update' && $options['type'] == 'plugin' && isset( $options['plugins'] ) ) {
foreach( $options['plugins'] as $plugin ) {
// Check to ensure it's my plugin
if( $plugin == plugin_basename( __FILE__ ) ) {
// do stuff here
}
}
@jeremysimmons
jeremysimmons / admin_head_post_edit_check.php
Created September 18, 2023 20:50 — forked from petenelson/admin_head_post_edit_check.php
WordPress admin action hooks for listing/adding/editing posts or pages
/* actions fired when listing/adding/editing posts or pages */
/* admin_head-(hookname) */
add_action( 'admin_head-post.php', 'admin_head_post_editing' );
add_action( 'admin_head-post-new.php', 'admin_head_post_new' );
add_action( 'admin_head-edit.php', 'admin_head_post_listing' );
function admin_head_post_editing() {
echo 'you are editing a post';
}
@jeremysimmons
jeremysimmons / wc_get_first_parent.php
Created August 28, 2023 14:55
Get the first parent id of a simple product woocommerce
function wc_get_first_parent($prod_id) {
$group_args = array(
'post_type' => 'product',
'meta_query' => array(
array(
'key' => '_children',
'value' => 'i:' . $prod_id . ';',
'compare' => 'LIKE',
)
),
@jeremysimmons
jeremysimmons / IndexedEnumerable.cs
Created October 18, 2022 14:33
Enumerable With Metadata
public static class IndexedEnumerable
{
public static IndexedEnumerable<T> AsIndexedEnumerable<T>(this IEnumerable<T> source)
{
return Create(source);
}
public static IndexedEnumerable<T> Create<T>(IEnumerable<T> source)
{
return new IndexedEnumerable<T>(source);
@jeremysimmons
jeremysimmons / .bashrc
Created September 19, 2022 16:21
dotnet format with desktop notify script
fcs() {
OUTPUT=$(dotnet format)
if [ $? -eq 0 ]; then
powershell -file $HOME/Toast.ps1 "Dotnet Format", "Completed successfully"
else
powershell -file $HOME/Toast.ps1 "Dotnet Format", "Failed $OUTPUT"
fi
}
@jeremysimmons
jeremysimmons / .gitconfig
Last active June 21, 2023 15:24
gitconfig
[user]
email = [email protected]
name = jeremy simmons
[alias]
# Get the current branch name (not so useful in itself, but used in other aliases)
branch-name = "!git rev-parse --abbrev-ref HEAD"
# Push the current branch to the remote "origin", and set it to track the upstream branch
publish = "!git push -u origin $(git branch-name)"
# Delete the remote version of the current branch