Skip to content

Instantly share code, notes, and snippets.

View msaari's full-sized avatar

Mikko Saari msaari

View GitHub Profile
@msaari
msaari / Solarized Dark Colourful.itermcolors
Created November 28, 2019 11:27
Solarized Dark Colourful color settings for iTerm2
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Ansi 0 Color</key>
<dict>
<key>Alpha Component</key>
<real>1</real>
<key>Blue Component</key>
<real>0.25332435965538025</real>
@msaari
msaari / wp_remote_get_with_cache.php
Last active December 15, 2021 21:13
wp_remote_get_with_cache – Fetches remote data with dual-layer caching
<?php
/**
* Fetches remote data with dual-layer caching.
*
* Uses wp_remote_get to fetch remote data. The data is cached twice: it's
* stored in a transient and an option. The transient is used as the main cache
* but if the transient has expired and the remote site doesn't respond,
* backup data from the option is returned.
*
@msaari
msaari / multi-version-tests.sh
Created November 17, 2019 04:39
Test runner for running PHPUnit tests with many WordPress versions
#!/bin/sh
# Test runner for running Phpunit tests against multiple WordPress versions.
# Will fetch and install different WordPress versions in this directory:
BASE_PATH=~/multiwptest
if [ ! -d $BASE_PATH ]
then
echo "ERROR: Test directory $BASE_PATH is missing."
@msaari
msaari / composer.json
Created November 17, 2019 04:33
Relevanssi package test composer.json
{
"repositories": [
{
"type": "package",
"package": {
"name": "relevanssi/relevanssi-premium",
"version": "2.4.4",
"type": "wordpress-plugin",
"dist": {
"type": "zip",
@msaari
msaari / test-indexing.php
Created November 17, 2019 04:19
Tests the relevanssi_no_image_attachments function and feature.
<?php
/**
* Tests the relevanssi_no_image_attachments function and feature.
*/
public function test_no_image_attachments() {
$this->delete_all_posts();
$image_attachment = array(
'post_title' => 'cat gif',
'post_mime_type' => 'image/gif',
'post_type' => 'attachment',
@msaari
msaari / phpunit.xml
Created November 17, 2019 03:59
PHPUnit configuration from Relevanssi
<phpunit
bootstrap="tests/bootstrap.php"
backupGlobals="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
>
<php>
<ini name="display_errors" value="true"/>
@msaari
msaari / gist:69ea41f2d9f57fe27a841edd4b2a62b2
Last active November 17, 2019 08:45
Anna-Kaari Hakkarainen: Dioraama, s. 304–307
Rakas Karl, olen pahoillani, etten koskaan vastannut sinulle. Haluan että tiedät tämän:
se johtui pelosta, elämisen pelosta. Ajattein, että en pystyisi elämään odotusten mukaisesti.
Ajattelin, että ihminen tarvitsee tabun. En usko siihen enää. Nyt tiedän, että ihminen
tarvitsee ihmettä, arjen yläpuolelle nousevaa. Rakkautta. Yhteyttä. Suggestiota. Kaikkea sitä
mitä me olimme.
Rakastin ja rakastan sinua enemmän kuin mitään koskaan. Anna anteeksi.
Mutta ajattele, jos onnistun, saamme elää ikuisesti yhdessä. Ikuisesti! Unohtaminen on
kuolemista. Sinä et unohda ikinä. Et unohda meitä.
@msaari
msaari / rlv_category_pinning.php
Created November 2, 2019 03:35
Relevanssi product category pinning
<?php
/**
* This will lift all the product categories in the results on top of the results.
*/
add_filter( 'relevanssi_hits_filter', 'rlv_lift_category', 20 );
function rlv_lift_category( $hits ) {
$categories = array();
$other_posts = array();
foreach ( $hits[0] as $hit ) {
@msaari
msaari / intermediary.php
Last active March 28, 2023 13:52
Relevanssi attachment indexing server intermediary script
<?php
/**
* Attachment processing intermediary to work between Relevanssi and a Tika server.
*
* Installation instructions:
* 1. Save this as index.php.
* 2. Change the Tika server URL in the constructor to point to your own Tika server.
* 3. Upload this file in a directory on your server.
*
* @author Mikko Saari (mikko@mikkosaari.fi)
@msaari
msaari / relevanssi-date-query.php
Last active August 29, 2019 10:23
Natural-language date querying for Relevanssi
<?php
add_filter( 'relevanssi_modify_wp_query', 'rlv_date_query' );
function rlv_date_query( $query ) {
$time = strtotime( $query->query_vars['s'] );
if ( $time ) {
$year = date( 'Y', $time );
$use_year = strpos( $query->query_vars['s'], $year ) !== false ? true : false;
$month = date( 'm', $time );
$day = date( 'd', $time );