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 / sandbox.py
Last active October 2, 2023 12:25
Django standalone script #python #django
# Standalone Django script
#
# Ideal for quickly testing some code.
#
# 1. Place at the root of your project
# 2. Edit the variable PROJECT_NAME
# 3. Run it: python sandbox.py
import os
@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 / test.sh
Created May 18, 2017 02:33
Webservice test for duplicating Moodle courses
#!/bin/bash
API="http://10.1.1.13/sm/webservice/rest/server.php" # WS entry point.
COURSEID=25 # Course to duplicated.
CATEGORYID=1 # Category to duplicate to.
TOKEN="490b48f8cd71e88a37fa70cc6eff3fb2" # WS Token.
# SCRIPT STARTS HERE.
SUFFIX=`date +"%s"`
@FMCorz
FMCorz / ssh_port_forward.md
Last active January 9, 2023 21:41
Port forwarding using SSH

Local port forwarding

ssh -nNT -L LOCALPORT:DESTINATION:DESTPORT SSHACCOUNT

To forward localhost:5000 to destination.net:80:

@FMCorz
FMCorz / gitconfig
Last active November 23, 2022 12:26
Global git config
# Edit using:
# git config -e --global
[user]
name = Me
email = email@example.com
[alias]
ap = add -p
au = add -u
bl = branch -l
@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 / 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) {
@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 / store.js
Last active August 4, 2022 10:01
Fallback on cache when Axios reports a network error
import Axios from 'axios';
import { setupCache } from 'axios-cache-adapter';
import exclude from 'axios-cache-adapter/src/exclude';
// Define the cache adapter.
const cacheAdapter = setupCache({
clearOnStale: false,
});
const getKey = cacheAdapter.config.key;
@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;
}