Skip to content

Instantly share code, notes, and snippets.

View rayrutjes's full-sized avatar
🎸

Raymond Rutjes rayrutjes

🎸
View GitHub Profile
@thehesiod
thehesiod / freeze_time.sql
Created May 20, 2020 09:41
fake/mock now on postgres DB
-- inspiration from https://dba.stackexchange.com/questions/69988/how-can-i-fake-inet-client-addr-for-unit-tests-in-postgresql/70009#70009
CREATE SCHEMA if not exists override;
create table if not exists override.freeze_time_param_type
(
param_type text not null primary key
);
insert into override.freeze_time_param_type values ('enabled'), ('timestamp'), ('tick') on conflict do nothing;
@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
@eudesgit
eudesgit / class-acf-image-upload.php
Last active January 31, 2023 14:40
WordPress - Uploading images to Advanced Custom Fields (AFC)
<?php
class ACF_Image_Upload {
public $post_id;
function update_acf ( ) {
$attach_id = $this->get_image_attach_id('my-image.jpg');
// Saving image
@holmberd
holmberd / php-pools.md
Last active June 28, 2024 14:43
Adjusting child processes for PHP-FPM (Nginx)

Adjusting child processes for PHP-FPM (Nginx)

When setting these options consider the following:

  • How long is your average request?
  • What is the maximum number of simultaneous visitors the site(s) get?
  • How much memory on average does each child process consume?

Determine if the max_children limit has been reached.

  • sudo grep max_children /var/log/php?.?-fpm.log.1 /var/log/php?.?-fpm.log
<?php
namespace Mamdauka\WpQuerySpeed\Command;
use WP_CLI;
use WP_CLI\Utils;
use WP_CLI_Command;
use WP_Query;
use Symfony\Component\Stopwatch\Stopwatch;
@rveitch
rveitch / sync_acf_post_title.php
Last active December 7, 2022 21:40
Update WordPress post title from an ACF field value on save. (Advanced Custom Fields)
<?php
/**
* Update Post Title from an ACF field value on post save.
*
* Triggers on save, edit or update of published posts.
* Works in "Quick Edit", but not bulk edit.
*/
function sync_acf_post_title($post_id, $post, $update) {
$acf_title = get_field('my_acf_field_name', $post_id); // NOTE: enter the name of the ACF field here
///////////////////////////
// ES6 original
////////////////////////////
class A extends B {
constructor(x) {
this.x = x;
}
b() {return this.x};
}
@klmr
klmr / Makefile
Last active May 16, 2024 20:30
Self-documenting makefiles
# Example makefile with some dummy rules
.PHONY: all
## Make ALL the things; this includes: building the target, testing it, and
## deploying to server.
all: test deploy
.PHONY: build
# No documentation; target will be omitted from help display
build:
@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 {
@rponte
rponte / get-latest-tag-on-git.sh
Last active May 16, 2024 06:48
Getting latest tag on git repository
# The command finds the most recent tag that is reachable from a commit.
# If the tag points to the commit, then only the tag is shown.
# Otherwise, it suffixes the tag name with the number of additional commits on top of the tagged object
# and the abbreviated object name of the most recent commit.
git describe
# With --abbrev set to 0, the command can be used to find the closest tagname without any suffix:
git describe --abbrev=0
# other examples