Skip to content

Instantly share code, notes, and snippets.

@dacre-denny
dacre-denny / fbDaemon-async-await.js
Created October 24, 2018 22:24
Nested async/await in Firebase snapshot iteration
fbDaemon = async ({ folderNames, folderPaths }) => {
const users = [];
const snapshot = await ref.once("value");
snapshot.forEach(user => {
users.push(user);
});
const settings = [];
for(const user of users) {
@dacre-denny
dacre-denny / index.js
Created December 27, 2018 20:02
Example of <SectionList /> usage for React-Native
import * as React from 'react';
import { Text, View, StyleSheet, FlatList, ActivityIndicator,SectionList } from 'react-native';
import { Constants } from 'expo';
export default class Test extends React.Component {
constructor(props){
super(props);
this.state ={ isLoading: true, dataSource : []}
}
@dacre-denny
dacre-denny / find-object-recursive.js
Created March 19, 2019 10:18
Find nested object recursively
const myObject = [{
"myItems": [{
"id": 1,
"group": {
"groupId": 33
},
},
{
"id": 2,
"group": {
@dacre-denny
dacre-denny / genericPropSetter.ts
Created April 7, 2019 05:17
TypeScript: Generic function that enforces typed value that corresponds to typed key
/* Enforces value type to correspond to that of key, in supplied map object */
function foo<T, K extends keyof T>(map:T, key:K, value: T[K]) {
map[key] = value;
}
interface Apple {
color:string;
weight:number;
}
@dacre-denny
dacre-denny / ToggleDivImage.jsx
Created July 23, 2019 10:56
Toggle image with react and hooks
/* Functional component based on hooks that toggles image when button clicked */
const ToggleDivImage = () => {
/* Setup component state that tracks visibility of the image. Initially, we'll set
the image to visible (toggled true) */
const [toggled, setToggled] = React.useState(true);
/* Define a function that toggles the visibility of the image */
const toggleImage = () => setToggled(!toggled);
const content = editorContent.content
function parseContent (arr) {
arr.forEach((item, index, array)=>{
// Check if item contains another array of items, and then iterate
over that one too.
if(item.content){
parseContent(item.content)
<!DOCTYPE html>
<html>
<head>
<title>SmartContract client: DacreSays</title>
<meta charset="utf-8" />
<script src="https://cdn.jsdelivr.net/npm/web3@latest/dist/web3.min.js"></script>
<style>
label {
font-weight: bold;
interface Item {
id : string;
application : string;
type : string;
title : string;
}
type ResultType = { [key: string] : Array<Item> };
var input : Array<Item> = [{