Skip to content

Instantly share code, notes, and snippets.

Avatar
🙃
working ...

Dimas Begunoff farinspace

🙃
working ...
View GitHub Profile
View add-source-meta.php
<?php
add_action( 'add_meta_boxes', 'my_register_meta_boxes' );
/**
* Register meta boxes.
*/
function my_register_meta_boxes() {
// id, title, callback, screen, context, priority, callback_args
add_meta_box( 'nooz-meta-box__coverage-source', 'Source', 'my_get_source_meta_box', 'nooz_coverage', 'normal', 'high', NULL );
@farinspace
farinspace / element-closest-polyfill.js
Created Nov 15, 2019
Element.closest(selector) polyfill
View element-closest-polyfill.js
/**
* Element.closest(selector) polyfill
*
* https://developer.mozilla.org/en-US/docs/Web/API/Element/closest#Polyfill
*/
(function(){
if (!Element.prototype.matches) {
Element.prototype.matches = Element.prototype.msMatchesSelector || Element.prototype.webkitMatchesSelector;
}
if (!Element.prototype.closest) {
@farinspace
farinspace / custom-event-polyfill.js
Last active Nov 15, 2019
CustomEvent() polyfill
View custom-event-polyfill.js
/**
* CustomEvent() polyfill
*
* https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent/CustomEvent#Polyfill
* https://caniuse.com/#feat=customevent
* https://developer.mozilla.org/en-US/docs/Web/Guide/Events/Creating_and_triggering_events
*/
(function(){
if (typeof window.CustomEvent === "function") return false;
function CustomEvent(event, params) {
@farinspace
farinspace / functions.php
Created May 10, 2019
Filter Nooz posts by custom-field values
View functions.php
<?php
/**
* The solution below allows you to filter Nooz posts by custom-field values.
*
* 1. Enable support for "custom-fields"
* 2. Add a custom field variable to a press release post, in the example below, the variable is "lang_type"
* 3. Use the "class" attribute to determine which shortcode instance gets filtered, in the example below, shortcodes using "class='lang-es'"
*/
@farinspace
farinspace / functions.php
Created Mar 13, 2019
Alter "posts_per_rss" option with querystring param to limit the number of posts returned for an RSS Feed
View functions.php
<?php
/**
* Alter "posts_per_rss" option with querystring param to limit the number of posts returned for an RSS Feed.
*/
add_filter( 'option_posts_per_rss', 'my_posts_per_rss' );
function my_posts_per_rss( $option ) {
if( isset( $_GET['limit'] ) ) {
return (int) $_GET['limit'] ?: $option;
}
@farinspace
farinspace / trim_non_alphanum.php
Created Aug 6, 2018
Trim non alpha-numeric characters from the beginning and end of a string
View trim_non_alphanum.php
<?php
function trim_non_alphanum( $str ) {
$str = preg_replace( '/^[^[:alnum:]]+/u', '', $str ); // beginning
return preg_replace( '/[^[:alnum:]]+$/u', '', $str ); // end
}
@farinspace
farinspace / nginx.conf
Created Jul 17, 2018
Prevent long caching in subdirectory for a WPEngine install
View nginx.conf
# Request is cached for at maximum of 10 minutes, then origin revalidation starts
# Clients that send "If-Modified-Since" headers will recieve 304 response unless the file actually changes on origin
# Use: `add_header Last-Modified ""` to remove Last-Modified server headers
location ~* ^/wp-content/themes/theme/subdir/ {
add_header Cache-Control "public, max-age=600, must-revalidate";
etag off;
}
@farinspace
farinspace / main.cf
Last active Jul 16, 2018
MacOS X postfix relyhost mail setup
View main.cf
...
# append to /etc/postfix/main.cf
relayhost=smtp.sendgrid.net:587
smtp_sasl_auth_enable=yes
smtp_sasl_password_maps=hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options=
smtp_use_tls=yes
smtp_tls_security_level=encrypt
tls_random_source=dev:/dev/urandom
@farinspace
farinspace / apache2.conf
Created Jun 10, 2018
Remove time from Apache directory listings
View apache2.conf
<IfModule mod_autoindex.c>
IndexHeadInsert "<script>window.onload=function(){document.querySelectorAll('tr td:nth-child(3)').forEach(function(td){if(td&&td.innerText.indexOf('-')>=0)td.innerHTML=td.innerText.match(/\d{4}-\d{2}-\d{2}/)[0]})}</script>"
</IfModule>
@farinspace
farinspace / x11vnc.md
Last active Mar 19, 2020
x11vnc setup solution, Ubuntu 18.04 LTS
View x11vnc.md

Make and Make install

See x11vnc stack smashing detected solution

Recommended version: x11vnc: 0.9.14 lastmod: 2013-11-21

.Xauthority

Set desktop to auto login and prevent screen locking .. else you will need to deal with Xauth

You can’t perform that action at this time.