Skip to content

Instantly share code, notes, and snippets.

VERSION = 0;
@Override
public void writeExternal(ObjectOutput out) throws IOException {
out.writeInt(VERSION);
out.writeInt(number);
out.writeObject(name);
}
@Override
public void readExternal(ObjectInput _in) throws IOException, ClassNotFoundException {
ObjectInputWrapper in = new ObjectInputWrapper(_in);
@pmanvi
pmanvi / ObjecrInputDecorator.java
Created September 25, 2011 17:04
Class used for implementing the forward compatability of serialized java objects
// A wrapper classes delegating the execution of method into the container that can handle forward compatibility
// This class implements all the methods ObjectInput & moves the cursor
// whenever it sees skippable data from future versions
// WARNING : Currently for POC only 2 methods are implemented
class ObjectInputDecorator{
ObjectInput input;
ObjectInputDecorator(ObjectInput input){
this.input=input;
}
@pmanvi
pmanvi / ObjectInputReaderTemplate.java
Created September 30, 2011 14:15
ObjectInputReaderTemplate - A generic class supporting all the data types
// Follows the template pattern to provide container for ObjectInput
static abstract class ObjectInputReaderTemplate<T> {
private ObjectInput objectInput;
public ObjectInputReaderTemplate(final ObjectInput objectInput){
this.objectInput=objectInput;
}
public final T execute() throws IOException {
T t = get();
@pmanvi
pmanvi / Eclipse_equals_hashcode
Created February 9, 2012 04:56
Eclipse_equals_hashcode
// IntelliJ generated
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof ElementNameKey)) return false;
ElementNameKey that = (ElementNameKey) o;
if (field1 != that.field1) return false;
if (field2 != that.field2) return false;
@pmanvi
pmanvi / enron_email_to_es_exporter.py
Last active August 29, 2015 14:07
Exporting enron email to ES friendly JSONs
__author__ = 'pmanvi'
import os
import sys
from email.parser import Parser
from elasticsearch import Elasticsearch
from datetime import date
import traceback
p = Parser()
@pmanvi
pmanvi / enron_email_searcher.py
Last active August 29, 2015 14:07
Searching enron mails with ES
__author__ = 'pmanvi'
from elasticsearch import Elasticsearch
from elasticsearch_dsl import Search, Q
es = Elasticsearch([{'host': 'localhost'},{'port': 9200}])
count = Search(using=es).index("enron-email").count()
print(count)
@pmanvi
pmanvi / enron_email_size_aggregator.json
Created October 18, 2014 17:28
enron_email_size_aggregator ES query
{
"aggs": {
"enron_size_ranges": {
"range": {
"field": "content_size_in_bytes",
"ranges": [
{
"key": "0KB to 1KB",
"from": 0,
"to": 1024
@pmanvi
pmanvi / aggregate_results.json
Created October 18, 2014 17:54
enron_size by count
buckets: [
{
key: 0KB to 1KB
from: 0
from_as_string: 0.0
to: 1024
to_as_string: 1024.0
doc_count: 124181
}
{
@pmanvi
pmanvi / test.java
Created August 2, 2015 17:05
java-8-blog-even-numbers
List<Integer> numbers = asList(1, 2, 3, 4, 5);
List<Integer> even_numbers = numbers.stream().filter(num -> num % 2 == 0).collect(Collectors.toList());
System.out.println(even_numbers)
// will print [2,4]
@pmanvi
pmanvi / dateStringToDate
Created December 22, 2015 17:57
utility to extract date from unknown format
public static LocalDate getLocalDateWithUnknownFormat(String dString) {
LocalDate[] localDate = {null};
Arrays.asList("yyyy-MM-dd'T'HH:mm:ss'Z'", "yyyy-MM-dd'T'HH:mm:ssZ",
"yyyy-MM-dd'T'HH:mm:ss", "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'",
"yyyy-MM-dd'T'HH:mm:ss.SSSZ", "yyyy-MM-dd HH:mm:ss",
"MM/dd/yyyy HH:mm:ss", "MM/dd/yyyy'T'HH:mm:ss.SSS'Z'",
"MM/dd/yyyy'T'HH:mm:ss.SSSZ", "MM/dd/yyyy'T'HH:mm:ss.SSS",
"MM/dd/yyyy'T'HH:mm:ssZ", "MM/dd/yyyy'T'HH:mm:ss",
"yyyy:MM:dd HH:mm:ss", "yyyyMMdd")
.stream().parallel().forEach(f-> {