Skip to content

Instantly share code, notes, and snippets.

View sAbakumoff's full-sized avatar

Sergey Abakumoff sAbakumoff

View GitHub Profile
var Twitter = require('twitter');
var client = new Twitter(/*pass auth keys*/);
function startTracking(topic){
var isTweet = obj => obj && typeof obj.id_str === 'string' &&
typeof obj.text === 'string' && obj.place &&
obj.place.country_code === "US" && obj.place.place_type === "city";
var handleTweet = tweet => {
if(isTweet(tweet)){
topic.publish({
var gcloud = require('google-cloud');
var pubsub = gcloud.pubsub({
projectId: 'in-full-gear',
keyFilename: __dirname + '/../secret/auth_key.json'
});
var topic = pubsub.topic('debate_tweets');
topic.get({autoCreate : true}, function(err, topic, apiResponse) {
if(err){
pipeline.apply(PubsubIO.Read.timestampLabel("created_at").topic("projects/in-full-gear/topics/debate_tweets"))
.apply(ParDo.of(new DoFn<String, TableRow>(){
@Override
public void processElement(ProcessContext c) {
TableRow row = new TableRow();
try{
JSONParser parser = new JSONParser();
Object obj = parser.parse(c.element());
%%bigquery udf --module extract_tokens
/**
* @param {{tweet_object: string, polarity: float, magnitude: float, syntax:string }} r
* @param function({{type: string, content:string}}) emitFn
*/
function(r, emitFn) {
try{
var tweet = JSON.parse(r.tweet_object);
var tokens = JSON.parse(r.syntax);
if (!Array.prototype.forEach) {
Array.prototype.forEach = function(callback, thisArg) {
if (this === null) {
throw new TypeError('Array.prototype.forEach called on null or undefined');
}
if (typeof callback !== "function") {
throw new TypeError(callback + ' is not a function');
}
var O = Object(this), len = O.length >>> 0, k = 0, value;
if (arguments.length > 1) {
if (!Array.prototype.forEach) {
Array.prototype.forEach = function(callback, thisArg) {
if (this === null) {
throw new TypeError('Array.prototype.forEach called on null or undefined');
}
if (typeof callback !== "function") {
throw new TypeError(callback + ' is not a function');
}
var len = this.length || 0;
for(var i=0; i<len;i++){
// way#1 - adding the element to an arbitrary position
var a1 = new Array();
a1[1000 * 1000 * 1000] = 'a';
a1.length; // 1000000001
// way#2 - setting the length at creation time
var a2 = new Array(1000*1000*1000 + 1);
a2[0] = 'a';
a2.length; // 1000000001
var a = new Array(1000*1000*1000 + 1);
a[0] = 'a'; a[110] = 'b'; a[900] = 'c';
Object.getOwnPropertyNames(a); // ["0", "110", "900", "length"]
// in operator automatically converts the left part to string
110 in a; // true
15 in a; // false
a[15] = 'd';
15 in a; // true
Object.getOwnPropertyNames(a); // ["0", "15", 110", "900", "length"]
(function f(){
var filterFn = Array.prototype.filter;
filterFn.call(arguments, function(item){
return item !== null;
}).forEach(function(item){
alert(item); // will show 1,2,3 and 5
});
})(1,2,3,null,5);
var str="JavaScript is awesome";
var reduceRightFn = Array.prototype.reduceRight;
var reverse_str = reduceRightFn.call(str, function(char1, char2){
return char1 + char2;
});
alert(reverse_str); //emosewa si tpircSavaJ