Skip to content

Instantly share code, notes, and snippets.

View spacetrack's full-sized avatar

Björn Winkler spacetrack

  • Gröbenzell, Munich, Germany
View GitHub Profile
<?php
$mymenu = wp_get_nav_menu_object('Main Navigation Menu');
$menuID = (int) $mymenu->term_id;
$myPage = get_page_by_title('About Us');
itemData = array(
'menu-item-object-id' => $myPage->ID,
'menu-item-parent-id' => 0,
'menu-item-position' => 2,
<?php
class EvalFileWithArgs_Command extends WP_CLI_Command {
/**
* Load and execute a PHP file after loading WordPress.
*
* ## EXAMPLES
*
* wp eval-file-with-args my-code.php arg1 arg2 arg3 arg4 arg5 arg6 arg7 arg8 arg9
// always exclude the first story from index pages!
if (!function_exists('archive_exclude_first_post')) {
function archive_exclude_first_post($query)
{
if (is_admin() || !is_archive() || !$query->is_main_query()) {
return;
}
$offset = 1;
$posts_per_page = get_option('posts_per_page');
#!/bin/bash
echo $#
this_date=`date +"%Y-%m-%d"`
this_time=`date +"%H:%M:%S"`
if [ $# -eq 1 ]
then
this_date=`date +"%Y-%m-%d"`
this_time=${1}
@spacetrack
spacetrack / urand.sh
Created January 25, 2016 15:33
print 3 * 4 random chars, exclude upper i "I", upper and lower o "O", lower L "l"
#!/bin/bash
# print 3 * 4 random chars, exclude upper i "I", upper and lower o "O", lower L "l"
for i in 1 2 3; do cat /dev/urandom | tr -cd 'A-HJ-NP-Za-kmnp-z0-9' | head -c4; if [ "$i" -eq "3" ]; then echo; else echo -n "."; fi; done
@spacetrack
spacetrack / indirect_reference.sh
Last active April 15, 2016 09:56
BASH Indirect Reference
#!/usr/bin/env bash
table_row_0=("Planet" "Size" "Distance")
table_row_1=("Mercury" 4879 "55")
table_row_2=("Venus" 12103 "108")
table_row_3=("Earth" 12735 "150")
table_row_4=("Mars" 6772 "228")
table_row_5=("Jupiter" 138346 "778")
table_row_6=("Saturn" 114632 "1433")
table_row_7=("Uranus" 50532 "2872")
@spacetrack
spacetrack / minimal-web-api-with-endpoint-logging.md
Last active October 18, 2022 03:02
.NET 6 Minimal Web API with Endpoint Logging

.NET 6 Minimal Web API with Endpoint Logging

with your project set to C# 10 (add <LangVersion>preview</LangVersion> to your .csproj file), in your Program.cs simply add ILogger<Program> logger to your endpoint delegate:

using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
@spacetrack
spacetrack / oop-2020.md
Last active August 26, 2023 01:47
Notizen von der OOP 2020

OOP 2020

Notizen von der OOP 2020 (München)


AWS Fargate

  • sozusagen Konkurrenz zu Kubernetes
  • geeignet für kleine Aufgaben, z. B. Batch-Jobs
@spacetrack
spacetrack / bash-multidimension-array.md
Last active August 26, 2023 03:52
bash: mehrdimensionale Arrays

bash: mehrdimensionale Arrays

In BASH gibt es keine mehrdimensionalen Arrays ...

... mag man kaum glauben, ist aber so. Doch es gibt einen Ausweg: man kann es über key/value-Hash-Arrays simulieren, das ist aber aus verschiedenen Gründen unpraktisch (und deckt maximal zweidimensionale Arrays ab, auch wenn das meist reicht). Eine zweite Methode ist die "Indirekte Referenz", dem “value of a value”, kurz gesagt $$var, gut lesbar mittels ${!var}.

Ein Beispiel: