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
import java.net.UnknownHostException; | |
import com.mongodb.Mongo; | |
import com.mongodb.DB; | |
import com.mongodb.DBCollection; | |
import com.mongodb.BasicDBObject; | |
import com.mongodb.DBCursor; | |
import com.mongodb.MongoException; | |
public class Mongo_Insert_Collection |
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
import com.mongodb.MongoClient; | |
import com.mongodb.MongoException; | |
import com.mongodb.WriteConcern; | |
import com.mongodb.DB; | |
import com.mongodb.DBCollection; | |
import com.mongodb.BasicDBObject; | |
import com.mongodb.DBObject; | |
import com.mongodb.DBCursor; | |
import com.mongodb.ServerAddress; | |
import java.util.Arrays; |
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
//STEP 1. Import required packages | |
import java.sql.*; | |
public class MySQL_Insert | |
{ | |
// JDBC driver name and database URL | |
static final String JDBC_DRIVER = "com.mysql.jdbc.Driver"; | |
static final String DB_URL = "jdbc:mysql://localhost/test"; | |
// Database credentials |
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
//STEP 1. Import required packages | |
import java.sql.*; | |
public class MySQL_Fetch | |
{ | |
// JDBC driver name and database URL | |
static final String JDBC_DRIVER = "com.mysql.jdbc.Driver"; | |
static final String DB_URL = "jdbc:mysql://localhost/test"; | |
// Database credentials |
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
#!/usr/bin/ruby | |
require './dijkstra' | |
def haversine (lat1, lon1, lat2, lon2) | |
r = 6371 # earth radius, km | |
degToRadConvFac = Math::PI / 180 | |
p1 = lat1 * degToRadConvFac | |
p2 = lat2 * degToRadConvFac |
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
Commands and editing for the five steps of the Hadoop DIY tutorial by Prithwis Mukherjee ( @prithwis ) at Ref [1]. | |
The five steps | |
-------------- | |
1. Install Hadoop 2.2, in a single machine cluster mode on a machine running Ubuntu | |
2. Compile and run the standard WordCount example in Java | |
3. Compile and run another, non WordCount, program in Java | |
4. Use the Hadoop streaming utility to run a WordCount program written in Python, as an example of a non-Java application | |
5. Compile and run a java program that actually solves a small but representative Predictive Analytics problem |
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
#! /usr/bin/env python | |
txt = 'but soft what light in yonder window breaks' | |
words = txt.split() | |
t = list() | |
for word in words: | |
t.append((len(word), word)) | |
t.sort(reverse = 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
#! /usr/bin/env ruby | |
require "./mh_util" | |
txt = 'but soft what light in yonder window breaks' | |
words = txt.split() | |
t = [] | |
words.each {|word| t << MH_util::Tuple.new(word.size, word)} | |
t.sort!.reverse! |
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
module MH_util | |
Tuple = Struct.new(:first, :second) do | |
def <=>(other) | |
return second <=> other.second if first == other.first | |
first <=> other.first | |
end | |
def to_s | |
"(#{first}, #{second})" | |
end |
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
# Dendrogram drawing (Python recipe) from http://code.activestate.com/recipes/139422-dendrogram-drawing/ | |
def printDendrogram(T, sep=3): | |
"""Print dendrogram of a binary tree. Each tree node is represented by a length-2 tuple.""" | |
def isPair(T): | |
return type(T) == tuple and len(T) == 2 | |
def maxHeight(T): | |
if isPair(T): |
OlderNewer