Skip to content

Instantly share code, notes, and snippets.

SELECT *
FROM search_logs
WHERE keyword = ‘rockset’
AND locale = ‘en’
SELECT keyword, count(*) c
FROM search_logs
GROUP BY keyword
ORDER BY c DESC
@julie-mills
julie-mills / FacebookBot.sql
Created July 31, 2019 23:14
FacebookMessengerBot
// Accepts POST requests at the /webhook endpoint
app.post('/webhook', (req, res) => { let body = req.body; if
(body.object === 'page') { body.entry.forEach(function(entry) { let
event = entry.messaging[0]; if (event.message && event.message.text)
{ // handle the message handleMessage(event); } }); // Return a '200
OK' response res.status(200).send('EVENT_RECEIVED'); } else { //
Return a '404 Not Found' res.sendStatus(404); } });
// Accepts POST requests at the /webhook endpoint
app.post('/webhook', (req, res) => { let body = req.body; if
(body.object === 'page') { body.entry.forEach(function(entry) { let
event = entry.messaging[0]; if (event.message && event.message.text)
{ // handle the message handleMessage(event); } }); // Return a '200
OK' response res.status(200).send('EVENT_RECEIVED'); } else { //
Return a '404 Not Found' res.sendStatus(404); } });
// Accepts POST requests at the /webhook endpoint
app.post('/webhook', (req, res) => {
let body = req.body;
if (body.object === 'page') {
body.entry.forEach(function(entry) {
let event = entry.messaging[0];
if (event.message && event.message.text) {
// handle the message
handleMessage(event);
}
@julie-mills
julie-mills / interacting.sql
Created July 31, 2019 23:19
Interacting with chatboot
with listings as (
select id, name, price, property_type
from airbnb_listings
where lower(airbnb_listings.city) like :city
and airbnb_listings.accommodates::int >= :number
order by airbnb_listings.number_of_reviews desc
)
select listings.id, listings.name, listings.property_type, listings.price
from listings, airbnb_calendar
where airbnb_calendar.date = :date and airbnb_calendar.available = :avail
@julie-mills
julie-mills / summaryairbnb.sql
Created July 31, 2019 23:21
summary airbnb
select summary from airbnb_listings where id = :listing_id
select comments, date
from airbnb_reviews
where listing_id = :listing_id
order by date desc
limit 3
exports.handler = async (event, context) => {
for (const record of event.Records) {
let platform = record.dynamodb['NewImage']['platform']['S'];
let amount = record.dynamodb['NewImage']['amount']['N'];
let data = ... // format according to your Redshift schema
var params = {
Data: data
StreamName: 'test'
PartitionKey: '1234'
};
import json
from botocore.vendored import requests
import os
ROCKSET_APIKEY = os.environ.get('ROCKSET_APIKEY')
QUERY_TEXT = """
WITH vehicle_incidents AS (
SELECT
*
FROM