Skip to content

Instantly share code, notes, and snippets.

@iamtrk
iamtrk / ConnectionPool.java
Last active August 29, 2015 13:59
JDBC Connection pool implemented in C3PO.
public class ConnectionPool {
private ComboPooledDataSource cpds;
private static ConnectionPool datasource;
private ConnectionPool() throws IOException, SQLException ,PropertyVetoException{
cpds = new ComboPooledDataSource();
cpds.setJdbcUrl("jdbc:mysql://localhost:3306/data_base");
@iamtrk
iamtrk / README.md
Created October 14, 2013 06:41 — forked from nikcub/README.md
@iamtrk
iamtrk / JAVA Code
Last active December 25, 2015 01:39
bloomreach Wine selection problem Solution
import java.io.BufferedReader;
import java.io.FileReader;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Hashtable;
@iamtrk
iamtrk / primes.js
Created July 23, 2013 06:32
Prime numbers code written in Node.js
var fs = require("fs");
function getPrimes(max) {
var sieve = [], i, j, primes = [];
for (i = 2; i <= max; ++i) {
if (!sieve[i]) {
// i has not been marked -- it is prime
primes.push(parseInt(i));
for (j = i << 1; j <= max; j += i) {
sieve[j] = true;
@iamtrk
iamtrk / app.js
Last active December 20, 2015 02:19
Simple wiring of mongoose, Node.js and express
var express = require('express')
, http = require('http')
, foodlist = require('./foodlist');
var app = express();
app.configure(function(){
app.set('port', process.env.PORT || 3000);
app.use(express.bodyParser());
});
@iamtrk
iamtrk / MongoDB
Created July 16, 2013 07:27
Mongo DB info queries
db.isMaster().maxBsonObjectSize() -- > upper limit on the size of a document
@iamtrk
iamtrk / query.txt
Last active December 19, 2015 19:29
M101J from 10Gen Education -> Final exam
Final: Question 2
Please use the Enron dataset you imported for the previous problem. For this question you will use the aggregation framework to figure out pairs of people that tend to communicate a lot(list Top5 pairs).
Query :
db.messages.aggregate([{$unwind:"$headers.To"},{$group:{_id:{from:"$headers.From",to:"$headers.To"},numbe:{$sum:1}}},{$sort:{numbe:-1}},{$limit:5}])
@iamtrk
iamtrk / chat.js
Last active December 19, 2015 19:28
A Simple chat server implemented in Node.js
//fs module is required for writing conversations and host info logging.
var net = require('net');
var fs = require('fs');
var sockets = [];
var people = {};
// Hosts are saved in hosts file and conversation is saved in conversation file.
var hosts = 'hosts.txt';
var conv = 'conversation.txt';
var server = net.createServer(function(socket){