Skip to content

Instantly share code, notes, and snippets.

View DanC5's full-sized avatar

Dan Carbonell DanC5

View GitHub Profile
@DanC5
DanC5 / gist:7fa25ca1ae62bd9b60807215f24b92bf
Created November 1, 2019 20:05
data-consumer-stream-context-blog
import React from "react";
import { View, Text } from "react-native";
import { BranchConsumer } from "./BranchContext";
let DataConsumer = ({ deeplinkContent }) => {
/*
at this point, all key/value pairs embedded in the deeplink
may be pulled off the `deeplinkContent` object for in-app use
*/
@DanC5
DanC5 / gist:ab8171e198e1a02172d8d99fc659f381
Created November 1, 2019 19:28
app-stream-context-blog
import React, { useEffect } from "react";
import { View, Text } from "react-native";
import branch from "react-native-branch";
import BranchProvider, { BranchConsumer } from "./BranchContext";
let App = ({ setContextData }) => {
// run code in useEffect callback on App load
useEffect(() => {
// branch's subscribe method listens for deeplink activity
@DanC5
DanC5 / gist:ba1e3d24ca7d8349701dacb2d529df81
Created November 1, 2019 19:14
branch-context-stream-context-blog
import React, { createContext, useState } from "react";
// create a React context for managing global state
const BranchContext = createContext();
// access context value through a consumer component
export const BranchConsumer = BranchContext.Consumer;
// save data and share with children through provider component
const BranchProvider = ({ children }) => {
@DanC5
DanC5 / gist:1f6f76e41dd87a0729406bb95f4d046c
Last active April 24, 2019 17:10
PostgreSQL DB Benchmarking
No Optimiztion:
- time to create CSV file with ten million entries: 15 seconds
- time to seed pricing table with CSV file: 78 seconds
- time to run a 'SELECT * FROM pricing;' query: 110 seconds
Single 'SELECT *' query:
- Pre-indexed query by ‘day’:
Pre-cached speed: 5901 ms
Post-cashed speed: 965 ms
@DanC5
DanC5 / gist:c8811024389f7eccc4599227f208b037
Last active April 20, 2019 18:50
SDC Seeding Script - Dan
const fs = require('fs');
const createRandomPrice = () => Math.floor(Math.random() * 100) + 100;
const columnNames = ['day', 'roomAvail', 'Priceline', 'Booking', 'Hotels',
'OfficialHotelSite', 'Expedia', 'TripAdvisor', 'Orbitz', 'Hotwire', 'Agoda', 'CheapTickets'];
const createDailyPrices = () => {
fs.writeFileSync('./data.csv', `${columnNames.join(',')}\n`);
for (let j = 0; j < 1000; j += 1) {
@DanC5
DanC5 / gist:2cabd20e21bfcbd4d8684c270d34a0bc
Created March 28, 2019 20:42
API GET Request and Sample Data - Spotify
// GET Request
app.get('/data/toptracks', (req, res) => {
db.getTopTracks()
.then(results => res.json(results))
.catch(console.log)
});
// Database Schema and Query Function