Skip to content

Instantly share code, notes, and snippets.

View node_hello_world.js
const http = require('http');
const hostname = '127.0.0.1';
const port = 3000;
const server = http.createServer((req, res) => {
res.statusCode = 200;
res.setHeader('Content-Type', 'text/plain');
res.end('Hello World');
});
View pyteaser_output.py
>>> from pyteaser import SummarizeUrl
>>> url = 'http://www.huffingtonpost.com/2013/11/22/twitter-forward-secrecy_n_4326599.html'
>>> summaries = SummarizeUrl(url)
>>> print summaries
Output
[
"Twitter's move is the latest response from U.S. Internet firms following disclosures by former spy agency contractor Edward Snowden about widespread, classified U.S. government surveillance programs.",
"Since then, it has become clearer and clearer how important that step was to protecting our users' privacy.",
"The online messaging service, which began scrambling communications in 2011 using traditional HTTPS encryption, said on Friday it has added an advanced layer of protection for HTTPS known as 'forward secrecy'",
View snippet_serverless_summarize.yaml
functions:
summarize:
handler: handler.summarize
events:
- http:
path: summarize
method: post
View example_slack_message_handler.js
// Initialize using signing secret from environment variables
const { createEventAdapter } = require('@slack/events-api');
const slackEvents = createEventAdapter(process.env.SLACK_SIGNING_SECRET);
const port = process.env.PORT || 3000;
// Attach listeners to events by Slack Event "type". See: https://api.slack.com/events/message.im
slackEvents.on('message', (event) => {
console.log(`Received a message event: user ${event.user} in channel ${event.channel} says ${event.text}`);
});
View snippet_serverless.yaml
functions:
slack_sqs:
handler: handler.sqsEvent
events:
- http:
path: slack_sqs
method: POST
- sqs: "arn:aws:sqs:us-east-1:<identifierhere>:summarizer-slack-to-summarizer"
View sqsEvent_serverless.js
module.exports.sqsEvent = async (event, context, callback) => {
// Read the SQS message we sent to ourselves
const record = event.Records[0];
const thread = record.messageAttributes.Thread.stringValue;
const channel = record.messageAttributes.Channel.stringValue;
const token = record.messageAttributes.Token.stringValue;
let url = record.messageAttributes.URL.stringValue;
View cortex.yaml
- name: summarizer
predictor:
type: python
path: predictor.py
compute:
cpu: 1
gpu: 1
mem: 1G
View slack_postmessage.js
var postMessage = async function(params) {
var response = await fetch('https://slack.com/api/chat.postMessage', {
method: 'POST',
body: params
})
var data = await response.json()
return data
}
View slack_serverless_handler.js
var buildReply = async function (msg, token, thread, url) {
var channel = msg.event.channel
// Check if URL exists
if (url.length > 0) {
// Load the AWS SDK for Node.js
var AWS = require('aws-sdk');
AWS.config.update({
region: 'us-east-1'
})
// Create an SQS service object
View summarizer_serverless_handler.js
module.exports.summarize = async (event, context, callback) => {
var body = event.body
var url = JSON.parse(body).url
let {
response,
selector,
} = await utils.getSummaryFromUrl(url)
return {
You can’t perform that action at this time.