Skip to content

Instantly share code, notes, and snippets.

View mattlockyer's full-sized avatar
💭
🥳

Matt Lockyer mattlockyer

💭
🥳
View GitHub Profile
@mattlockyer
mattlockyer / settings.json
Created March 21, 2019 04:18
VS Code Settings
{
"terminal.integrated.shell.windows": "C:\\WINDOWS\\sysnative\\bash.exe",
"workbench.colorTheme": "Ayu Light Bordered",
"editor.minimap.enabled": false,
"workbench.activityBar.visible": false,
"git.ignoreMissingGitWarning": true,
"workbench.editor.enablePreview": false,
"editor.fontSize": 16,
"editor.tabSize": 2,
"editor.hover.enabled": false,
@mattlockyer
mattlockyer / keybindings.json
Created March 21, 2019 04:20
VS Code Key Bindings
// Place your key bindings in this file to override the defaults
[
{ "key": "ctrl+shift+d", "command": "editor.action.copyLinesDownAction", "when": "editorTextFocus" },
{ "key": "alt+shift+x", "command": "type", "args": { "text": "console.log(" }, },
{ "key": "alt+shift+c", "command": "type", "args": { "text": "/********************************\n\n********************************/" }, },
]
@mattlockyer
mattlockyer / user.js
Created April 11, 2019 17:05
Example of Reduced Redux Code for a User State Boilerplate
import { reducer, UPDATE } from '../util/redux-util'
//state
export const userState = ({ userReducer: { ...keys } }) => (keys)
//dispatch
export const userDispatch = (dispatch) => ({
onMount: () => dispatch(mount()),
});
//functions
export const mount = () => async (dispatch, getState) => {
console.log('REDUX: user mount')
@mattlockyer
mattlockyer / ecdh-example.js
Created April 20, 2019 14:47
WebCrypto ECDH Encryption / Decryption Basic Example (without validation, authentication)
//functions
const qs = (sel) => document.querySelector(sel)
const dhParams = (public) => ({ name: "ECDH", namedCurve: "P-256", public })
const aesParams = (length, counter) => ({ name: "AES-CTR", length, counter })
const keyInt = async(key) => new Uint8Array(await crypto.subtle.exportKey('raw', key));
const derive = async() => await window.crypto.subtle.generateKey(dhParams(), true, ["deriveKey", "deriveBits"])
const deriveAES = async(publicKey, privateKey) => await window.crypto.subtle.deriveKey(
dhParams(publicKey), privateKey, aesParams(256), true, ["encrypt", "decrypt"]
)
const encrypt = async (key, iv, data) => await window.crypto.subtle.encrypt(aesParams(128, iv), key, data)
@mattlockyer
mattlockyer / post.js
Last active April 24, 2019 17:55
JSON POST from console
fetch('http://localhost:8080/test', {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify({name:'matt', number:34}),
// optional
// mode: "cors", // no-cors, cors, *same-origin
// cache: "no-cache", // *default, no-cache, reload, force-cache, only-if-cached
@mattlockyer
mattlockyer / unfollow.js
Last active June 1, 2019 16:45
Unfollow everyone on Twitter
/*
Go to mobile.twitter.com
Click following and you should see the followers / following tabs at the top, make sure you're on "following".
Open the developer console and paste this bad boy in.
You can watch it working away... And stop it anytime by closing the tab.
It will start with your most recently followed first and work backwards chronological as it scrolls the accounts you follow.
*/
@mattlockyer
mattlockyer / composition-example-1.js
Created June 11, 2019 13:38
Object Composition Example
const canBark = (state) => ({
bark:(howManyTimes) => {
state.barks += howManyTimes
}
})
const canEat = (state) => ({
eat:(howMuch) => {
state.food -= howMuch
}
const canBark = (state, howManyTimes) => {
state.barks += howManyTimes
}
const canEat = (state, howMuch) => {
state.food -= howMuch
}
const dog = (name) => {
let state = {
const canBark = (state) => ({
bark:(howManyTimes) => {
state.barks += howManyTimes
}
})
const canEat = (state, howMuch) => {
state.food -= howMuch
}
//helper function
const assignFuncs = (state, funcs) => funcs
.map((func) => ({[func.name]: (...args) => func(state, ...args)}))
.reduce((acc, func) => ({...acc, ...func}))
//example
const bark = (state, howManyTimes) => {
state.barks += howManyTimes