Skip to content

Instantly share code, notes, and snippets.

View kogupta's full-sized avatar
💻
Yak Shaving

Kohinoor Gupta kogupta

💻
Yak Shaving
View GitHub Profile
@kogupta
kogupta / AliceInAggregatorLand.scala
Created March 8, 2017 10:59 — forked from johnynek/AliceInAggregatorLand.scala
A REPL Example of using Aggregators in 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
*/

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 / UncompressingFileHandler.java
Created June 1, 2018 09:45
Created this as a template for "async" decompressing - check http://www.cowtowncoder.com/blog/archives/2012/05/entry_475.html for more details
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;
@kogupta
kogupta / Apache Kafka on Ubuntu.txt
Last active June 20, 2019 09:14 — forked from SemenMartynov/Apache Kafka on Ubuntu.txt
kafka installation on ubuntu 16.04
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 / DelegatingSocketFactory.java
Created June 13, 2018 16:46
A delegating javax.net.SocketFactory that enables Socket configuration
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 / PojoGetters.java
Created June 14, 2018 04:58
bean introspection using lambda metafactory
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 / ThrowingFunction.java
Created July 8, 2018 15:57
function throwing checked exception
@FunctionalInterface
public interface ThrowingFunction<I, O, T extends Throwable> {
O apply(I i) throws T;
}
@kogupta
kogupta / BinaryJsonHelper.java
Last active July 19, 2018 08:22
Exploration in binary json formats
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 / IntegerKeyTest2.java
Last active September 13, 2018 13:31
Range search in LmdbJava
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 / ByteBufIterator.java
Created September 19, 2018 14:13
Iterating over a jdk ByteBuffer
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;