Skip to content

Instantly share code, notes, and snippets.

View FMCorz's full-sized avatar

Frédéric Massart FMCorz

  • Branch Up Pty Ltd
  • Perth, Australia
View GitHub Profile
@FMCorz
FMCorz / restricted.host
Created September 2, 2022 03:22
Restrict access to local network in Apache
<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 June 15, 2022 10:39
Remove overlays and paywalls from the page, when possible.
(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 November 27, 2020 00:22
Create a Level up! entry for students added to a cohort
<?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 September 9, 2020 08:06
Rendering Moodle shortcode in a theme's layout
{{!
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 February 1, 2019 07:09
Redux: Accessing state from mapDispatchToProps
// 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 November 27, 2018 03:13
Adminer with SQLite no-login

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 June 11, 2022 04:22
Useful functions for Level Up XP integrations
<?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 November 14, 2018 03:13
Basic module to simply throttle a function call
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 September 20, 2023 08:02
ReactStrap Tabs using React hooks
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 October 24, 2022 06:58
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.
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) {