This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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++){ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%%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); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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){ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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({ |