Skip to content

Instantly share code, notes, and snippets.

@jackrobertscott
jackrobertscott / ghub-mac-script.lua
Created July 19, 2023 06:00
Mac gesture control using the Logitech G Hub software.
--[[
Usage: Logitech G HUB > Menu > Games & Applications > Profiles > Default > Scripting
Bottom button click: mission control.
Bottom button press & swipe left / right: go desktop left / right.
Bottom button press & swipe up / down: more mac menus...
Top button press: allows scrolling of left and right directions.
--]]
btnA = 4;
btnB = 5;
@jackrobertscott
jackrobertscott / mongodb-json-export.sh
Last active February 14, 2021 04:25
Export & import all MongoDB collections using JSON files.
#!/bin/bash
# Usage: ./mongodb-json-export.sh dbName
DB=$1
COLLECTIONS=$(mongo localhost:27017/$DB --quiet --eval "db.getCollectionNames()" | tr -d '\[\]\"[:space:]' | tr ',' ' ')
mkdir json
for collection in $COLLECTIONS; do
@jackrobertscott
jackrobertscott / react-context-local-storage.ts
Created January 7, 2020 13:14
The perfect demo of react context and local storage in one file.
import {
createElement as element,
createContext,
useContext,
FC,
ReactNode,
useState,
useMemo,
useEffect,
} from 'react'
@jackrobertscott
jackrobertscott / MutationObserverAttributes.ts
Created December 17, 2019 07:30
Simple mutation observer on attributes.
/**
* Mutation observer is not a big library. Rather it's a simple way to observe:
* 1. New attributes on nodes.
* 2. Added / removed node to document.
* 3. Changes to "contenteditable" text elements.
*/
const observer = new MutationObserver((mutationsList, observer) => {
for (let mutation of mutationsList) {
if (mutation.type === 'attributes') {
import axios from 'axios';
async function getGoogleUserInfo(access_token) {
const { data } = await axios({
url: 'https://www.googleapis.com/oauth2/v2/userinfo',
method: 'get',
headers: {
Authorization: `Bearer ${access_token}`,
},
});
import axios from 'axios';
async function getAccessTokenFromCode(code) {
const { data } = await axios({
url: `https://oauth2.googleapis.com/token`,
method: 'post',
data: {
client_id: process.env.APP_ID_GOES_HERE,
client_secret: process.env.APP_SECRET_GOES_HERE,
redirect_uri: 'https://www.example.com/authenticate/google',
import * as queryString from 'query-string';
const urlParams = queryString.parse(window.location.search);
if (urlParams.error) {
console.log(`An error occurred: ${urlParams.error}`);
} else {
console.log(`The code is: ${urlParams.code}`);
}
return (
<a href={googleLoginUrl}>
Login with Google
</a>
);
import * as queryString from 'query-string';
const stringifiedParams = queryString.stringify({
client_id: process.env.CLIENT_ID_GOES_HERE,
redirect_uri: 'https://www.example.com/authenticate/google',
scope: [
'https://www.googleapis.com/auth/userinfo.email',
'https://www.googleapis.com/auth/userinfo.profile',
].join(' '), // space seperated string
response_type: 'code',
import axios from 'axios';
async function getGitHubUserData(access_token) {
const { data } = await axios({
url: 'https://api.github.com/user',
method: 'get',
headers: {
Authorization: `token ${access_token}`,
},
});