Skip to content

Instantly share code, notes, and snippets.

@georgestephanis
georgestephanis / client.js
Last active Jul 11, 2021
This is an example client app to integrate with the WordPress 5.6 Application Passwords system. It walks the user through authenticating, and then queries and enumerates all users on the site.
View client.js
(function($){
const $root = $( '#root' );
const $stage1 = $( '.stage-1', $root );
const $stage2 = $( '.stage-2', $root );
// If there's no GET string, then no credentials have been passed back. Let's get them.
if ( ! window.location.href.includes('?') ) {
// Stage 1: Get the WordPress Site URL, Validate the REST API, and Send to the Authentication Flow
const $urlInput = $( 'input[type=url]', $stage1 );
@thatdevgirl
thatdevgirl / simple-autocomplete.js
Created Nov 29, 2018
Simple Autocomplete component for WP Gutenberg
View simple-autocomplete.js
/**
* A very simple autocomplete component
*
* This is to replace the OOTB Gutenberg Autocomplete component because it is
* currently broken as of v4.5.1.
*
* See Github issue: https://github.com/WordPress/gutenberg/issues/10542
*
* Note: The options array should be an array of objects containing labels and values; i.e.:
* [
@connerbw
connerbw / EventEmitter.php
Last active Jan 28, 2021
Refactor Your Slow Form Using PHP Generators and Event Streams
View EventEmitter.php
<?php
/**
* @license GPLv3 (or any later version)
* @see http://kizu514.com/blog/refactor-your-slow-form-using-php-generators-and-event-streams/
*/
namespace KIZU514;
class EventEmitter
{
@tombigel
tombigel / README.md
Last active Nov 22, 2021 — forked from a2ikm/limit.maxfiles.plist
How to Change Open Files Limit on OS X and macOS Sierra (10.8 - 10.12)
View README.md

How to Change Open Files Limit on OS X and macOS

This text is the section about OS X Yosemite (which also works for macOS Sierra) from https://docs.basho.com/riak/kv/2.1.4/using/performance/open-files-limit/#mac-os-x

The last time i visited this link it was dead (403), so I cloned it here from the latest snapshot in Archive.org's Wayback Machine https://web.archive.org/web/20170523131633/https://docs.basho.com/riak/kv/2.1.4/using/performance/open-files-limit/

Mac OS X

To check the current limits on your Mac OS X system, run:

View standardDeviation.js
let orders = [26, 3, 5, 7, 8, 5, 0, 8, 4]
let arrSum = arr => (arr.reduce((x, accumulate) => accumulate + x, 0))
let avgOrders = arrSum(orders)/orders.length
console.log(avgOrders)
let differences = orders.map(x => x - avgOrders).map(x => x * x)
console.log(differences)
@yairEO
yairEO / jQuery.ajaxRetry.js
Last active Jul 17, 2020
jQuery AJAX smart retry
View jQuery.ajaxRetry.js
// enhance the original "$.ajax" with a retry mechanism
$.ajax = (($oldAjax) => {
// on fail, retry by creating a new Ajax deferred
function check(a,b,c){
var shouldRetry = b != 'success' && b != 'parsererror';
if( shouldRetry && --this.retries > 0 )
setTimeout(() => { $.ajax(this) }, this.retryInterval || 100);
}
return settings => $oldAjax(settings).always(check)
@azhararmar
azhararmar / Symfony - Manual User Authentication
Last active Nov 26, 2021
Manually Authenticate User In Symfony
View Symfony - Manual User Authentication
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
// Manually authenticate user in controller
$token = new UsernamePasswordToken($user, null, 'main', $user->getRoles());
$this->get('security.token_storage')->setToken($token);
$this->get('session')->set('_security_main', serialize($token));
@indiesquidge
indiesquidge / objects-over-classes.md
Last active Sep 13, 2021
We are better off avoiding ES6 classes in JavaScript when possible
View objects-over-classes.md

Plain JavaScript objects are better than classes when they can be used, and many popular modern frameworks have adopted their use.

Consider that in React a component can be created as either a class or as an object.

// using a class
class Welcome extends React.Component {
  render() {
    <h1>Hello, {this.props.name}</h1>
@ajskelton
ajskelton / WP Customizer - Number
Last active Sep 22, 2021
Add a Number field to the WordPress Customizer.
View WP Customizer - Number
$wp_customize->add_setting( 'themeslug_number_setting_id', array(
'capability' => 'edit_theme_options',
'sanitize_callback' => 'themeslug_sanitize_number_absint',
'default' => 1,
) );
$wp_customize->add_control( 'themeslug_number_setting_id', array(
'type' => 'number',
'section' => 'custom_section', // Add a default or your own section
'label' => __( 'Custom Number' ),