Skip to content

Instantly share code, notes, and snippets.

View rominirani's full-sized avatar

Romin Irani rominirani

  • Mumbai
View GitHub Profile
@rominirani
rominirani / main.py
Last active August 28, 2023 04:50
Python Cloud Function to summarize text via PaLM2 Bison Text Model
import os
import json
import functions_framework
import google.cloud.logging
import vertexai
from vertexai.language_models import TextGenerationModel
PROJECT_ID = os.environ.get('GCP_PROJECT','-')
@rominirani
rominirani / snippet.js
Created October 21, 2018 14:50
Puppeteer code snippet to fetch comic strip
const browser = await puppeteer.launch({args: ['--no-sandbox']});
const page = await browser.newPage();
await page.goto("https://loveiscomix.com/random");
let imageurl = await page.evaluate(() => {
let item = document.querySelector('#primary > main > article > div > div.cellcomic > a > img');
return 'https://loveiscomix.com/' + item.getAttribute('src');
})
browser.close();
@rominirani
rominirani / index.js
Created October 21, 2018 14:35
Love Is Comic Google Cloud Function
let LoveIsComic_HTMLTemplate = (
url
) => {
return `
<!DOCTYPE html>
<html>
<head>
<title>Love Is Comic</title>
</head>
<body>
@rominirani
rominirani / bq.md
Last active September 6, 2018 05:24

Public Data Set to use

bigquery-public-data.new_york_taxi_trips.tlc_yellow_trips_2017

Dataset details

Table size 12.79 GB

Number of rows 113,496,874

Find the most expensive taxi trip taken

``SELECT total_amount, pickup_datetime, trip_distance

@rominirani
rominirani / index.js
Created May 31, 2018 08:09
Apps Script method to invoke the Cloud Natural Language API
function retrieveSentimentCF (line) {
var apiEndpoint = 'YOUR_CLOUDFUNCTIONS_HTTPS_ENDPOINT';
var reviewData = {
review_text: line
};
var cfCallOptions = {
method : 'post',
contentType: 'application/json',
@rominirani
rominirani / index.js
Created May 31, 2018 07:55
Cloud Function for invoking the Google Cloud Natural Language API
'use strict';
const Language = require('@google-cloud/language');
// Instantiates a client
const language = new Language.LanguageServiceClient();
exports.analyzeSentiment = (req, res) => {
if (req.body.review_text == undefined) {
res.status(400).send("No review text provided");
@rominirani
rominirani / index.js
Created May 31, 2018 06:20
Apps Script to invoke Google Cloud Natural Language API in Google Sheet
function onOpen() {
var ui = SpreadsheetApp.getUi();
ui.createMenu('Review Analysis Tools')
.addItem('Analyze Sentiment', 'analyzeSentiment')
.addToUi();
}
function analyzeSentiment() {
@rominirani
rominirani / index.js
Created May 31, 2018 06:14
Apps Script code for using Google Cloud Natural Language API
function onOpen() {
var ui = SpreadsheetApp.getUi();
ui.createMenu('Review Analysis Tools')
.addItem('Analyze Sentiment', 'analyzeSentiment')
.addToUi();
}
function analyzeSentiment() {
@rominirani
rominirani / index.js
Created May 16, 2018 05:28
Firestore Cloud Functions Demo
const admin = require('firebase-admin');
const functions = require('firebase-functions');
//Initialize Firebase
admin.initializeApp(functions.config().firebase);
const db = admin.firestore();
//Number of Questions. We could have evaluated the count of questions, but thats for a future
'use strict';
const axios = require("axios");
const url = "https://api.coindesk.com/v1/bpi/currentprice.json"
function verifyWebhook (body) {
if (!body || body.token !== "--YOUR_VERIFICATION_TOKEN--") {
const error = new Error('Invalid credentials');
error.code = 401;
throw error;