Skip to content

Instantly share code, notes, and snippets.

View rayrutjes's full-sized avatar
🎸

Raymond Rutjes rayrutjes

🎸
View GitHub Profile
@rayrutjes
rayrutjes / detectcontenttype.go
Created December 12, 2015 13:36
golang detect content type of a file
file, err := os.Open(path)
if err != nil {
return err
}
defer file.Close()
// Only the first 512 bytes are used to sniff the content type.
buffer := make([]byte, 512)
_, err = file.Read(buffer)
if err != nil {
@rayrutjes
rayrutjes / Spitfire LABS Drums mapping.txt
Last active November 18, 2020 20:11
Spitfire LABS Drums mapping for Megababy 2
36 Bass
37 Bass alt.
38 Snare
39 Snare (Rim Hit)
40 Rim Click
41 Rim Click Alt.
42 High-Hat Closed
43 Floor Tom
44 High-Hat Half Open
45 Mid Tom
@rayrutjes
rayrutjes / base64-kubernetes-secret.sh
Created December 4, 2019 09:24
Base64 encode file as Kubernetes secret properly dealing with line breaks
echo -n "$(cat private.key)" | base64 | tr -d '\n' | pbcopy
@rayrutjes
rayrutjes / search-by-algolia-for-woocommerce.php
Created September 23, 2016 11:14
This is a boilerplate for using Algolia in WooCommerce
<?php
/**
* @wordpress-plugin
* Plugin Name: Search by Algolia for WooCommerce - Instant & Relevant results
*/
/**
* If Algolia is not active, let users know.
@rayrutjes
rayrutjes / fix-broken-php-serialized-data.php
Created June 9, 2019 16:57
Helper to fix broken PHP serialized data. Helpful mostly on broken WordPress databases.
<?php
$data = <<< EOF
The broken serialized data goes here.
And can expand on multiple lines.
EOF;
$data = preg_replace_callback ('!s:(\d+):"(.*?)";!', function($match) {
return ($match[1] == strlen($match[2])) ? $match[0] : 's:' . strlen($match[2]) . ':"' . $match[2] . '";';
}, $data);
@rayrutjes
rayrutjes / remove-html-tags-wordpress-algolia-plugin.php
Created November 20, 2018 09:37
Remove HTML tags from title - Algolia WordPress plugin
<?php
function remote_html_tags( array $shared_attributes, WP_Post $post) {
$shared_attributes['post_title'] = strip_tags( $shared_attributes['post_title'] );
return $shared_attributes;
}
add_filter( 'algolia_post_shared_attributes', 'remote_html_tags', 10, 2 );
@rayrutjes
rayrutjes / autocomplete-show-more-link-footer-dynamic.js
Created September 13, 2018 14:55
Dynamic show more results like algolia autocomplete
@rayrutjes
rayrutjes / hide-autocomplete.php
Created July 23, 2018 14:42
Hide autocomplete snippet on custom condition - WordPress - Algolia
<?php
add_filter( 'algolia_autocomplete_config', function ( $config ) {
if (true) { // Replace this condition to match your needs.
// Autocomplete enabled.
return $config
}
@rayrutjes
rayrutjes / algolia-wordpress-exclude-home-page.php
Last active July 20, 2018 12:31
Exclude home page WordPress Algolia plugin
<?php
// functions.php
define( 'CUSTOM_HOME_ID', 2 );
function custom_should_index_post( $flag, WP_Post $post ) {
if ( $post->post_type === 'page' && $post->ID === CUSTOM_HOME_ID ) {
return false;
}
@rayrutjes
rayrutjes / evicted-pods-cleanup.sh
Created July 19, 2018 13:37
Cleanup evicted pods - Kubernetes
kubectl get pod -a --all-namespaces -o json \
| jq '.items[] | select(.status.reason!=null) | select(.status.reason | contains("Evicted")) | "kubectl delete pod \(.metadata.name) -n \(.metadata.namespace)"' \
| xargs -n 1 bash -c