Skip to content

Instantly share code, notes, and snippets.

View stoph's full-sized avatar
🏎️

Christoph Khouri stoph

🏎️
View GitHub Profile
@stoph
stoph / code.gs
Created July 11, 2024 00:38
Google Sheets selection script
var trackingCell = 'O1';
function onEdit(e) {
var sheet = e.source.getActiveSheet();
var range = e.range;
if (sheet.getName() === 'People' && range.getColumn() === 2) {
var selectedPeople = [];
var peopleRange = sheet.getRange('A2:B'); // Adjust range as needed
var values = peopleRange.getValues();
@stoph
stoph / gist:519ecc72fc5d7856a8e4b79d8724e8d2
Created July 8, 2024 21:56
Dynamic URL parameters for WP pages
<?php
/**
* Plugin Name: Dynamic Parameters
*/
$dynamic_page_slugs = [
'product-detail' => [ // product-detail/12345/awesome_product
'product_id' => '(\d+)',
'product_name' => '([a-zA-Z0-9-_]+)',
],
@stoph
stoph / Serve and Open.workflow
Created June 24, 2024 20:17
Quick Action to serve a file or folder (using php)
on run {input, parameters}
set inputPath to POSIX path of (item 1 of input)
set isFolder to (do shell script "test -d " & quoted form of inputPath & " && echo true || echo false") as boolean
set folderPath to ""
set urlPath to "http://localhost:8124"
if isFolder then
set folderPath to inputPath
else
@stoph
stoph / convert.py
Created February 23, 2024 20:58
Convert Shopify's products.json to csv file for import
# https://<shopify.store.com>/products.json?limit=250 (defaults to 30)
import csv
import json
def convert_json_to_csv(json_file, csv_file):
with open(json_file, 'r', encoding='utf-8') as file:
data = json.load(file)
products = data['products']
@stoph
stoph / gist:7bb7fe09c85ec1fac58b34c7dfc1ea1b
Created November 29, 2023 15:53
Show Mac App Switcher on all screens
# Enable
defaults write com.apple.dock appswitcher-all-displays -bool true; killall Dock;
# Revert
defaults delete com.apple.Dock appswitcher-all-displays; killall Dock
@stoph
stoph / gist:1fa9d20cf34fdab87e6d6667f1d3e5d0
Created September 18, 2023 15:42
Expandable Textarea
/**
* Expands a textarea element to fit its content up to a maximum height.
* @param {string} id - The id of the textarea element.
* @param {number} [maxHeight=0] - The maximum height of the textarea element. 0 for no maximum.
* @author Christoph Khouri <christoph.khouri@gmail.com>
*/
function expandableTextarea(id, maxHeight = 0) {
const textarea = document.getElementById(id);
textarea.style.height = 'auto';
textarea.style.height = (textarea.scrollHeight) + 'px';
namespace
{
template<typename T1>
void debug(T1 v){
#ifdef ENABLE_DEBUG
Serial.println(v);
#endif
}
template<typename T2>
@stoph
stoph / section_titles.py
Last active February 7, 2022 17:07
Extract all section titles from MMPs
from progressbar import ProgressBar
import requests
from lxml import html
import os
import tqdm
pbar = ProgressBar()
filename = "mmp.urls"
@stoph
stoph / Car_and_Driver-full_screen_image.js
Created November 2, 2021 00:40
Bookmarklet to view a gallery image from Car and Driver full screen
javascript:void%20function(){function htmlToElement(e){var t=document.createElement("template");return e=e.trim(),t.innerHTML=e,t.content.firstChild}var img=document.getElementsByClassName("active")[0].getElementsByClassName("slide-image-wrap")[0].getElementsByTagName("picture")[0].getElementsByTagName("img")[0],img_src=img.src.split("?")[0];document.body.appendChild(htmlToElement('<div id="view_image" style="display:flex;position:fixed; max-width: 100%;max-height: 100%;z-index:999; top: 0; left:0;" onclick="this.remove()"><img style="object-fit: contain;width:auto;height:auto;object-fit: contain;" src="'+img_src+'"></div>'));}();
@stoph
stoph / github1s-new-window.js
Created February 12, 2021 21:07
Opens a new window for github1s from a github page.
javascript: if(window.location.hostname=="github.com")window.open(window.location.href.replace('github.com', 'github1s.com'));