Skip to content

Instantly share code, notes, and snippets.

@isabellachen
isabellachen / generics-classes.ts
Created February 2, 2022 10:45
TypeScript Series: Generics and Classes
interface HotelRooms {
name: string;
capacity: number;
}
class Hotel<T extends HotelRooms> {
public rooms: T[] = []
addRoom(room:T) {
this.rooms.push(room)
@isabellachen
isabellachen / ErrorWithTypeNever.ts
Last active February 2, 2022 10:44
TypeScript Series: Type Checking Errors: Handle errors with type unknown | Type check with classes
// @errors: 2345
function obtainRandomVehicle(): any {
return {} as any
}
class Car {
drive() {
console.log("vroom")
}
}
class Truck {
@isabellachen
isabellachen / flexible-compound-components.js
Last active July 19, 2021 07:40
React.useContext() in action
// Flexible Compound Components
// http://localhost:3000/isolated/exercise/03.js
import * as React from 'react'
import {Switch} from '../switch'
/**
* Create a Toggle component that accepts child elements and shares its
* state with its child elements. This example shows a good use case for
* React.useContext() to expose your component's state management API
@isabellachen
isabellachen / customise-learndash-template.md
Created March 21, 2021 14:26
Customise/override LearnDash 3.0 templates

Customise/Override LearnDash template

If you want to override how LearnDash outputs dynamic content, you have to add a file of the same name into your theme or child theme. For example, if you want to change how the infobar content is displayed, you need to edit the infobar.php file. All that is needed is to place your php file in the correct folder.

If you’re overriding the file: /wp-content/plugins/sfwd-lms/themes/ld30/templates/modules/infobar.php then the file in the child theme will be: /wp-content/themes/xxx-child/learndash/ld30/modules/infobar.php

@isabellachen
isabellachen / wp_walker_social_icons.php
Last active February 22, 2021 14:26
WP Walker menu for social icons
<?php
/**
* Custom Social Media Nav Walker by Aurooba Ahmed
* This uses Font Awesome and adds in the correct icon by detecting the URL of the menu item.
* You can use this by doing a custom wp_nav_menu query:
* wp_nav_menu(array('items_wrap'=> '%3$s', 'walker' => new WO_Nav_Social_Walker(), 'container'=>false, 'menu_class' => '', 'theme_location'=>'social', 'fallback_cb'=>false ));
*
*/
class WO_Nav_Social_Walker extends Walker_Nav_Menu {
@isabellachen
isabellachen / remote-debugging-jetpack-vscode.md
Created February 5, 2021 09:07
Remote Debugging of WordPress JetPack with VS Code

You'll need:

PHP Debug plugin installed in VSCode If you use Google Chrome, install the Xdebug Helper extension. If you use Firefox, install Xdebug Helper add-on. Set up the Debugging Task In the debug panel in VSCode, select Add Configuration. Since you have PHP Debug installed, you'll have the option to select "PHP" from the list. This will create a .vscode folder in the project root with a launch.json file in it.

You will need to supply a pathMappings value to the launch.json configuration. This value connects the debugger to the volume in Docker with the Jetpack code. Your launch.json file should have this configuration when you're done.

@isabellachen
isabellachen / header.php
Created August 16, 2020 11:07
Adding Depth to WordPress Sub Menu
<?php
/**
* In header.php
*/
<nav id="site-navigation" class="main-navigation">
<button class="menu-toggle" aria-controls="primary-menu" aria-expanded="false"><?php esc_html_e('Primary Menu', 'custom_walker'); ?></button>
<?php
wp_nav_menu(
array(
@isabellachen
isabellachen / content.html
Created August 6, 2020 16:39
Read More Slide Out Effect
<div class="archive-lead-content">
<p>Kenya has incredible wildlife and unparalleled natural splendour. Out in the vast expanse of its savannahs are some world-famous locations. Among these are Amboseli national park, Hell’s Gate and Lake Naivasha. The last two locations are both in the Great Rift Valley, the cradle of mankind.</p>
<p>This country is responsible for a lot of the ideas in popular culture about Africa. Here, we photographed the classic image of the African savannah – elephant herds roaming through vast grassland. Kenya is truly a spectacular place, an unparalleled destination to experience nature in the raw.</p>
</div>
<button class="my-button">Read More</button>
@isabellachen
isabellachen / jetpack-masonryjs-rebuild.js
Created August 6, 2020 11:14
Get masonry.js to rebuild with jetpack turned on
(function($) {
$(document.body).on('jetpack-lazy-loaded-image', function() {
var $container = $('.blog-masonry');
$container.imagesLoaded(function() {
$container.masonry('reloadItems').masonry('layout');
});
});
})(jQuery);
@isabellachen
isabellachen / query-images-gatsby-source-filesystem.md
Created April 29, 2020 19:29
Query for image files in directory with source gatsby-file-system
query {
  allFile(filter:{relativeDirectory: {eq: "demo-map"}}) {
    edges {
      node {
        absolutePath
        name
        relativePath
        relativeDirectory
 extension