Skip to content

Instantly share code, notes, and snippets.

View cbrannen9a's full-sized avatar

Chris Brannen cbrannen9a

View GitHub Profile
@cbrannen9a
cbrannen9a / partial_fieldValidator2.js
Created November 8, 2018 12:20
Partial demo of credit card check using Regex and luhnCheck methods
const validateCardNumber = (number) => {
var regex = new RegExp("^[0-9]{16}$");
if (!regex.test(number)) { return false; }
return luhnCheck(number);
}
const luhnCheck = (val) => {
var sum = 0;
for (var i = 0; i < val.length; i++) {
@cbrannen9a
cbrannen9a / main.py
Created April 1, 2019 08:33
Add data from csv to firestore with types
import csv
import firebase_admin
import google.cloud
from firebase_admin import credentials, firestore
cred = credentials.Certificate("./ServiceAccountKey.json")
app = firebase_admin.initialize_app(cred)
store = firestore.client()
@cbrannen9a
cbrannen9a / UseState.js
Created January 18, 2019 10:03
React hooks useState example
export const UseState = () => {
//Declare state value of count and setCount function to update
//set the initial value of count as 0
const [count, setCount] = useState(0);
//setCount function
return (
<div className='content'>
<h4>UseState</h4>
<p>You clicked {count} times</p>
@cbrannen9a
cbrannen9a / test.py
Created January 4, 2019 15:36
Checking data from firestore
import firebase_admin
from firebase_admin import credentials, firestore
cred = credentials.Certificate("./ServiceAccountKey.json")
app = firebase_admin.initialize_app(cred)
store = firestore.client()
doc_ref = store.collection(u'COLLECTION_TO_CHECK')
data = []
@cbrannen9a
cbrannen9a / main.py
Created January 4, 2019 14:44
Add data from csv to Firestore
import csv
import firebase_admin
import google.cloud
from firebase_admin import credentials, firestore
cred = credentials.Certificate("./ServiceAccountKey.json")
app = firebase_admin.initialize_app(cred)
store = firestore.client()
@cbrannen9a
cbrannen9a / main.py
Created January 4, 2019 12:43
Adding data to Firestore
import firebase_admin
import google.cloud
from firebase_admin import credentials, firestore
cred = credentials.Certificate("./ServiceAccountKey.json")
app = firebase_admin.initialize_app(cred)
store = firestore.client()
doc_ref = store.collection(u'test')
@cbrannen9a
cbrannen9a / main.py
Created January 4, 2019 12:35
Get data from Firestore
import firebase_admin
import google.cloud
from firebase_admin import credentials, firestore
cred = credentials.Certificate("./ServiceAccountKey.json")
app = firebase_admin.initialize_app(cred)
store = firestore.client()
doc_ref = store.collection(u'users').limit(2)
@cbrannen9a
cbrannen9a / requirements.py
Created January 4, 2019 12:01
Requirements
pip install firebase-admin google-cloud-firestore
@cbrannen9a
cbrannen9a / setup.py
Created January 4, 2019 11:45
Virtualenv setup
virtualenv env
@cbrannen9a
cbrannen9a / Example2.js
Created November 12, 2018 17:09
Adding second hook
import React, { useState, useEffect } from 'react';
function Example() {
// Declare a new state variable, which we'll call "count"
const [count, setCount] = useState(0);
useEffect(() => {
// Update the document title using the browser API
document.title = `You have written ${count} hooks`;
});