Skip to content

Instantly share code, notes, and snippets.

Avatar

Frédéric Massart FMCorz

  • Branch Up Pty Ltd
  • Perth, Australia
View GitHub Profile
@FMCorz
FMCorz / restricted.host
Created Sep 2, 2022
Restrict access to local network in Apache
View restricted.host
<VirtualHost *:80>
DocumentRoot /var/www/dirforbidden
<Directory /var/www/dirforbidden>
# Local machine only
Require local
# Broader local network
Require ip 192.168
Require ip 10
</Directory>
@FMCorz
FMCorz / remove-overlay.js
Last active Jun 15, 2022
Remove overlays and paywalls from the page, when possible.
View remove-overlay.js
(function() {
let overlay;
let node = document.elementFromPoint(window.innerWidth / 2, window.innerHeight / 2);
while (true) {
if (!node.parentNode || node.tagName === 'BODY') break;
const styles = getComputedStyle(node);
if (styles['overflow'] === 'hidden') {
overlay = node;
}
@FMCorz
FMCorz / example.php
Created Nov 27, 2020
Create a Level up! entry for students added to a cohort
View example.php
<?php
/**
* Snippet showing how to create a record for a student as they are added to
* a cohort. Students will earn 0 points so to only creates their record.
*
* These files below must be implemented as part of an existing plugin, or
* a new one. Only the two files relevant to Level up! are displayed below.
*/
@FMCorz
FMCorz / columns2.mustache
Created Sep 9, 2020
Rendering Moodle shortcode in a theme's layout
View columns2.mustache
{{!
This represents a theme's layout template.
To render the shortcode, simply call the renderer method defined in the renderer.
}}
<div>
{{{ output.block_xp_progress_bar }}}
</div>
@FMCorz
FMCorz / example.jsx
Created Feb 1, 2019
Redux: Accessing state from mapDispatchToProps
View example.jsx
// Re. https://github.com/reduxjs/react-redux/issues/535
//
// Here is a solution to access props derived from the state in mapDispatchToProps.
//
// I personally prefer this over those suggested in the issue above.
const unlockItem = () => null; // Replace with some redux action.
const Unlocker = props => {
return <button onClick={() => props.unlockItem(props.itemId)}>Unlock</button>;
@FMCorz
FMCorz / README.md
Created Nov 27, 2018
Adminer with SQLite no-login
View README.md

Adminer setup

Enables plugins, and SQLite no-login.

Instructions

  1. Copy index.php to a new directory
  2. Download Adminer to adminer.php
@FMCorz
FMCorz / functions.php
Last active Jun 11, 2022
Useful functions for Level Up XP integrations
View functions.php
<?php
/**
* Manually award points.
*
* @param int $userid The ID of the target user.
* @param int $points The numbers of points to award.
* @param int $courseid The course ID to use, this has no effect in 'For the whole site' mode.
*/
function block_xp_award_points($userid, $points, $courseid = 0) {
if (!class_exists('block_xp\di')) {
@FMCorz
FMCorz / throttler.js
Created Nov 14, 2018
Basic module to simply throttle a function call
View throttler.js
define([], function() {
/**
* Throttler.
*
* @param {Number} delay The delay.
*/
function Throttler(delay) {
this.delay = delay || 300;
this.timeout = null;
this.time = new Date();
@FMCorz
FMCorz / example.js
Last active Jan 3, 2023
ReactStrap Tabs using React hooks
View example.js
import React, { useState } from 'react';
import { Nav, NavItem, NavLink, TabContent, TabPane } from 'reactstrap';
export default function MyTabs(props) {
const [activeTab, setActiveTab] = useState('1');
return (
<div>
<Nav tabs>
<NavItem>
<NavLink className={activeTab == '1' ? 'active' : ''} onClick={() => setActiveTab('1')}>
@FMCorz
FMCorz / requests.js
Last active Oct 24, 2022
Axios with a custom cache adapter. It handles setting cache to groups to permit invalidating a bunch at once, and it returns cache data when there is an error with the request.
View requests.js
import Axios from 'axios';
import { setupCache } from 'axios-cache-adapter';
import localforage from 'localforage';
import find from 'lodash/find';
import isEmpty from 'lodash/isEmpty';
const CACHE_MAX_AGE = 2 * 60 * 60 * 1000;
// Extracting 'axios-cache-adapter/src/exclude' as importing it leads to webpack not compiling it.
function exclude(config = {}, req) {