Skip to content

Instantly share code, notes, and snippets.

@iamtrk
iamtrk / ConnectionPool.java
Last active Aug 29, 2015
JDBC Connection pool implemented in C3PO.
View ConnectionPool.java
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");
View README.md
@iamtrk
iamtrk / JAVA Code
Last active Dec 25, 2015
bloomreach Wine selection problem Solution
View JAVA Code
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 Jul 23, 2013
Prime numbers code written in Node.js
View primes.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 Dec 20, 2015
Simple wiring of mongoose, Node.js and express
View app.js
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 Jul 16, 2013
Mongo DB info queries
View MongoDB
db.isMaster().maxBsonObjectSize() -- > upper limit on the size of a document
@iamtrk
iamtrk / query.txt
Last active Dec 19, 2015
M101J from 10Gen Education -> Final exam
View query.txt
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 Dec 19, 2015
A Simple chat server implemented in Node.js
View chat.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){
You can’t perform that action at this time.