Skip to content

Instantly share code, notes, and snippets.

View mh-github's full-sized avatar

Mahboob Hussain mh-github

View GitHub Profile
@mh-github
mh-github / Mongo_Insert_Collection.java
Created July 13, 2014 08:56
Inserting a million records into MongoDB
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
@mh-github
mh-github / Mongo_Retrieve_Collection.java
Created July 13, 2014 09:04
Fetch records from MongoDB and print them
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;
@mh-github
mh-github / MySQL_Insert.java
Created July 13, 2014 09:06
Insert 20,000 records into MySQL
//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
@mh-github
mh-github / MySQL_Fetch.java
Created July 13, 2014 09:08
Fetch records from MySQL and print them
//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
#!/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
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
@mh-github
mh-github / sort-words-with-tuples.py
Created October 26, 2014 09:08
sorting words with Python (from pythonlearn.com - http://www.pythonlearn.com/html-008/cfbook011.html
#! /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)
@mh-github
mh-github / sort-words-with-structs.rb
Created October 26, 2014 09:10
sorting words with Ruby using struct
#! /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!
@mh-github
mh-github / mh_util.rb
Created October 26, 2014 09:14
Ruby utility module to simulate a Python tuple to be used for sorting
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
@mh-github
mh-github / pdg.py
Created February 21, 2015 19:32
# 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): h = max(maxHeight(T[0]), maxHeig…
# 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):