934Removing Nth lines from at Textfile

awk 'NR % 2 == 1' // every 2nd line
awk 'NR % 10 == 1' // every 10th line
awk 'NR % 100 == 1' // every 100th line

NR ordinal number of the current record<br/ > <br/ > X == 1 keeps the first line intact, whereas X == 0 would remove the first line. Important for CSV files.

925Creating a tar Archive

tar -vcf target.tar source

v → verbose
c → create
f → file. word followed by f will be name of archive, f needs to be last in the command.

924Connecting via SSH and Key

ssh -i ~/.ssh/path_to_key username@server

921Forcing a Database Upgrade in ACF/WordPress

Background:

A site that was developed some years ago with Wordpress 4.x and ACF 4.x got moved to a new server. During the migration process, Wordpress and the Plug-ins were updated to their latest version - I assume, before the MySQL DB got migrated, which let to the following complaint:

"ACF are not showing in ACF 5.x"

After some detective work, I realise that the data was still present. ACF v4.x was storing the ACF data in wp_options, ACF v5.x is storing it in wp_termmeta.

Which is great, because all that is needed, is to update the DB! But how to do it?

First attempt: Re-install ACF 4.4.12, then update to ACF 5.x

Didn't work as expected.

Second attempt: change the acf_version in wp_options

In the wp_options, the acf_version is set to the current WP version, 5.7.6 in this case. Setting it to 4.4.12, triggered the ACF DB update script, the ACF data got migrated to wp_termmeta, the site is working again as expected.

Shout out to the ACF Support Pages for solving the last piece of the puzzle.

918Permanent Redirect of all Subpages to new Server

LetsEncrypt will not autor-renew if it encounters a 301 Redirect. Which is NG, because it means httpswill stop working.
Not-so-elegant solution: use Redirecting with meta & refresh.

301 Redirect is great, if you want to keep you old structure and only change the server.

.htaccess

Redirect 301 / https://www.trembl.org/

Any page of your old.site/about would get redirected to https://www.trembl.org/about.

If you want to redirect all your page links from your old.site (e.g. old.site, old.site/aaa, old.site/bbb, ...) to https://www.trembl.org, use this RewriteRule:<

.htaccess

RewriteEngine On
RewriteRule ^(.*)$ https://www.trembl.org/ [R=301]

Meaning of 301 and 302

  • 301 Moved Permanently
  • 302 Moved Temporarily

916Order and ggplot2

Set Levels by Value x$name <- factor(x$name, levels = x$name[order(x$val)])

Set Levels by Name, Reverse Name Vector, first Name on top df$name <- factor(df$name, levels = rev(df$name))

TODO:

  • Explain/Understand R Factors
  • Add Example Data
  • Add Example Graphics

Source: https://rstudio-pubs-static.s3.amazonaws.com/7433_4537ea5073dc4162950abb715f513469.html

915SSH form OSX to Ubuntu – Locale Error

Problem: ‘std::runtime_error’ what(): locale::facet::_S_create_c_locale name not valid Aborted

Solution: export LC_ALL="en_US.UTF-8"

via http://martinhjelm.github.io/2015/06/14/Runtime-error-when-sshing-from-OSX-to-Ubuntu/

914Show WordPress Theme Menu

$l = get_nav_menu_locations(); $m = wp_get_nav_menu_items($l['footer-menu']); foreach($m as $i) { // $i->url; // $i->title; }

913WordPress functions.php

// update_option('siteurl','http://127.0.0.1/my-site'); // update_option('home','http://127.0.0.1/my-site');

// add excerpts to pages add_post_type_support('page', 'excerpt');

// remove auto-p in blog content remove_filter('the_content', 'wpautop');

// replace \n with <br /> // substitute
for line breaks in the content function addLineBreaks($content) { return str_replace("\n", "\n<br />", $content); } add_filter('the_content', 'addLineBreaks');

// register menu function register_theme_menu() { register_nav_menu('footer-menu', 'Footer Menu'); } add_action('init', 'register_theme_menu');

Show Wordpress Theme Menu

912WP Menus – Theme Setup & Menu as Array

functions.php function register_theme_menu() { register_nav_menu('my-menu', 'My Menu'); } add_action( 'init', 'register_theme_menu' );

Menu Location $l = get_nav_menu_locations(); $m = wp_get_nav_menu_items($l['my-menu']); foreach($m as $i) { // custom HTML echo $i->url; echo $i->title; }