Skip to content

Instantly share code, notes, and snippets.

@gabhi
gabhi / gist:25a0994fd01f3a1d6795
Created April 7, 2015 09:37
isValidParentheses
// Time complexity: O(n)
function isValidParentheses(str) {
var i = 0, l = str.length, arr = [];
if (!l) {
return true;
}
if ((l % 2) !== 0) {
return false;
}
@gabhi
gabhi / gist:7a0829ce012aa6bff620
Created April 4, 2015 08:01
capturejs --uri http://phantomjs.org --output 'phantomjs.org.png'
capturejs --uri http://phantomjs.org --output 'phantomjs.org.png'
@gabhi
gabhi / gist:f7d24f850ffa9c2770e5
Created April 2, 2015 05:51
CSV to JSON node js
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);
@gabhi
gabhi / gist:202c19dc12f5a3f54f12
Created April 2, 2015 05:43
phantonjs node js screenshot of a website
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');
}
import org.apache.cxf.binding.soap.interceptor.SoapHeaderInterceptor;
import org.apache.cxf.configuration.security.AuthorizationPolicy;
import org.apache.cxf.endpoint.Endpoint;
import org.apache.cxf.interceptor.Fault;
import org.apache.cxf.message.Exchange;
import org.apache.cxf.message.Message;
import org.apache.cxf.transport.Conduit;
import org.apache.cxf.ws.addressing.EndpointReferenceType;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@gabhi
gabhi / gist:11484e4a08f46fe3bbb7
Created March 27, 2015 07:26
Algorithm for Determining Tic Tac Toe Game Over/winner
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){
@gabhi
gabhi / gist:750fcb1e499be000b277
Last active August 29, 2015 14:17
spark tutorial commands
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")
@gabhi
gabhi / gist:ee291f92e8a5efb3fae0
Last active August 29, 2015 14:17
rest server showcasing post/get/ getbyId using express/mongoose/mongodb
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
}));
@gabhi
gabhi / gist:5287805abc7cb1dfe3a1
Created March 18, 2015 09:26
node js streaming response example
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;
@gabhi
gabhi / gist:e22bd0d19dc7c346c512
Created March 18, 2015 08:25
Twitter Bot node js example
//
// 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.');