Skip to content

Instantly share code, notes, and snippets.

View sulmansarwar's full-sized avatar

Muhammad Sarwar sulmansarwar

  • University of Melbourne
  • Melbourne, Australia
View GitHub Profile
Nested Fields
---------------------
Following is what is meant by nested_fields. This will break. Index will not be created as nested_fields are greater than 2.
"mappings": {
"properties": {
"user": {
"type": "nested"
},
"address":{
"type": "nested"
@sulmansarwar
sulmansarwar / java.util.List.pagination
Created February 9, 2017 05:57
1- Retrieve data using JDBC 2- Populate java.util.List from java.sql.ResultSet 3- Paginate java.util.List
String query = "SELECT DISTINCT article_id from articles WHERE article_summary IS NULL";
SqlConnection connection = new SqlConnection();
SqlCommand command = new SqlCommand(query, connection.getDatabaseConnection());
ResultSet resultSet = command.executeSelect();
int counter = 1;
List idList = new ArrayList();
//populate List::idList
while (resultSet.next()) {
idList.add(resultSet.getInt("article_id"));
@sulmansarwar
sulmansarwar / gist:6820936
Created October 4, 2013 04:29
Iterate over the contents of a Map..
Iterator iter = myMap.entrySet().iterator();
while (iter.hasNext()) {
Map.Entry mapEntry = (Map.Entry) iter.next();
System.out.println(mapEntry.getKey() + " : " + mapEntry.getValue());
}
@sulmansarwar
sulmansarwar / unzep.java
Last active December 20, 2015 06:29
unzip the zipArchive. Takes the zipfile location and output directory.
/**
* Takes the zipfile location and output directory and returns the reference to output folder
* @param zfile
* @param outDir
* @throws IOException
*
*/
public File unzep(String zfile, String outDir) throws IOException
{
@sulmansarwar
sulmansarwar / gist:5352275
Created April 10, 2013 06:32
read from inputstream and store in file. Java.
/**
* read from input stream and store in file.
*/
InputStream in = .....
File file = File.createTempFile(filename,".dat");
FileOutputStream fos = new FileOutputStream(file,true);
byte[] b = new byte[4096];
while(in.read(b, 0, 4096) != -1)
{
fos.write(b,0,4096);