Skip to content

Instantly share code, notes, and snippets.

View leblancmeneses's full-sized avatar
🏠
Working from home

Leblanc Meneses leblancmeneses

🏠
Working from home
View GitHub Profile
@dinvlad
dinvlad / retries.ts
Last active February 2, 2024 16:18
Retries with exponential backoff and jitter for idempotent background Google Cloud Functions
// one can also use Google Cloud Firestore library,
// with a slight change in semantics
import { firestore } from 'firebase-admin';
import { EventContext, runWith } from 'firebase-functions';
import { promisify } from 'util';
const eventCollection = 'function-events';
enum EventStatus {
RUNNING = 'running',
@mbleigh
mbleigh / README.md
Last active April 12, 2024 10:18
Firebase Hosting Fetch All Files

Fetch All Files from Firebase Hosting

This script fetches all of the files from the currently deployed version of a Firebase Hosting site. You must be signed in via the Firebase CLI and have "Site Viewer" permission on the site in question to be able to properly run the script.

Running via NPX

npx https://gist.github.com/mbleigh/9c8680cf319ace2f506f57380da66e7d <site_name>
@dnozay
dnozay / My Exiftool Cheatsheet.md
Last active November 12, 2023 15:48 — forked from rjames86/My Exiftool Cheatsheet.md
Cheatsheet for image / video metadata manipulation.

Cheatsheet for image / video metadata manipulation.

Last updated 2019-07-24

Disclaimer

until more specific license...

THE CONTENT BELOW IS PROVIDED "AS-IS",
WE DISCLAIM LIABILITY FOR ALL USES TO THE FULLEST EXTENT PERMITTED BY APPLICABLE LAW.
@mohanpedala
mohanpedala / bash_strict_mode.md
Last active April 16, 2024 08:50
set -e, -u, -o, -x pipefail explanation

A handful of BigQuery SQL queries that you can use to analyze your own Google Analytics for Firebase data. To find out more about how they work, check out our presentation from Cloud Next 2018 (Video link to be added soon)

Please note that these scripts have been updated to make sure of the new Firebase schema, which was rolled out to Analytics products in July of 2018.

Note that none of these scripts will work out of the box -- you'll need to update the values in brackets with the names of your actual datasets, and you'll most likely also need to replace the names of events and event properties with ones that are appropriate for your app.

The contents of this gist are licensed under the Apache License, version 2.0

export const countReviews = functions.firestore.document("movies/{movieId}/reviews/{reviewId}").onCreate(async (event) => {
console.log(`Got a ${event.data.data().stars} star review`);
const review = event.data.data();
admin.database().ref("movieRevies").child(event.params.movieId).transaction(movie => {
if (!movie) {
return movie;
}
@katowulf
katowulf / rules.js
Created March 3, 2016 00:05
Search for users by email address in Firebase, without exposing everyone's email address to the world in a bulk-readable format.
{
"rules": {
"users": {
"$user_id": {
// email address is required
".validate": "newData.hasChildren(['email'])",
}
},
"emails_to_users": {
@elcamino
elcamino / full-page-screenshots-selenium-chrome.rb
Last active February 1, 2024 21:41
How to take full-page screenshots with Selenium and Google Chrome in Ruby
#!/usr/bin/env ruby
require 'selenium-webdriver'
wd = Selenium::WebDriver.for :remote, url: 'http://10.3.1.7:4444/wd/hub', desired_capabilities: :chrome
wd.navigate.to 'https://snipt.net/restrada/python-selenium-workaround-for-full-page-screenshot-using-chromedriver-2x/'
# Get the actual page dimensions using javascript
#
width = wd.execute_script("return Math.max(document.body.scrollWidth, document.body.offsetWidth, document.documentElement.clientWidth, document.documentElement.scrollWidth, document.documentElement.offsetWidth);")

Template composition with inclusion

Every template language I have seen provides some mechanism for one template to include another, thus supporting the reuse of repeated elements like headers and footers. The included templates are called partials in Mustache parlance:

<!-- home.hbs -->
<html>
<body>
  {{> header}}
  <p> HOME </p>
  {{> footer}}
@mikelehen
mikelehen / generate-pushid.js
Created February 11, 2015 17:34
JavaScript code for generating Firebase Push IDs
/**
* Fancy ID generator that creates 20-character string identifiers with the following properties:
*
* 1. They're based on timestamp so that they sort *after* any existing ids.
* 2. They contain 72-bits of random data after the timestamp so that IDs won't collide with other clients' IDs.
* 3. They sort *lexicographically* (so the timestamp is converted to characters that will sort properly).
* 4. They're monotonically increasing. Even if you generate more than one in the same timestamp, the
* latter ones will sort after the former ones. We do this by using the previous random bits
* but "incrementing" them by 1 (only in the case of a timestamp collision).
*/