Skip to content

Instantly share code, notes, and snippets.

@k1sul1
k1sul1 / class.vite.php
Created June 8, 2022 11:44
"Basic" Vite & WP theme setup
<?php
namespace k1;
class ViteAsset {
public $file = null;
public $src = null;
public $isEntry = false;
public $isDynamicEntry = false;
@k1sul1
k1sul1 / index.js
Last active June 27, 2023 20:02
Express.js server with a proxy and session management for making authenticated requests to WP without the gray hairs of OAuth
const express = require('express')
const cors = require('cors')
const bodyParser = require('body-parser')
const session = require('express-session')
const redis = require('redis')
const RedisStore = require('connect-redis')(session)
const axios = require('axios')
const csurf = require('csurf')
const cookieParser = require('cookie-parser')
const listEndpoints = require('express-list-endpoints')
@k1sul1
k1sul1 / yolo
Created May 11, 2021 02:06
Created from Remix Form!
not really
@k1sul1
k1sul1 / test
Created May 11, 2021 02:04
Created from Remix Form!
xxx
find Original -type d | sed 's/^Original/Resized/' | tr '\n' '\0' | xargs -0 mkdir -p
for f in (find Original -type f -name '*.png'); convert "$f" -resize 'x256>' (string replace Original Resized "$f"); end
# images need to be inside folder called Original, they will be sized to be 256 wide
@k1sul1
k1sul1 / mousemove.ts
Created May 11, 2020 13:30
I spent way too much time digging the correct properties. For future reference.
function onMouseMove(event, initialX: number, initialY: number) {
const { clientX, clientY, movementX, movementY } = event
const moving = {
left: movementX < 0
right: movementX > 0
up: movementY < 0
down: movementY > 0
}
@k1sul1
k1sul1 / webpack.config.babel.js
Last active December 15, 2023 18:47
Webpack configuration for building a WordPress plugin with React and Typescript
const path = require("path");
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const ManifestPlugin = require("webpack-manifest-plugin");
const WriteFilePlugin = require("write-file-webpack-plugin");
const TerserJSPlugin = require("terser-webpack-plugin");
const OptimizeCSSAssetsPlugin = require("optimize-css-assets-webpack-plugin");
const BundleAnalyzerPlugin = require("webpack-bundle-analyzer")
.BundleAnalyzerPlugin;
@k1sul1
k1sul1 / wordpress.types.ts
Created April 28, 2020 15:44
Mostly autogenerated type defs for WordPress REST API
// Below: Autogenerated types from Quicktype. They have been modified by hand.
// ACF fields in standard endpoints do not exist out of the box, you have to add them yourself.
// k1sul1/k1kit does that for you automagically.
// To parse this data:
//
// import { Convert, RawStoneData, Texts, Taxonomies, PostTypes, PostStatuses } from "./file";
//
// const taxonomies = Convert.toTaxonomies(json);
// const tags = Convert.toTags(json);
@k1sul1
k1sul1 / build-non-split.js
Created April 1, 2020 14:45
Build create-react-app to a single file. Useful for things like WordPress plugins.
const rewire = require('rewire');
const defaults = rewire('react-scripts/scripts/build.js');
let config = defaults.__get__('config');
config.optimization.splitChunks = {
cacheGroups: {
default: false,
},
};
@k1sul1
k1sul1 / yolo.php
Created January 9, 2020 19:44
Get all translations of post content from a value translated with qtranslate-x
<?php
$post = $GLOBALS['post'];
$wpdb = $GLOBALS['wpdb'];
// :trollface:
// qtranslate is not a very nice tool
$id = (int) $post->ID; // No injections here
$raw = $wpdb->get_var("SELECT post_content from $wpdb->posts WHERE ID = $id");
$extractor = function($lang = 'fi') use ($raw) {