Skip to content

Instantly share code, notes, and snippets.

class NullOnEmptyConverterFactory : Converter.Factory() {
override fun responseBodyConverter(type: Type, annotations: Array<Annotation>, retrofit: Retrofit): Converter<ResponseBody, *> {
val delegate: Converter<ResponseBody, Any> = retrofit.nextResponseBodyConverter(this, type, annotations)
return Converter { body -> if (body.contentLength() == 0L) null else delegate.convert(body) }
}
}
@rajivrnair
rajivrnair / all_in_one.sh
Last active April 1, 2018 05:57
simple journal with vi
# Create a folder and write a simple script to open a file.
$> mkdir /Journal && cd /Journal && touch writer.sh && chmod u+rwx writer.sh`
# Here's `writer.sh`
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#!/bin/zsh
# create a folder with today's date if it does not exist
folder=`date +%Y_%m_%d`
mkdir -p $folder
@rajivrnair
rajivrnair / Ping.java
Created November 14, 2017 04:11
Testing the Form Post in Spring Boot/MVC
public class Ping {
private String message = "";
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
@rajivrnair
rajivrnair / egghead_YouTube_downloader.py
Last active August 29, 2015 14:22 — forked from SamuelMarks/egghead_YouTube_downloader.py
Added egghead videos through to 59.
# Original script at https://gist.github.com/SamuelMarks/7961833
# This one has a few more videos, though it might be a bit out of order.
"""
Simple algorithm to download all the egghead.io videos in highest-quality from YouTube.
Run from the directory you want the videos to appear. Renames them so that they have the video number + omit the repetitive "Egghead.io - AngularJS -" text.
Installing dependency:
$ pip install git+https://github.com/NFicano/pytube#egg=pytube
"""
@rajivrnair
rajivrnair / ThreadInformation.java
Created March 30, 2015 05:07
Print information about currently running threads
private static void printThreadInformation() {
ThreadGroup threadGroup = Thread.currentThread().getThreadGroup();
ThreadGroup parent;
while ((parent = threadGroup.getParent()) != null) {
threadGroup = parent;
Thread[] threads = new Thread[threadGroup.activeCount()];
threadGroup.enumerate(threads);
for (Thread thread : threads) {
String identity = thread.getThreadGroup().getName() + "::" + thread.getName();
System.out.println(identity + ", Priority: " + thread.getPriority() + ", Daemon: " + thread.isDaemon());
@rajivrnair
rajivrnair / Entity.java
Created February 7, 2015 06:22
Custom Hibernate UUID Generator
// Before
@Id
@Column(name = "entity_id")
@GeneratedValue(generator = "system-uuid")
@GenericGenerator(name = "system-uuid", strategy = "uuid2")
private String entityId;
// After
@Id
@Column(name = "entity_id")