Skip to content

Instantly share code, notes, and snippets.

@lgvalle
lgvalle / firebase-scraping.js
Last active September 23, 2021 01:17
Firebase cloud function to scrap html and send the content with push notifications
const rp = require('request-promise');
const cheerio = require('cheerio');
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp();
const db = admin.firestore();
exports.allyPallyFarmersMarket = functions.https.onRequest((request, response) => {
@lgvalle
lgvalle / gist:d03f594c85db23b432ff9ab173f10e24
Created March 31, 2018 15:03
Run firebase tools docker image
docker run -v $PWD:/usr/app -w /usr/app -p 9005:9005 -u node -it lgvalle/firebasetools:v2 sh
@lgvalle
lgvalle / Docker shell commands.sh
Created March 31, 2018 12:45 — forked from bahmutov/Docker shell commands.sh
A personal cheat sheet for running local Node project in a Docker container
# See list of docker virtual machines on the local box
$ docker-machine ls
NAME ACTIVE URL STATE URL SWARM DOCKER ERRORS
default * virtualbox Running tcp://192.168.99.100:2376 v1.9.1
# Note the host URL 192.168.99.100 - it will be used later!
# Build an image from current folder under given image name
$ docker build -t gleb/demo-app .
@lgvalle
lgvalle / docker-compose.yml
Last active February 26, 2018 15:32
openstf
version: '3'
services:
rethinkdb:
image: rethinkdb:2.3
ports:
- "8080:8080"
- "28015:28015"
- "29015:29015"
restart: always
volumes:
@lgvalle
lgvalle / index.js
Created September 10, 2017 18:38
Blogpost Firebase II - Full code
const ONE_HOUR = 3600000
var functions = require('firebase-functions');
const URL_THE_GUARDIAN = "https://www.theguardian.com/uk/london/rss"
var Client = require('node-rest-client').Client;
var client = new Client();
const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);
const functions = require('firebase-functions')
const URL_THE_GUARDIAN = "https://www.theguardian.com/uk/london/rss"
const Client = require('node-rest-client').Client
const client = new Client()
exports.fetch = functions.https.onRequest((req, res) => {
client.get(URL_THE_GUARDIAN, function (data, response) {
const items = cleanUp(data)
res.status(201)
function cleanUp(data) {
// Empty array to add cleaned up elements to
const items = []
// We are only interested in children of the 'channel' element
const channel = data.rss.channel
channel.item.forEach(element => {
item = {
title: element.title,
description: element.description,
[{
"title": "'Leaving London means I can afford kids': readers on why the capital lost its sparkle",
"description": "Almost 100,000 Londoners moved out last year. Here they, and others who are avoiding the city altogether, explain why it is no longer the place to be<br></p><p>The rate of Londoners leaving the capital is more than <a href="https://www.theguardian.com/uk-news/2017/jul/24/bloated-london-property-prices-fuelling-exodus-from-capital">80% higher than five years ago</a>, according to Savills, with people in their thirties the age group most likely to leave. </p><p>We asked readers why they’re leaving London, or avoiding moving to the capital altogether. Here’s what you said:</p><p>All my salary was being spent on living costs in London</p> <a href="https://www.theguardian.com/uk-news/2017/jul/31/leaving-london-means-i-can-afford-kids-readers-on-why-the-capital-lost-its-sparkle">Continue reading...</a>",
"date": "Mon, 31 Jul 2
<rss xmlns:media=”http://search.yahoo.com/mrss/" xmlns:dc=”http://purl.org/dc/elements/1.1/" version=”2.0">
 <channel>
 <title>London | The Guardian</title>
 <link>https://www.theguardian.com/uk/london</link>
 <description>Latest news and features from theguardian.com, the world’s leading liberal voice</description>
 <language>en-gb</language>
 <copyright>Guardian News and Media Limited or its affiliated companies. All rights reserved. 2017</copyright>
 <pubDate>Mon, 31 Jul 2017 15:32:49 GMT</pubDate>
 <dc:date>2017–07–31T15:32:49Z</dc:date>
 <dc:language>en-gb</dc:language>
@lgvalle
lgvalle / step2.js
Last active August 8, 2017 06:57
Post: Take control of your backend (II)
const Client = require('node - rest - client').Client
const client = new Client()
exports.fetch = functions.https.onRequest((req, res) => {
client.get(BACKEND_URL, function (data, response) {
(…) // TODO Clean up
return res.status(200)
.type('application / json')
.send(data)