This file contains 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
// Time complexity: O(n) | |
function isValidParentheses(str) { | |
var i = 0, l = str.length, arr = []; | |
if (!l) { | |
return true; | |
} | |
if ((l % 2) !== 0) { | |
return false; | |
} |
This file contains 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
capturejs --uri http://phantomjs.org --output 'phantomjs.org.png' | |
This file contains 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 Converter=require("csvtojson").core.Converter; | |
var csvConverter=new Converter({constructResult:false, toArrayString:true}); // The constructResult parameter=false will turn off final result construction in memory for stream feature. toArrayString will stream out a normal JSON array object. | |
var readStream=require("fs").createReadStream("top-1m.csv"); | |
var writeStream=require("fs").createWriteStream("outpuData.json"); | |
readStream.pipe(csvConverter).pipe(writeStream); |
This file contains 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 phantom = require('phantom'); | |
var website_name = "amazon.in"; | |
var takeScreenShot = function(website_name) { | |
phantom.create(function(ph) { | |
ph.createPage(function(page) { | |
page.open("http://" + website_name, function(status) { | |
if (status === "success") { | |
page.render("./images/"+website_name + '.png'); | |
} |
This file contains 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
public class TripleT { | |
enum State{Blank, X, O}; | |
int n = 3; | |
State[][] board = new State[n][n]; | |
int moveCount; | |
void Move(int x, int y, State s){ | |
if(board[x][y] == State.Blank){ |
This file contains 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
val data = 1 to 10000 | |
val distData = sc.parallelize(data) | |
//display values less than 10 | |
distData.filter(_ < 10).collect() | |
//Word count | |
val f = sc.textFile("README.md") | |
val wc = f.flatMap(l => l.split(" ")).map(word => (word, 1)).reduceByKey(_ + _) | |
wc.saveAsTextFile("wc_out") |
This file contains 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 express = require('express'); | |
var app = express(); | |
var request = require("request"); | |
var bodyParser = require('body-parser') | |
app.use(bodyParser.json()); // to support JSON-encoded bodies | |
app.use(bodyParser.urlencoded({ // to support URL-encoded bodies | |
extended: true | |
})); |
This file contains 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 express = require('express') | |
var app = express() | |
app.get('/', function(req, res) { | |
res.write('<html><head>'); | |
res.write('<body>'); | |
res.write("hello"); | |
res.write("<ol>"); | |
var i = 0; |
This file contains 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
// | |
// RTD2 - Twitter bot that tweets about the most popular github.com news | |
// Also makes new friends and prunes its followings. | |
// | |
var Bot = require("./bot") | |
, config1 = require("../config1"); | |
var bot = new Bot(config1); | |
console.log('RTD2: Running.'); |