Skip to content

Instantly share code, notes, and snippets.

View mattlockyer's full-sized avatar
💭
🥳

Matt Lockyer mattlockyer

💭
🥳
View GitHub Profile
@mattlockyer
mattlockyer / test.js
Created April 15, 2017 16:10
Testing Immutable.js as data store that will always point to the most updated reference of the map
//with store
const STORE = {
head: new Map(),
undo: () => {
const action = STORE.queue.pop();
STORE.head = STORE.queue[STORE.queue.length - 1];
return action;
},
queue: []
};
@mattlockyer
mattlockyer / immutable-store.js
Last active April 15, 2017 18:13
Immutability.js as data store with get, set, merge and added undo, redo
const STORE = {
head: new Map(),
undoStack: [],
redoStack: [],
//implement undo
undo: () => {
if (STORE.undoStack.length === 1) return STORE.head;
const action = STORE.undoStack.pop();
STORE.head = STORE.undoStack[STORE.undoStack.length - 1];
STORE.redoStack.push(action);
@mattlockyer
mattlockyer / s3.js
Created April 25, 2017 17:30
s3 put and get functions
/**************************************
* File Put
**************************************/
const uuidV1 = require('uuid/v1');
const multer = require('multer');
const upload = multer({ storage: multer.memoryStorage(), limits: { fileSize: 10*1024*1024 } }); //10mb limit
const fileUpload = (req, res) => {
//get args
const { id } = req.body;
const file = req.file;
@mattlockyer
mattlockyer / client.js
Last active February 22, 2023 18:30
s3 upload as stream using req stream (extra info in request header)
const file = this.input.files[0];
//console.log(file);
var xhr = new XMLHttpRequest();
xhr.addEventListener('load', (e) => {
console.log(e.target.response);
});
xhr.open('POST', host + 'fileuploadstream', true);
xhr.setRequestHeader('body', JSON.stringify({ id: 'somebucketfolderid', fn: file.name }));
xhr.send(file);
@mattlockyer
mattlockyer / table.js
Created May 9, 2017 21:12
React Component for Draggable Re-ordering of Columns in react-table
import React, { Component } from 'react';
import ReactTable, { ReactTableDefaults } from 'react-table';
//https://github.com/tannerlinsley/react-table
//https://react-table.js.org/
import 'react-table/react-table.css'
Object.assign(ReactTableDefaults, {
defaultPageSize: 10,
minRows: 3,
});
@mattlockyer
mattlockyer / package.json
Created July 6, 2017 18:25
package.json Boilerplate
{
"name": "",
"description": "",
"version": "0.0.0",
"private": true,
"author": "Matt Lockyer",
"homepage": "",
"contributors": [ "Matt Lockyer (mattdlockyer@gmail.com)" ],
@mattlockyer
mattlockyer / gist:7de893299e5390c1b3179964095a1852
Created July 27, 2017 21:53
Test Address for Rinkerby Faucet
0xf1a11C42075F2d89aC2792B4D43E2d48457F311F
@mattlockyer
mattlockyer / web3-utils.js
Created September 28, 2017 19:42
Portable Web3 Utils. Depends on Truffle Contract.
const web3utils = (function() {
/**************************************
* Web3
**************************************/
const getWeb3 = (fallbackURL = 'http://localhost:8545', web3 = window.web3) => {
if (web3 !== undefined) {
web3 = new Web3(web3.currentProvider);
} else {
@mattlockyer
mattlockyer / dd.md
Last active February 22, 2018 20:47
Decentralized Dictionary

Blockchain

A transactional database where the changes in state are made by updating the difference from A to B. The transactions are bundled into blocks and cryptographically hashed to produce a unique signature. Blocks are arranged forward in time with the hash of the previous block included in the next block, this prevents tampering. Merkle tree data structures are used to efficiently store transactions and compute the current state from the root of the blockchain. Typically what is computed is the balance of an account.

Blockchain Network

A network designed to update a blockchain database. Distributed and decentralized are not prerequisites. Allows for the creation and tokenization of digital scarcity through consensus, game theory or mechanism design. Allows for the individual ownership, exchange and administration of cryptographically secured assets.

Private Permissioned Blockchain Network

Network participants chosen by centralized entity, consortium or federation.

Public Permissioned Bloc

@mattlockyer
mattlockyer / HelloMarket.sol
Created June 6, 2018 17:53
HelloMarket smart contract for Solidity workshops
//jshint ignore: start
pragma solidity ^0.4.21;
contract Owner {
address public owner;
modifier onlyOwner() {
require(msg.sender == owner);