Skip to content

Instantly share code, notes, and snippets.

View mattlockyer's full-sized avatar
💭
🥳

Matt Lockyer mattlockyer

💭
🥳
View GitHub Profile
@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 / 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 / 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,
3Box is a social profiles network for web3. This post links my 3Box profile to my Github account!
✅ did:muport:Qme8gP1U9LfNe5J75N19QXqghFg5DUQ5gtwJBFjjdaBmMz ✅
Create your profile today to start building social connection and trust online. https://3box.io/
@mattlockyer
mattlockyer / custom-grunt.js
Created January 10, 2019 15:46
Custom Gruntfile for materializecss
const files = [
'js/cash.js',
'js/component.js',
'js/global.js',
'js/anime.min.js',
// 'js/collapsible.js',
// 'js/dropdown.js',
// 'js/modal.js',
@mattlockyer
mattlockyer / redux-connect-multiple.js
Created January 5, 2019 18:45
Connect multiple Redux states and dispatches ... elegantly
export default connect(
(state) => ({
state1: state1(state),
state2: state2(state),
}),
(dispatch) => ({
dispatch1: dispatch1(dispatch),
dispatch2: dispatch2(dispatch),
})
)(App);
@mattlockyer
mattlockyer / generic-reducer.js
Created January 5, 2019 17:52
Generic Reducer for Redux - update state with any action key/vaue passed (excluding type)
//generic event type for updating state
export const UPDATE = 'STATE_UPDATE'
//generic reducer for updating state
export const reducer = (state, action) => {
//console.log(action)
const { type } = action
switch (type) {
case UPDATE:
const a = { ...action }
delete a.type
@mattlockyer
mattlockyer / wait.js
Last active January 11, 2019 16:41
Wait for function to return true uses promise for async / await
/**************************************
* Wait for function to return true, default 50ms for 100 attempts (5s)
**************************************/
export const wait = (func, del = 50, lim = 100) => new Promise((resolve, reject) => {
let attempt = 0
const test = () => {
if (func()) resolve()
else if (attempt < lim) setTimeout(test, del)
else reject("ran out of attempts")
console.log('wait attempt', attempt)
@mattlockyer
mattlockyer / Lecture-week6.md
Last active June 23, 2018 22:26
Lighthouse Labs Week 6 Lecture Notes - Web3.js, TruffleContract, Frontends, Accounts and Transactions

Web3.js, TruffleContract and Frontend Development of Decentralized Applications

To date, we've been writing and testing contracts using JavaScript tests.

Those tests are a lot like our frontend code that we need to create in order to allow users of our decentralized applications (dapps) to talk to the Ethereum Blockchain.

However, there's a lot of initial setup and network configuration code that was automated (black boxed) by our test runner.

User experience, waiting for transactions and returning the updated state to the application and user interface are also a primary concern for developing these dapps.

@mattlockyer
mattlockyer / hellomarket-testrunner.js
Created June 6, 2018 20:10
Test Runner for HelloMarket.sol / HelloMarketToken.sol (empty)
//jshint ignore: start
// contracts
const contracts = [
{ name: 'HelloMarket' }
];
contracts.forEach(c => c.artifact = artifacts.require('./' + c.name + '.sol'))
/**************************************
* Tests