Skip to content

Instantly share code, notes, and snippets.

View karlazz's full-sized avatar

Karla Leibowitz karlazz

  • herself
  • Walnut Creek, CA
View GitHub Profile
@karlazz
karlazz / gist:d757ffd500b7ce4fe8405518639969aa
Created January 9, 2024 00:53
useful drag and drop table rows
<ul class="draggable" >
<li>
<td class="rule-info rule-op">
<span class="gripicon"><i class="fas fa-grip-vertical"></i></span>
<span class="ruleNum"> 2</span>
</td>
<td>
Other
@karlazz
karlazz / unset API endpoints example: user
Created January 20, 2023 00:37
unset API endpoints example: user
// Unset user API endpoints to prevent user enumeration
add_filter('rest_endpoints', function($endpoints) {
unset( $endpoints['/wp/v2/users'] );
unset( $endpoints ['/wp/v2/users/(?P<id>[\d]+)']);
unset( $endpoints ['[/wp/v2/users/me]']);
unset( $endpoints ['[/wp/v2/users/(?P<user_id>(?:[\d]+|me))/application-passwords]']);
unset( $endpoints ['[/wp/v2/users/(?P<user_id>(?:[\d]+|me))/application-passwords/introspect]']);
unset( $endpoints ['[/wp/v2/users/(?P<user_id>(?:[\d]+|me))/application-passwords/(?P<uuid>[\w\-]+)']);
@karlazz
karlazz / Fluid truly responsive text and spacing with calc in CSS
Last active January 20, 2023 00:41
Fluid truly responsive text and spacing with calc in CSS
/* baseline sizes for use on screen width > 1699, want it fixed here */
// or you can use css clamp --
// https://www.smashingmagazine.com/2022/01/modern-fluid-typography-css-clamp/ */
// https://developer.mozilla.org/en-US/docs/Web/CSS/clamp
.sidebar .top {
margin-bottom: 22px;
font-size: 16px;
line-height: 24px;
}
@karlazz
karlazz / makeatablefromanobject
Created April 26, 2022 18:44
Make a table from a javascript object
function arrayToTable(data) {
const keys = [...data.reduce((all, obj)=>{
Object.keys(obj).forEach(key => all.add(key));
return all;
}, new Set())];
const header = keys.map(key => `<th>${key}</th>`).join('')
const tbody = data.map(row => keys.map(key => `<td>${row[key]}</td>`).join('')).map(row => `<tr>${row}</tr>`)
return `<table>
@karlazz
karlazz / gist:0bac0b59e9b5c7b7797b1601a30ba12f
Last active April 29, 2021 22:40
Detect onclick event in iframe
var clickIframe = window.setInterval(checkFocus, 100);
var i = 0;
function checkFocus() {
if(document.activeElement == document.getElementById("ifr")) {
console.log("clicked "+(i++));
window.focus();
}
}
@karlazz
karlazz / gist:0f6ff048eb350857fed6b5e01673fd67
Last active April 22, 2021 23:55
Automated reponsive grid from Heydon Pickering and further grid notes
.container {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr));
grid-gap: 1rem;
}
@karlazz
karlazz / Recurse server program
Last active March 19, 2021 00:20
For a pair programming session, a server to accept and return key value pairs
<?php
set_time_limit(0);
/* works with GET or POST, one key pair only :-(
curl -d '{"path":"/set","query":{"color":"green"}}' -X POST http://localhost:4000
curl -d '{"path":"/get","query":{"key":"color"}}' -X POST http://localhost:4000
localhost:4000/set?color=green
localhost:4000/get?key=color
@karlazz
karlazz / gist:3f527021dcaf2d80bf0e910ea53d79f8
Created February 12, 2021 19:44
Simple fetch and WP REST API example
fetch("https://domain.com/wp-json/wp/v2/published_rest_accessible_post_type/"+ ID)
.then(response => response.json())
.then(data => document.getElementById("<?php echo $a['dest'];?>").innerHTML= data.content.rendered );
}
@karlazz
karlazz / gist:7faf6458841ec45983e7f974afb6901e
Created January 28, 2021 19:51
Add a rest route to WordPress
//Jack Johannson at https://wordpress.stackexchange.com/questions/306609/how-can-i-fetch-css-from-json-wp-rest-api-response
// syntax for use: http://example.com/wp-json/alexi/v1/output_css_uri
// Register a new rest route and create callback to execute
add_action( 'rest_api_init', 'my_rest_routes' );
function my_rest_routes() {
register_rest_route(
'alexi/v1',
@karlazz
karlazz / gist:6ac5b6e7e36803abe55e798d15d63970
Created September 23, 2020 02:01
scraper example uses simple html dom integrates with wordpress
<?php
include ('./simple_html_dom.php');
include ('./wp-load.php');
function custom_wpkses_allow_iframe_here( $tags, $context ) {
if ( 'post' === $context ) {
$tags['iframe'] = array(
'src' => true,
'height' => true,