Clippy
CSS
color-mix(in srgb, red 25%, blue)
CSS x JS
- change custom property on
:root/html:document.documentElement.style.setProperty(--var-name, val)
color-mix(in srgb, red 25%, blue):root/html: document.documentElement.style.setProperty(--var-name, val)/* alpha syntax */
color: rgba(255, 0, 255 / 75%); /* vs. rgba(…) */
color: rgba(255, 0, 255 / .75);
/* (HDR) color modes */
color: color(display-p3 1 0 1); /* vs. #F0F */
/* new color functions */
color: oklch(71.5% 0.35 330); /* vs. #F0F */
/* utilities */
color: color-mix(in lch, #F0F, white 20%);
/*
* keep a tab on …
*/
/* relative color syntax */
color: lch(from #F0F l calc(c + 75) h); /* increaces chroma by 75 */
/* color contrast */
color: color-contrast(var(--bg) vs #F0F, hotpink); /* pick the color that contrasts the most with --bg, choose between #F0F and hotpink)
:q,
:q!:wqi)
esc back to normal mode+p paste from clipboardxdduw:2:!<command>:set numberRandom selected notes regarding PHP
str_contains(string $haystack, string $needle): boolfunction someFunc(string $value, array $options) -> someFunc(options: $opt, value: $val)npm install -g @vue/clinew Vue({
el: '#app',
data: {
// supplied data
entries: datahere
},
computed: {
// computed data, will be updated if data changes
},
methods: {
// custom functions
}
})
<!-- SCOPE: -->
<div id="app">
<!-- accessible by vue -->
</div>
<div id="something">
<!-- NOT accessible by vue -->
</div>
(mehr …)if ("method" in object) {...}
// Example (from MDN):
if("geolocation" in navigator) { ... }
(from modernizr)
const hasSomeFeature = () => {
try {
// test something, eg. write to localStorage.
return true;
} catch(e) {
return false;
}
}
Create an instance of the Element in memory and test the porperty
if (!!document.createElement('element').property) {...}
// Example (from MDN):
function supports_canvas() {
return !!document.createElement('canvas').getContext;
}
if(supports_canvas()) { ... }
Remidner: !! returns the truthy value (bool).
equivalent of CSS’s @supports(property: value).
CSS.supports("property", "value")
equivalent of CSS’s @media
window.matchMedia('(max-width: 600px)');
check match with .matches (bool):
const mq = window.matchMedia('(max-width: 600px)');
// Checking for matches:
if (mq.matches) {
// media query matches!
}
// Listening for matches:
mq.addEventListener('change', e => {
if (e.matches) {
// ...
}
});
Careful: At the time of writing the addEventListener example does not work in Safari and IE, see browser compatibility table (MDN).
→ MDN, in depth: CSS Ttricks
More
java --version . Scala requires at least Version 1.8.brew cask install adoptopenjdkbrew install scalascala -version or running directly scala and outputting something like println("Moshi moshi").First compile with scalac providing filename/-path (including extension). This generates a file with the class name in the folder defined in the package entry (or, if omitted, in the same as the scala file) then run it by calling scala followed by the method name (without extension)
scalac script.scala
scala script
// package name
package ch.lrnz.example // binary will be generated in ch/lrnz/example
// imports
import import ch.lrnz.example.Functions // all, as 'package'
import import ch.lrnz.example.Utils._ // all, as single classes/methods
import java.util.Date
object myObject {
def main(args:Array[String]): Unit = {
// Void.
// Needed somehow? Otherwise: Compiling Error.
}
def myMethod(param1:Double,param2:Double):Double = {
// do sth and be sure to return a Double.
}
}
magick source.jpg -strip -interlace Plane -gaussian-blur 0.05 -quality 60% result.jpg
mogrify -quality 60 -density 72 -strip -resize 2500x1500\> -path ../foto-compressed *.jpg
In prose: This example sets the image quality to 60% and the dpi to 72, strips exif infos et al (only for png?) resizes the image if dimensions are bigger than 2500px w or 1500px heigh (keeping the aspect ratio [default]) and saving the news files at the specified (here: relative) path
Note the difference between the -densinty and the -resample option.
-compose <blendmode>
convert img1.png imgN.png -compose multiply -composite imgOut.png
Note: whithout -composite, every layer would be outputet separately
List all blend modes with identify -list compose
convert img1.png \( img2.png -alpha set -channel A -evaluate set 60% \) -composite imgOut.png
or:
convert img1.png \( img2.png -normalize +level 0,60% \) -composite imgOut.png
(not tested). Source
Copies the inner Text of a list (ordered or unordered) to the clipboard, one item per line.
Select the <ul> or <ol> element in the inspector, then run the following code in the console:
copy(Array.from($0.querySelectorAll('li'), el => el.innerText).join('\r\n'));
Explainer: Selects all <li> elements of the selected parent ($0), converts it to an Array (Array.from()since the returned node list is map‚able), get the innerText of those elements via map, the second parameter of Array.from(), join the Array to a Line-by-line string-list (otherwise we would get an array markup), then copy everything to clipboard.
Adapt to your own needs, e.g replace 'li' with 'img' and el.innerText with el.src to get all image urls.
👉 wrap code inside an IIFE in order to re-run it without an … alreay declared error:
(() => {
// function here
})();
A few strategies to «generate» (or rather multiply) content with JS.
Just copy/paste the contetn x times.
<div id="grid">
<div class="item">
...
</div>
</div>
const container = document.getElementById('grid');
container.insertAdjacentHTML('beforeend',container.innerHTML.repeat(3) );
Use template-tags and replace %placeholders% with data.
<template id="exampleTemplate">
<section>
<h1>%1%</h1>
...
</section>
</template>
<div id="dynamicContent"></div>
const expandTemplate = (id, data) => {
const template = document.querySelector(`#${id}`);
const target = document.querySelector('#dynamicContent');
data.forEach((dataPoint, index) => {
const instance = document.importNode(template.content, true);
// replace
const section = instance.querySelector('section');
section.innerHTML = section.innerHTML.replace( '%1%', dataPoint );
target.appendChild(instance);
});
}
expandTemplate( 'exampleTemplate', ['Hello', 'World', 'Data'] );
<template id="exampleTemplate">
<section>
...
</section>
</template>
<custom-section foo="bar"></custom-section>
<custom-section foo="doo"></custom-section>
class CustomSection extends HTMLElement {
connectedCallback() {
if (this.hasAttribute('foo')) {
const fooAtt = this.getAttribute('foo');
}
// use template
const template = document.querySelector('#exampleTemplate');
const instance = document.importNode(template.content, true);
// get content of instance – here the section tag:
// const section = instance.querySelector('section');
// do something with section ...
this.appendChild(instance);
}
}
customElements.define('custom-section', CustomSection);
(whithout shadow dom)
Collect styles from custom attributes and bundle them into a stylesheet.
<custom-section customStyle="background:salmon;color:white;"></custom-section>
<custom-section customStyle="background:rose;color:black;"></custom-section>
// function for appending custom style-sheet
const appendStyle = styles => {
let css = document.createElement('style');
css.type = 'text/css';
if (css.styleSheet){
css.styleSheet.cssText = styles;
}else{
css.appendChild(document.createTextNode(styles));
}
document.getElementsByTagName("head")[0].appendChild(css);
}
let styles="";
class CustomSection extends HTMLElement {
connectedCallback() {
// generate random ID
const randID = Math.ceil(Math.random() * 100000);
const id = `s-${randID}`;
if(this.hasAttribute('customStyle')) {
styles += `
#${id}{
${this.getAttribute('customStyle')}
}`;
}
// append template as in preceding example ...
}
}
customElements.define('custom-section', CustomSection);
// append styles
appendStyle(styles);
Notes from Tom Greenwood: Zero Carbon Emission talk (WordCamp Europe 2017)
HTML (note: 1x1px spacer gif as src)
<img class="lazy-img" src="data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==" data-src="lazyDog.jpg">
<img class="img lazy-img" ... >
JS:
const ioOpt = {
// root: null,
// threshold: 0.2
}
const ioCallback = (entries, observer) =>{
entries.forEach( entry => {
const img = entry.target;
if( entry.intersectionRatio > 0 ){
img.src = img.dataset.src;
observer.unobserve( img );
}
} );
}
const observer = new IntersectionObserver( ioCallback, ioOpt);
const targets = document.querySelectorAll(".lazy-img");
targets.forEach( target => {
observer.observe(target);
} );
Notes:
root ist omitted or null, the viewport is used as the root elementthreshold 0.0 – 1.0 how much (percentage) of the target hast to be intersecting with the root to fire the callbackentry.boundingClientRect.y is greater/lesser than entry.rootBounds.y. see: https://www.cyon.ch/blog/Mit-WP-CLI-WordPress-auf-der-Kommandozeile-verwalte
Troubleshooting section at the bottom of the page
wp plugin update [options below]--all : updates all plugins--dry-run : Preview which plugins would be updated.--exclude=<pluin-name(s)>wp core check-update and wp core updatewp option get blog_public1 to enable, 0 to disablewp config get wp core versionwp core verify-checksums--version=4.9.9 : Check for specific versionwp search-replace '//temporarydomain.com' '//finaldomain.com'--dry-run first to prevent f*#©<upsSee: Handbook
Install wp-cli locally, then add the aliases as follows to the wp-cli/config.yml
@aliasname
ssh: user@server/path/to/wp
@otheralias
ssh:otheru@others/path/to/wp
@aliasgroup
- @aliasname
- @otheralias
Usage: wp <aliasname|group|@all> <command>.
Examples:
wp @otheralias core check-updatewp @all option get blog_publicSee: WP-Cli Commands Handbook | Jason Yingling
\")v=$(wp @nekos core version);
/usr/bin/osascript -e "tell application \"Alfred 3\" to run trigger \"myTrigger\" in workflow \"ch.lnrz.wphelpers\" with argument \"$v\""
v=$(wp @nekos core version); runs the comands and stores it to the variable v/usr/bin/osascript -e "tell ... executes apple script which calls the external trigger myTrigger of the workflow ch.lnrz.wphelperswith the argument of the variable vSymptom: comand nof found: complete
For Tab completion in zsh use the following lines in the .zshrc or the sourced .bash_profile [s]:
autoload bashcompinit
bashcompinit
source ~/.wp-cli/wp-completion.bash
Symptom:command not found: wp
See: Making WP-CLI accessible on a remote server (WP Handbook)
=> third solution (before_ssh) worked for me (dont forget the <?php ... ?> Tags in the included file)
Reason: The built in uglify lib does not support ES6+ and throws an error if it stumbles upon something like const.
Solution: Use the uglify harmony branch (uglify-es) instead via a CodeKit hook
npm list -g uglify-es . If not install it globaly: npm install uglify-es -g (see the harmony repository )uglifyjs $CK_INPUT_PATH --compress --mangle -o $CK_OUTPUT_PATHSee the Comandline Usage section of the uglify-es repo for more options and the CodeKit hook help for constants for the CodeKit part of the deal.
ssh-keygenls ~/.sshcat ~/.ssh/id_rsa.pub | pbcopyeval ssh-agentssh-add -K ~/.ssh/<private key>code ~/.ssh/config :Host *
seKeychain yes
AddKeysToAgent yes
IdentityFile ~/.ssh/id_rsa
see: Atlassian
ssh-copy-id user@server
=> Client public key will be copied to server’s location ~/.ssh/authorized_keys
ssh user@server
grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
👉 allowed_block_types hook
add_filter( 'allowed_block_types', 'slug_allowed_block_types' );
function slug_allowed_block_types( $allowed_blocks ) {
return array(
'core/image',
'core/paragraph',
'core/heading',
'core/list'
);
}
Takes $post as a second parameter, so the allowed blocks can be set on a per post-type basis
add_filter( 'allowed_block_types', 'slug_allowed_block_types', 10, 2 );
function slug_allowed_block_types( $allowed_blocks, $post ) {
$allowed_blocks = array(
'core/image',
// ...
);
if( $post->post_type === 'page' ) {
$allowed_blocks[] = 'core/shortcode';
}
return $allowed_blocks;
}
Note:
if( 'page-template-name.php' == get_page_template_slug( $post ){ ... } but is only aplied when page with template already has been saved.Source: Misha Rudrastyh: Removing Default Gutenberg Blocks
function slug_remove_gutenberg_default_styles() {
if( !is_admin() ){
wp_dequeue_style( 'wp-block-library');
}
}
add_action( 'wp_print_styles', 'slug_remove_gutenberg_default_styles' );
(duplicate of Gutenberg notes entry)
// Disable color palette.
add_theme_support( 'editor-color-palette' );
// Disable color picker.
add_theme_support( 'disable-custom-colors' );
Note: As with all add_theme_support methods hook into after_setup_theme
Source: Theme Coder
Predefined blocks per post type.
function slug_add_template_to_page() {
$post_type_object = get_post_type_object( 'page' );
$post_type_object->template = array(
array( 'core/paragraph', array(
'placeholder' => 'Add Description...',
) ),
array( 'core/image', array(
) ),
);
$post_type_object->template_lock = 'all';
}
add_action( 'init', 'slug_add_template_to_page' );
->template-lock :'all' : prevents all block manipulation (changing order adding, removing)'insert' : prevents inserting or removing blocks but allows chaning the orderadd_theme_support( 'editor-font-sizes') removes the Buttons (S,M,L,XL) but leaves the reset button Follwing along Zac Gordons Gutenberg Development Course.
Insert:
icon: property __() methods in phpAll of these libs are accessible globaly (e.g. through the console or other scripts)
To access them within code, use something like
const { __ } = wp.i18n; // using deconstruction
Default roadmap:
registerBlockType() [js]enque_block_edtior_assets: hook for enquing block js+css in the editor (not the frontend). Used to enque the main block js file, or editor-only styles.enque_block_assets : hook to enque (mostly) css (and js) for both, the editor and the front end. User for main block styles. Use !is_admin()for front-end-only styles/scripts wp.blocks.registerBlockType(
'plugin-name/block-name',
{
title: wp.i18n.__('Blocktitle', 'textdomain),
description: '...',
category: 'common',
icon: 'wordpress-alt',
keywords: [wp.i18n.__('Demo', 'textdomain)],
supports: { html: false },
attributes: {} ,
edit: () => {},
save: () => {}
}
);
Which information to (re-)store and manipulate
attributes {
message: {
type: "array",
source: "children",
selector: ".classname-of-element"
},
}
Controls how the block is rendered (and updated) in the editor.
Usualy constists of a return method as well as a method that handles what hapens onChange (e.g. text editing). props ( React, anyone?) are passed on automatically from WP.
edit: props => {
const {
attributes: { message },
className,
setAttributes
} = props;
const onChangeMessage = message => {
setAttributes({ message });
};
return {
<div className={className}>
<RichText
tagName="div"
multiline="p"
placeholder={__("Type something ...", "textdomain")}
onChange={onChangeMessage}
value={message}
/>
</div>
}
}
How to save the post – for displaying on the front end and restoring for the editor.
save: props => {
const {
attributes: { message }
} = props;
return (
<div>
<div class="output-feld">{message}</div>
</div>
);
}
attributes: {
content: {
...
}
}
edit: props => {
const { attributes: { content }, setAttributes } = props;
...
return (
<RichText
...
onChange={ content => { setAttributes( { content } ) } }
value={ content }
>
);
wp.data.<STORE_NAME> (stores: „core/editor“, „core/blocks“, „core/editor“ …, to check them out log wp.data.select("<STORE_NAME>") [or dispatch instead of select])
(import: const { <STORE_NAME> } = wp.data)
=> get data
select("core/editor").getBlockCount();
=> subscribe/listen to status change
subscribe(() => {
// updated every time the block count changes
const blockCount = select("core/editor").getBlockCount();
});
Note: subscribe returns a unsubscribe function
const unsubscribe = subscribe(()=>{ /* ... */ });
unsubscribe();
Subscribe Class to controll the state handling (otherwise you might want to use withSelect) – more Reactish, less WP abstraction
const { Component } = wp.element;
const { select, subscribe } = wp.data;
export default class SubscribeDemo extends Component{
state = {
blockCount: "",
}
componentDidMount() {
const unsubscribe = subscribe( () => {
const blockCount = select("core/editor").getBlockCount();
this.setState({blockCount});
} );
}
render() {
return <p>Block count: {this.state.blockCount}</p>
}
}
Key-Points:
state object ( => React )this.statethis.setState() [see: React]componentDidMount()method [see: React]render() function=> HOC [?] for select, similar to subscribe it will update everytime its values changes
As component:
const WithSelectDemo = ({ blockCount }) => (
<p>Block Count: {blockCount}</p>
)
export default withSelect( (select, ownProps) => {
return {
blockCount: select("core/editor").getBlockCount()
}
} )(WithSelectDemo);
First code block: Create <WithSelectDemo /> component that takes the current block count as an argument (and prints it)
Second code block: Export withSelect()(WithSelectDemo):
<WithSelectDemo />is exported/used …withSelect()…select() (getting the block count) …blockCount…<WithSelectDemo /> component (which takes it as its argument)Notice the ownProps parameter for the withSelect()above. It will get all props (think: attributes) passed into the component (and can be passed on to the component, of course)
<WithSelectDemo text="blah" />
export default withSelect( (select, ownProps) => {
console.log(ownProps) // logs: {text: "blah"}
return {
...
}
...
=> calling an action
dispatch( "core/editor" ).removeBlock( clientID ) // clientID = BlockID
=> HOC [?] for dispatch
//TODO
=> HOC [?] for combining multiple HOC’s (Takes an array of HOCs and returns a new component)
// Todo