Skip to content

Instantly share code, notes, and snippets.

@demosifter
demosifter / how-to-text-utilities.js
Last active October 15, 2016 16:03
requiring text-utils
let textUtils = require('@redsift/text-utilities');
// ...
let counts = others.map(value => {
let text = value.textBody || value.strippedHtmlBody || '';
let count = textUtils.splitWords(textUtils.trimEmailThreads(text)).length;
return count;
});
console.log(counts);
"dag": {
...
"nodes":[{
"#": "First Node",
"input": {
"bucket": "gmailEmails"
},
"implementation": {
"javascript": "server/node1.js"
},
module.exports = function (got) {
const json = got.in.data.map(d => JSON.parse(d.value));
const query = got.query;
const threadId = query[0];
let newestCount = json
.sort((a, b) => new Date(b.date).getTime() - new Date(a.date).getTime())
.shift().count;
return [{
loadThreadListView (listInfo) {
console.log('counter: loadThreadListView: ', listInfo);
if (listInfo) {
return {
template: '001_list_common_txt',
value: {
color: '#ffffff',
backgroundColor: '#e11010',
subtitle: listInfo + ' words'
}
module.exports = function (got) {
const total = got.in.data.reduce((p, d) => p + parseInt(d.value), 0);
return {
key: 'word_count',
value: total
}
}
return {
key: `${value.threadId}/${value.id}`, // instead of 'value.id
value: {
count: count,
date: value.date
}
}
<div class="column">
<p>I'm a Sift!</p>
<p id='number'>0</p>
</div>
//...
constructor() {
// You have to call the super() method to initialize the base class.
super();
this.controller.subscribe('counts', this.onCounts.bind(this));
}
// for more info: https://docs.redsift.com/docs/client-code-siftview
presentView(value) {
console.log('counter: presentView: ', value);
constructor() {
// You have to call the super() method to initialize the base class.
super();
this._suHandler = this.onStorageUpdate.bind(this);
}
loadView(state) {
console.log('counter: loadView', state);
this.storage.subscribe(['count'], this._suHandler);
@demosifter
demosifter / how-to-node1-1.js
Last active October 11, 2016 17:42
Simple node implementation in server/node1.js
module.exports = function (got) {
// got.in contains the key/value pairs that match the given query
const inData = got.in;
console.log('counter: node1.js: running...', inData.data);
const json = inData.data.map(d => JSON.parse(d.value));
json.forEach(function(value, i){
console.log('datum#', i, 'value:', value)