Skip to content

Instantly share code, notes, and snippets.

@devStepsize
devStepsize / alchemy_api_get_sentiment_sample.py
Last active April 22, 2016 23:07
Method to return the given overall sentiment its strength for a given string using the Alchemy API
import requests
def get_sentiment(body):
endpoint = "http://gateway-a.watsonplatform.net/calls/text/TextGetTextSentiment"
parameters = {
'apikey': API_KEY,
'outputMode': 'json',
'text': body
}
@devStepsize
devStepsize / index.html
Created April 22, 2016 21:56
An example index.html for a renderer process in an electron app.
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Hello World!</title>
</head>
<body>
<h1>Hello World!</h1>
We are using node <script>document.write(process.versions.node)</script>,
Chrome <script>document.write(process.versions.chrome)</script>,
@devStepsize
devStepsize / main.js
Created April 22, 2016 21:54
A basic example main.js for an electron app.
'use strict';
const electron = require('electron');
const app = electron.app; // Module to control application life.
const BrowserWindow = electron.BrowserWindow; // Module to create native browser window.
// Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the JavaScript object is garbage collected.
var mainWindow = null;
@devStepsize
devStepsize / electron_package.json
Last active April 22, 2016 21:55
A basic example package.json for an electron app.
{
"name" : "your-app",
"version" : "0.1.0",
"main" : "main.js"
}
@devStepsize
devStepsize / botkit_change_ears.js
Created April 22, 2016 21:22
Botkit replace the built in regex match with a middleware function
// From https://github.com/howdyai/botkit#hear-middleware
// This will replace the matching function used in hears() as well as inside convo.ask()
controller.changeEars(function(patterns, message) {
// ... do something
// return true or false
});
@devStepsize
devStepsize / botkit_hear_middleware.js
Last active April 22, 2016 21:19
Botkit hear middleware to change the way bots hear triggers
// From https://github.com/howdyai/botkit#hear-middleware
// this example does a simple string match instead of using regular expressions
function custom_hear_middleware(patterns, message) {
for (var p = 0; p < patterns.length; p++) {
if (patterns[p] == message.text) {
return true;
}
}
return false;
@devStepsize
devStepsize / ipcrenderer_on.html
Last active April 22, 2016 21:18
An example of the recieving end for messages from the main process.
<!-- index.html -->
<html>
<body>
<script>
require('electron').ipcRenderer.on('ping', function(event, message) {
console.log(message); // Prints "whoooooooh!"
});
</script>
</body>
</html>
@devStepsize
devStepsize / botkit_send_middleware.js
Created April 22, 2016 21:14
Botkit send middleware to do things like preprocess the message content before it gets sent
// From https://github.com/howdyai/botkit#send-middleware
controller.middleware.send.use(function(bot, message, next) {
// do something useful...
if (message.intent == 'hi') {
message.text = 'Hello!!!';
}
next();
});
@devStepsize
devStepsize / botkit_receive_middleware.js
Last active April 22, 2016 21:15
Botkit receive middleware to do things like preprocess the incoming message content
// From https://github.com/howdyai/botkit#receive-middleware
controller.middleware.receive.use(function(bot, message, next) {
// do something...
// message.extrainfo = 'foo';
next();
});
@devStepsize
devStepsize / botkit_facebook_say.js
Created April 22, 2016 21:08
Botkit say something on Facebook
// From https://github.com/howdyai/botkit#botsay
bot.say(
{
text: 'my message_text',
channel: '+1(###)###-####' // a valid facebook user id or phone number
}
);