Skip to content

Instantly share code, notes, and snippets.

Avatar
🤹‍♂️
hardly working

Jeff Delaney codediodeio

🤹‍♂️
hardly working
View GitHub Profile
@codediodeio
codediodeio / config.js
Last active Feb 23, 2021
Snippets from the Firestore Data Modeling Course
View config.js
import * as firebase from 'firebase/app';
import 'firebase/firestore';
var firebaseConfig = {
// your firebase credentials
};
// Initialize Firebase
firebase.initializeApp(firebaseConfig);
@codediodeio
codediodeio / database.rules.json
Last active Feb 23, 2021
Common Database Rules for Firebase
View database.rules.json
// No Security
{
"rules": {
".read": true,
".write": true
}
}
@codediodeio
codediodeio / index.js
Last active Jan 23, 2021
Transactional Email Firebase Cloud Function with Sendgrid
View index.js
var functions = require('firebase-functions');
const sendgrid = require('sendgrid')
const client = sendgrid("YOUR_SG_API_KEY")
function parseBody(body) {
var helper = sendgrid.mail;
var fromEmail = new helper.Email(body.from);
var toEmail = new helper.Email(body.to);
var subject = body.subject;
@codediodeio
codediodeio / index.js
Created Sep 13, 2017
Integrate Twilio with Firebase Cloud Functions
View index.js
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
const twilio = require('twilio');
const accountSid = functions.config().twilio.sid
const authToken = functions.config().twilio.token
const client = new twilio(accountSid, authToken);
View state-alt.dart
import 'package:flutter/material.dart';
Stream<bool> interval =
Stream.periodic(Duration(seconds: 1), (i) => (i % 2 == 0))
.asBroadcastStream();
class Blink extends StatelessWidget {
String text;
Blink({Key key, this.text}) : super(key: key);
@codediodeio
codediodeio / phone-login.component.html
Last active Dec 23, 2020
Firebase Phone Login Angular 4
View phone-login.component.html
<div [hidden]="user">
<h1>Sign In with Your Phone Number</h1>
<label for="phone">Phone Number</label><br>
<input type="text" [(ngModel)]="phoneNumber.country" class="input" placeholder="1" maxlength="2">
<input type="text" [(ngModel)]="phoneNumber.area" class="input" placeholder="949" maxlength="3">
<input type="text" [(ngModel)]="phoneNumber.prefix" class="input" placeholder="555" maxlength="3">
<input type="text" [(ngModel)]="phoneNumber.line" class="input" placeholder="5555" maxlength="4">
@codediodeio
codediodeio / geo-json.ts
Last active Nov 10, 2020
A Typescript interface for GeoJSON objects based on rfc7946
View geo-json.ts
export interface IGeometry {
type: string;
coordinates: number[];
}
export interface IGeoJson {
type: string;
geometry: IGeometry;
bbox?: number[];
properties?: any;
@codediodeio
codediodeio / reverse-int.js
Created Sep 4, 2017
Reverse integer and determine overflow in JavaScript - LeetCode solution
View reverse-int.js
/**
* @param {number} x
* @return {number}
*/
var reverse = function(x) {
let a = x.toString().split('')
let num;
if(a[0] == '-') {
let c = a.shift()
num = parseInt(c +a.reverse().join(''))
@codediodeio
codediodeio / longest-substring.js
Created Sep 4, 2017
Longest Substring JavaScript - LeetCode Solution
View longest-substring.js
// Given a string, find the length of the longest substring without repeating characters.
// Examples:
// Given "abcabcbb", the answer is "abc", which the length is 3.
// Given "bbbbb", the answer is "b", with the length of 1.
// Given "pwwkew", the answer is "wke", with the length of 3. Note that the answer must be a substring, "pwke" is a subsequence and not a substring.
@codediodeio
codediodeio / index.js
Created Jun 28, 2017
Firebase Cloud Functions image thumbnail generator using Sharp for 4x faster resizing
View index.js
const functions = require('firebase-functions');
const gcs = require('@google-cloud/storage')();
const sharp = require('sharp')
const _ = require('lodash');
const path = require('path');
const os = require('os');
exports.generateThumbnail = functions.storage.object('uploads/{imageId}').onChange(event => {
const object = event.data; // The Storage object.