Skip to content

Instantly share code, notes, and snippets.

💻

Kohinoor Gupta kogupta

💻
Block or report user

Report or block kogupta

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@kogupta
kogupta / ByteBufIterator.java
Created Sep 19, 2018
Iterating over a jdk ByteBuffer
View ByteBufIterator.java
public final class ByteBufIterator {
public static void main(String[] args) {
ByteBuffer buffer = ByteBuffer.allocate(Integer.BYTES * 10);
for (int i = 0; i < 10; i++) buffer.putInt(i);
buffer.flip(); // dont forget to flip!!!
// read in groups of 3
// so 4 BBs, 3 of size 3 and 1 of 1
final int end = buffer.limit(), stride = 3 * Integer.BYTES;
@kogupta
kogupta / IntegerKeyTest2.java
Last active Sep 13, 2018
Range search in LmdbJava
View IntegerKeyTest2.java
import org.lmdbjava.*;
import java.io.File;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.file.Files;
import java.time.LocalDateTime;
import java.time.Month;
import java.time.ZoneOffset;
import java.util.Comparator;
@kogupta
kogupta / BinaryJsonHelper.java
Last active Jul 19, 2018
Exploration in binary json formats
View BinaryJsonHelper.java
import com.codahale.metrics.Histogram;
import com.codahale.metrics.SlidingTimeWindowArrayReservoir;
import com.codahale.metrics.Snapshot;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.databind.deser.std.FromStringDeserializer;
import com.fasterxml.jackson.databind.module.SimpleModule;
import com.fasterxml.jackson.dataformat.cbor.CBORFactory;
@kogupta
kogupta / ThrowingFunction.java
Created Jul 8, 2018
function throwing checked exception
View ThrowingFunction.java
@FunctionalInterface
public interface ThrowingFunction<I, O, T extends Throwable> {
O apply(I i) throws T;
}
@kogupta
kogupta / PojoGetters.java
Created Jun 14, 2018
bean introspection using lambda metafactory
View PojoGetters.java
import java.lang.invoke.LambdaMetafactory;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;
import java.lang.reflect.Method;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.function.Function;
/**
@kogupta
kogupta / DelegatingSocketFactory.java
Created Jun 13, 2018
A delegating javax.net.SocketFactory that enables Socket configuration
View DelegatingSocketFactory.java
import javax.net.SocketFactory;
import java.io.IOException;
import java.net.InetAddress;
import java.net.Socket;
import java.util.function.Consumer;
/**
* A {@link SocketFactory} that delegates calls. Sockets can be configured after creation by
* overriding {@link #configureSocket(java.net.Socket)}.
*/
@kogupta
kogupta / Apache Kafka on Ubuntu.txt
Last active Jun 12, 2018 — forked from SemenMartynov/Apache Kafka on Ubuntu.txt
kafka installation on ubuntu 16.04
View Apache Kafka on Ubuntu.txt
Install and configure Apache Kafka on Ubuntu 16.04
1. Install Java (JDK8)::
Add the repository
$ sudo add-apt-repository -y ppa:webupd8team/java
Update the metadata of the new repository and install JDK
@kogupta
kogupta / UncompressingFileHandler.java
Created Jun 1, 2018
Created this as a template for "async" decompressing - check http://www.cowtowncoder.com/blog/archives/2012/05/entry_475.html for more details
View UncompressingFileHandler.java
import com.ning.compress.DataHandler;
import com.ning.compress.UncompressorOutputStream;
import com.ning.compress.gzip.GZIPUncompressor;
import com.ning.compress.lzf.LZFUncompressor;
import io.netty.handler.codec.http.HttpHeaders;
import org.asynchttpclient.AsyncHandler;
import org.asynchttpclient.HttpResponseBodyPart;
import org.asynchttpclient.HttpResponseStatus;
import java.io.File;
View Advanced-FP-with-Scala.md

Advanced Functional Programming with Scala - Notes

Copyright © 2017 Fantasyland Institute of Learning. All rights reserved.

1. Mastering Functions

A function is a mapping from one set, called a domain, to another set, called the codomain. A function associates every element in the domain with exactly one element in the codomain. In Scala, both domain and codomain are types.

val square : Int => Int = x => x * x
@kogupta
kogupta / AliceInAggregatorLand.scala
Created Mar 8, 2017 — forked from johnynek/AliceInAggregatorLand.scala
A REPL Example of using Aggregators in scala
View AliceInAggregatorLand.scala
/**
* To get started:
* git clone https://github.com/twitter/algebird
* cd algebird
* ./sbt algebird-core/console
*/
/**
* Let's get some data. Here is Alice in Wonderland, line by line
*/
You can’t perform that action at this time.