Skip to content

Instantly share code, notes, and snippets.

View watsh-rajneesh's full-sized avatar
🎯
Focusing

Watsh Rajneesh watsh-rajneesh

🎯
Focusing
View GitHub Profile
@watsh-rajneesh
watsh-rajneesh / LRUCache.java
Created August 8, 2017 05:33
LRU Cache implementation with linked hash map.
package edu.sjsu.watsh.algos;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
/**
* Implement LRU cache using linked hash map.
*
for i in 1 2 3; do
docker-machine create \
-d virtualbox \
swarm-$i
done
eval $(docker-machine env swarm-1)
docker swarm init \
--advertise-addr $(docker-machine ip swarm-1)
@watsh-rajneesh
watsh-rajneesh / IntentElem.java
Created March 11, 2017 21:47
Wit.AI Java Integration
package edu.sjsu.amigo.mp.kafka;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
/**
* The intent object returned from the wit.ai service.
*
* {
"msg_id" : "5e89f3d9-93d1-4dfa-b128-73fda21974b3",
@watsh-rajneesh
watsh-rajneesh / Dockerfile
Created March 2, 2017 07:38
Dockerize Java Application
# Use this base image for JDK 8
# You can even use this image to set up maven and build from source the fat jar
# that you will execute below.
# See this for setting up maven - https://runnable.com/docker/java/dockerize-your-java-application
FROM sjsucohort6/oracle-java:8
MAINTAINER Watsh Rajneesh <watsh.rajneesh@sjsu.edu>
WORKDIR /slackbot
@watsh-rajneesh
watsh-rajneesh / HttpClient.java
Last active September 10, 2018 17:41
Unirest Java REST HTTP Client
package edu.sjsu.amigo.http.client;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.JsonNode;
import com.mashape.unirest.http.ObjectMapper;
import com.mashape.unirest.http.Unirest;
import com.mashape.unirest.http.exceptions.UnirestException;
import com.mashape.unirest.request.GetRequest;
@watsh-rajneesh
watsh-rajneesh / DockerTask.java
Last active March 2, 2017 07:19
Docker image execution in Java
package edu.sjsu.amigo.cp.docker;
import com.spotify.docker.client.DefaultDockerClient;
import com.spotify.docker.client.DockerClient;
import com.spotify.docker.client.LogStream;
import com.spotify.docker.client.exceptions.DockerException;
import com.spotify.docker.client.messages.ContainerConfig;
import com.spotify.docker.client.messages.ContainerCreation;
import com.spotify.docker.client.messages.RegistryAuth;
import edu.sjsu.amigo.cp.api.CommandExecutionException;
@watsh-rajneesh
watsh-rajneesh / ConsumerLoop.java
Last active March 2, 2017 07:14
Apache Kafka Consumer Example
/*
* Copyright (c) 2017 San Jose State University.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
@watsh-rajneesh
watsh-rajneesh / MessageProducer.java
Created March 2, 2017 07:08
Apache Kafka Message Producer
package edu.sjsu.amigo.mp.kafka;
import org.apache.kafka.clients.producer.KafkaProducer;
import org.apache.kafka.clients.producer.Producer;
import org.apache.kafka.clients.producer.ProducerConfig;
import org.apache.kafka.clients.producer.ProducerRecord;
import java.io.Closeable;
import java.util.Properties;
@watsh-rajneesh
watsh-rajneesh / MessageListener.java
Last active March 2, 2017 07:31
SlackBot in Java
package edu.sjsu.amigo.slackbot;
import com.ullink.slack.simpleslackapi.SlackChannel;
import com.ullink.slack.simpleslackapi.SlackSession;
import com.ullink.slack.simpleslackapi.SlackUser;
import com.ullink.slack.simpleslackapi.events.SlackMessagePosted;
import com.ullink.slack.simpleslackapi.impl.SlackSessionFactory;
import com.ullink.slack.simpleslackapi.listeners.SlackMessagePostedListener;
import edu.sjsu.amigo.mp.kafka.Message;
import edu.sjsu.amigo.mp.kafka.MessageProducer;
Verifying that "rwatsh.id" is my Blockstack ID. https://onename.com/rwatsh