Skip to content

Instantly share code, notes, and snippets.

@alexminza
alexminza / ExcelReaderMonkey.py
Created December 7, 2023 13:09
Fix openpyxl ExcelReader to load broken XLSX files exported by 1C
import pandas as pd
import openpyxl
#https://foss.heptapod.net/openpyxl/openpyxl
#from openpyxl.xml.constants import (ARC_SHARED_STRINGS, SHARED_STRINGS, ARC_CONTENT_TYPES, CONTYPES_NS)
#https://foss.heptapod.net/openpyxl/openpyxl/-/blob/branch/3.1/openpyxl/xml/constants.py#L35
#openpyxl.xml.constants.ARC_SHARED_STRINGS = openpyxl.xml.constants.PACKAGE_XL + '/SharedStrings.xml'
#from openpyxl.reader.strings import read_string_table, read_rich_text
@alexminza
alexminza / AlgoliaMemory.cs
Created October 2, 2023 18:43
Semantic Kernel AlgoliaMemory
using System.Runtime.CompilerServices;
using Microsoft.SemanticKernel.Memory;
using Algolia.Search.Clients;
using Algolia.Search.Models.Search;
using System.Text.Json;
public class AlgoliaMemory : ISemanticTextMemory
{
private readonly ISearchClient _searchClient;
@alexminza
alexminza / AsyncEnumerableStringsResult.cs
Last active August 31, 2023 12:38
AsyncEnumerableStringsResult
//https://stackoverflow.com/questions/76106284/how-to-return-chunked-text-plain-content-from-web-api-using-minimal-api
//https://github.com/dotnet/aspnetcore/tree/main/src/Http/Http.Results
public class AsyncEnumerableStringsResult : IResult, IContentTypeHttpResult, IStatusCodeHttpResult
{
protected readonly IAsyncEnumerable<string> chunks;
public string? ContentType => "text/plain; charset=utf-8";
public int StatusCode => StatusCodes.Status200OK;
@alexminza
alexminza / ConversationalRetrievalPlugin.cs
Created August 11, 2023 09:49
Semantic Kernel ConversationalRetrievalPlugin
using System.ComponentModel;
using System.Text;
using Microsoft.Extensions.Logging;
using Microsoft.SemanticKernel;
using Microsoft.SemanticKernel.Orchestration;
using Microsoft.SemanticKernel.SkillDefinition;
using Microsoft.SemanticKernel.AI.ChatCompletion;
using Microsoft.SemanticKernel.Memory;
class ConversationalRetrievalPlugin
@alexminza
alexminza / ForceRecalculate.gs
Last active October 2, 2023 18:40
Google Sheets Force Recalculate
"use strict";
var FORMULA_DISABLED_PREFIX = '?';
var FORMULA_DISABLED_FULL_PREFIX = '=' + FORMULA_DISABLED_PREFIX;
//https://support.geckoboard.com/hc/en-us/articles/206260188
function ForceRecalculateActiveSheet() {
var sheet = SpreadsheetApp.getActiveSheet();
ForceRecalculateSheet(sheet);
}
@alexminza
alexminza / translate__.php
Created February 27, 2018 11:33
WordPress translate__ shortcode
<?php
//https://codex.wordpress.org/Function_Reference/shortcode_atts
$args = shortcode_atts(
array(
'text' => '',
'domain' => 'default',
), $atts, 'translate__');
//https://developer.wordpress.org/reference/functions/__/
return __($args['text'], $args['domain']);
@alexminza
alexminza / do_shortcode_title.php
Created February 27, 2018 11:31
WordPress shortcodes in titles
<?php
function do_shortcode_title($title) {
return do_shortcode($title);
}
add_filter('the_title', 'do_shortcode_title');
add_filter('single_post_title', 'do_shortcode_title');
@alexminza
alexminza / wordpress_locale_switch.php
Created February 27, 2018 11:10
WordPress locale language switch
<?php
function set_locale($lang) {
define('LANG_PARAM', 'lang');
$req_lang = $lang;
if(!isset($_SESSION))
session_start();
if(isset($_REQUEST[LANG_PARAM])) {
@alexminza
alexminza / woocommerce_ga_snippet_output_userid.php
Last active December 28, 2023 02:15
WooCommerce Google Analytics Integration - add UserID tracking
<?php
//https://github.com/woocommerce/woocommerce-google-analytics-integration/blob/master/includes/class-wc-google-analytics-js.php
function woocommerce_ga_snippet_output_userid($code) {
$user_id = get_current_user_id();
if($user_id > 0) {
$ga_user_id = WC_Google_Analytics_JS::tracker_var() . "('set', 'userId', '" . $user_id . "');";
$code = $code . $ga_user_id;
}
@alexminza
alexminza / add_rss_featured_image.php
Created February 8, 2018 21:28
WooCommerce rss2_item action - add blog posts featured images to RSS feed