Skip to content

Instantly share code, notes, and snippets.

@ripter
ripter / useValidationHook.ts
Created March 24, 2020 18:45
simple validation hook
export function useValidationHook(defaultItemState: Partial<KeywordAdItem>) {
// Allow partial a partial state to be used as the default/inital render.
let defaultState = {...DEFAULT_STATE};
if (defaultItemState) {
Object.assign(defaultState.item, defaultItemState);
}
return useReducer((state: State, action: Action) => {
const { field, value } = action;
// Create a shallow copy of the old data and add/repace the new value.
@ripter
ripter / updateList.ts
Created March 23, 2020 19:26
Reducer Array CRUD
/**
* Returns a new list, based on the previous list.
* Action describes how to create the new list.
* Shallow Copy
*/
export function updateList(prevList: objectList, action: KeywordDispatchAction): objectList {
const { type, listIndex, data } = action;
// console.group('Action', type);
switch (type) {
// https://threejs.org/examples/webgl_lights_hemisphere.html
AFRAME.registerShader('gradient', {
schema: {
timeMsec: {type: 'time', is: 'uniform'},
topColor: {type: 'color', is: 'uniform', default: '#0077ff'},
bottomColor: {type: 'color', is: 'uniform', default: '#ffffff'},
offset: {is: 'uniform', default: 33},
exponent: {is: 'uniform', default: 0.6},
},
raw: false,
[
["KIAA0141",-7.583179872,-0.03334987 ],
["EIF2AK1",-5.286158957,-0.038206876 ],
["URI1",-5.023483452,0.021195171 ],
["KIAA0947",-3.960840625,-0.389346067 ],
["TAZ",1.393157325,4.844039489 ],
["BRPF1",-3.668330762,-0.487446006 ],
["NELFE",-3.745420274,-0.603712746 ],
["GRSF1",-0.374317963,2.701531952 ],
["EIF4E2",-2.884958128,0.076901041 ],
[
["A1BG__P1_h3_Top5",-0.02149393,0.322957496 ],
["A1BG__P2_h3_Top5",-0.948661145,0.087967564 ],
["A1CF__P1P2_h3_Top5",-0.787883758,-0.14937761 ],
["AAAS__P1P2_h4_Top5",1.458158366,0.303433169 ],
["AADAC__P1P2_h3_Top5",-0.153730471,0.021665742 ],
["AAMP__P1P2_h3_Top5",-2.900039485,-2.12058401 ],
["AASDH__P1P2_h4_Top5",1.241920441,0.019673949 ],
["AASDHPPT__P1P2_h3_Top5",-0.753686771,-0.3382019 ],
["ABCA12__P1P2_h3_Top5",-2.208185006,-0.121822514 ],
@ripter
ripter / SandwichFactory.sol
Created August 10, 2018 20:43
Storage vs Memory in Solidity
// From: https://cryptozombies.io/en/lesson/2/chapter/7
contract SandwichFactory {
struct Sandwich {
string name;
string status;
}
Sandwich[] sandwiches;
function eatSandwich(uint _index) public {
pragma solidity ^0.4.0;
contract BOSGame {
struct Vote {
uint choice;
uint amount;
address owner;
}
mapping(address => Vote) playerVote;
@ripter
ripter / BankContract.sol
Created July 18, 2018 19:41
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.4.24+commit.e67f0147.js&optimize=false&gist=
pragma solidity ^0.4.24;
contract BankContract {
uint balane;
function deposit() public payable {
balane += msg.value;
}
function getBalance() public view returns (uint) {
@ripter
ripter / power_user.html
Last active January 22, 2018 19:26
Tout Embed Codes v3
<!-- Embed Code, v1 Power User Style
No wrapper means no extra network call.
Everything is loaded in parallel.
-->
<link rel="stylesheet" href="https://tesla.tout.com/sdk/v2/sdk.css" />
<script src="https://tesla.tout.com/sdk/v2/sdk.js" async defer></script>
<script src="https://tesla.tout.com/sdk/v2/af660e.js" async defer></script>
@ripter
ripter / getQueryParams.js
Created January 18, 2018 18:44
getQueryParams as an Object
function getQueryParams() {
let match, result = {}, reg = /[&?]([^=]+)=([^&]+)/g;
// Match each reg in the queryString (aka search) and add it to the result object.
while (match = reg.exec(location.search)) { result[match[1]] = match[2]; }
return result;
}