Skip to content

Instantly share code, notes, and snippets.

View jhackett1's full-sized avatar
🦁

Jaye Hackett jhackett1

🦁
View GitHub Profile
@jhackett1
jhackett1 / async.js
Last active January 5, 2018 14:44
A simple blocking function, used for async exercises
// A function which returns an object after one second
var getData = function(cb){
setTimeout(function(){
var data = {
data: "Some data",
moreData: "And more data",
lastData: true
}
cb(data)
}, 1000)
@jhackett1
jhackett1 / forTest.js
Last active December 20, 2017 13:13
A function just crying out for a unit test
// This function should return a user object. Does it?
module.exports.getUser = function(){
var user = {
firstName: "Dave",
lastName: "Bowman",
occupation: "Astronaut",
admin: false
}
return;
@jhackett1
jhackett1 / bookmarklet.js
Last active April 7, 2019 09:45
Hide popups and make the page scrollable again
var elements = document.querySelectorAll('body *')
for (i = 0; i < elements.length; i++) {
if (getComputedStyle(elements[i]).position === 'fixed') elements[i].parentNode.removeChild(elements[i])
}
document.querySelector('body').setAttribute('style', 'overflow-y:scroll !important');
document.querySelector('html').setAttribute('style', 'overflow-y:scroll !important');
@jhackett1
jhackett1 / query.sql
Created May 24, 2019 20:42
bucks-community-assets-export
SELECT ASSETS.[Asset ID], ASSETS.[GET category], ASSETS.KeyWords, ASSETS.ACMD, ASSETS.CR, ASSETS.DO, ASSETS.EL, ASSETS.SG, ASSETS.SCG, ASSETS.SA, ASSETS.YPA, ASSETS.[Local Area], ASSETS.Area, ASSETS.Organisation, ASSETS.Meeting, ASSETS.MO, ASSETS.TU, ASSETS.WE, ASSETS.TH, ASSETS.FR, ASSETS.ST, ASSETS.SU, ASSETS.DaytimeMeetings, ASSETS.[Time-Date], ASSETS.Venue, ASSETS.Postcode, ASSETS.Cost, ASSETS.ContactName, ASSETS.ContactNo, ASSETS.Website, ASSETS.ContactEmail, ASSETS.Description, ASSETS.[Last-Updated], ASSETS.ReviewDate, ASSETS.[Status-of-Review], ASSETS.[Review Notes], ASSETS.Assigned, ASSETS.ReviewNumber, [Page 2].[Age YP], [Page 2].[Age YA], [Page 2].[Age OA], [Page 2].[Local Area], [Page 2].[LAF GAyl], [Page 2].[LAF Wadd], [Page 2].[LAF C&CV], [Page 2].[LAF Beec], [Page 2].[LAF W&D], [Page 2].[LAF NWC], [Page 2].[LAF GBWI], [Page 2].[LAF H&LC], [Page 2].[LAF SWC&M], [Page 2].[LAF Amer], [Page 2].[LAF Buck], [Page 2].[LAF HW], [Page 2].[LAF W&I], [Page 2].[LAF CWV], [Page 2].[LAF Chal], [Page 2].[LAF W
@jhackett1
jhackett1 / functions.php
Last active January 28, 2021 19:04
wp-geo-search example template usage
<?php
// Make WP recognise the extra query parameter
function example_query_vars( $qvars ) {
$qvars[] = 'location';
return $qvars;
}
add_filter( 'query_vars', 'example_query_vars' );
@jhackett1
jhackett1 / learn-sql-demo-db.sql
Last active December 10, 2020 15:46
demo postgresql database for learning sql
create table employees (
id SERIAL PRIMARY KEY,
first_name VARCHAR(50),
last_name VARCHAR(50),
email VARCHAR(50),
street_address VARCHAR(50),
postcode VARCHAR(50),
department VARCHAR(50),
currently_employed VARCHAR(50),
employed_from DATE,
@jhackett1
jhackett1 / authContext.js
Created December 14, 2020 11:35
A React context showing how you might manage authentication
import React, { createContext, useContext } from "react"
import useSWR from "swr"
const AuthContext = createContext(false)
export const AuthProvider = (props) => {
const { data, error, mutate } = useSWR(`/api/v1/auth/me`)
const googleLogIn = async googleData => {
@jhackett1
jhackett1 / google-oauth.js
Created December 14, 2020 11:40
Using Google oAuth to authenticate a React app and Express API
////////////
// REACT APP
////////////
// Your login screen
<GoogleLogin
clientId={process.env.REACT_APP_GOOGLE_CLIENT_ID}
buttonText="Sign in with Google"
className="ct-button ct-button--secondary"
@jhackett1
jhackett1 / vouchsafe-node-demo.js
Last active August 28, 2024 12:43
How to call the live Vouchsafe API using node.js
const ENDPOINT_HOST = "https://app.vouchsafe.id/api/v1"
// Step 1. Get client ID and secret from the dashboard
const CLIENT_ID = "YOUR_CLIENT_ID_HERE"
const CLIENT_SECRET = "YOUR_CLIENT_SECRET_HERE"
// Step 2. Trade client id and secret for a time-limited access token
const getAccessToken = async () => {
const res = await fetch(`${ENDPOINT_HOST}/authenticate`, {
method: "POST",
@jhackett1
jhackett1 / example-payload.json
Last active October 22, 2024 20:02
Example JSON verified identity payload returned by some Vouchsafe APIs
{
"sub": "5cb14773-584b-450a-9204-b0be325d72ce",
"iat": 1385066178,
"verified_claims": {
"verification": {
"outcome": "VERIFIED_SUCCESSFULLY",
"trust_framework": "uk_tfida",
"profile": "M0X",
"assurance_policy": "GPG_45"
"confidence_level": "medium",