Skip to content

Instantly share code, notes, and snippets.

View farinspace's full-sized avatar
🙃
working ...

Dimas Begunoff farinspace

🙃
working ...
View GitHub Profile
@farinspace
farinspace / x11vnc.md
Last active November 6, 2021 20:53
x11vnc setup solution, Ubuntu 18.04 LTS

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

@farinspace
farinspace / combos.php
Last active February 4, 2021 11:56
Recursive functions, I can never find exactly what I need in a pinch
<?php
function combos($data, &$all = array(), $group = array(), $val = null, $i = 0) {
if (isset($val)) {
array_push($group, $val);
}
if ($i >= count($data)) {
array_push($all, $group);
} else {
foreach ($data[$i] as $v) {
@farinspace
farinspace / add-source-meta.php
Created November 25, 2019 03:34
Adding meta boxes
<?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 November 15, 2019 17:31
Element.closest(selector) polyfill
/**
* 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 November 15, 2019 17:30
CustomEvent() polyfill
/**
* 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 03:54
Filter Nooz posts by custom-field values
<?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 March 13, 2019 17:41
Alter "posts_per_rss" option with querystring param to limit the number of posts returned for an RSS Feed
<?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 / php_clean_function.php
Created July 6, 2011 23:35
PHP function to clean an array recursively
function clean(&$arr)
{
if (is_array($arr))
{
foreach ($arr as $i => $v)
{
if (is_array($arr[$i]))
{
clean($arr[$i]);
# NGINX CodeIgniter Config
server
{
server_name .organizetheweb.com;
access_log /var/log/nginx/organizetheweb.com.access.log;
root /var/www/organizetheweb.com/trunk;
@farinspace
farinspace / trim_non_alphanum.php
Created August 6, 2018 17:28
Trim non alpha-numeric characters from the beginning and end of a string
<?php
function trim_non_alphanum( $str ) {
$str = preg_replace( '/^[^[:alnum:]]+/u', '', $str ); // beginning
return preg_replace( '/[^[:alnum:]]+$/u', '', $str ); // end
}