Skip to content

Instantly share code, notes, and snippets.

View DrDanL's full-sized avatar

Dan Leightley DrDanL

View GitHub Profile
@DrDanL
DrDanL / python-big-query.py
Created September 1, 2023 15:15
Query and download data from Google BigQuery buckets using Python and google.cloud and pandas
from google.cloud import bigquery
from google.oauth2 import service_account
import pandas as pd
# generate a service account container based on service account key
credentials = service_account.Credentials.from_service_account_file('ServiceAccountKey.json')
# define the project ID
project_id = ''
@DrDanL
DrDanL / python-storage-bucket.py
Created September 1, 2023 15:05
Query and download data from Google Storage buckets using Python and pyrebase
import pyrebase
import os
# define firebase config for the project being queried
firebaseConfig = {
"apiKey": "",
"authDomain": "",
"projectId": "",
"storageBucket": "",
"messagingSenderId": "",
@DrDanL
DrDanL / python-firestore.py
Created September 1, 2023 14:26
Query and download data from Google Firestore using Python and firebase_admin
import pandas as pd
import firebase_admin
from firebase_admin import credentials, firestore
# set the root folder path
base_url = '<BASE URL HERE>'
# used for paging when downloading data e.g. only 1000 documents downloaded per call
limit = 1000
@DrDanL
DrDanL / api.js
Created February 14, 2020 15:51
Firebase RESTful server API - Authentication validation
const express = require('express');
const http = require('http');
const https = require('https');
const app = express();
const router = express.Router();
const cors = require('cors')
const admin = require('firebase-admin');
const bodyParser = require('body-parser');
server {
listen 80;
listen [::]:80;
server_name kcmhr.org www.kcmhr.org;
return 301 https://$host$request_uri;
}
server {
@DrDanL
DrDanL / thameslink.py
Created June 15, 2018 16:41
This is a Gist for using Python 3 to perform NLP. This is from the blog post entitled Sentiment analysis of Thameslink Tweets using Python 3. See http://leightley.com/sentiment-analysis-of-thameslink-tweets-using-python
@DrDanL
DrDanL / canActiveRoutes.js
Created May 11, 2018 09:15
Example of canActiveRoutes.js in protecting routes using Firebase. See https://leightley.com/angular-2-and-firebase-authentication-route-guard/
import { ModuleWithProviders } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { AppComponent } from './app.component';
import { AuthGuard } from "./services/authGuard.service";
import { LoginComponent } from "./views/login/login.component";
import { SignupComponent } from './views/signup/signup.component';
import { DashboardComponent } from "./views/dashboard/dashboard.component";
@DrDanL
DrDanL / canActivate.js
Last active August 21, 2020 12:07
Example of CanActivate being used to check if a user is logged in or not via Firebase - see https://leightley.com/angular-2-and-firebase-authentication-route-guard/
import { Injectable } from '@angular/core';
import { CanActivate, ActivatedRouteSnapshot, RouterStateSnapshot, Router } from '@angular/router';
import { Observable } from 'rxjs/Observable';
import { AngularFireAuth } from 'angularfire2/auth';
import 'rxjs/add/operator/do';
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/take';
@Injectable()
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
exports.deleteProfile = functions.auth.user().onDelete( event => {
return admin.database().ref(`/user/${event.data.uid}`).remove();
});
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
exports.createProfile = functions.auth.user().onCreate( event => {
return admin.database().ref(`/user/${event.data.uid}`).set({
email: event.data.email,
emailUpdates: true
});
});