Skip to content

Instantly share code, notes, and snippets.

View ajjain's full-sized avatar

Abhishek Jain ajjain

  • Impetus Technologies Inc.
  • Indore
View GitHub Profile
@ajjain
ajjain / subsitution.scala
Created December 4, 2013 14:17
Substitution principle on classes in Scala. A three stepped process: 1) Constructor parameter substitution 2) Actual parameter reference substitution 3) Actual variable substitution
package learn.scala
/**
* This tutorial represents how subsitution principle works in Scala.
*/
object SubsitutionPrincipleNClasses {
println("Welcome to the Scala worksheet") //> Welcome to the Scala worksheet
class Rational(x: Int, y: Int){
def numer = x;
@ajjain
ajjain / JsonizedObject.java
Last active December 30, 2015 08:29
JsonizedObject is a Activiti's DeserializedObject which flushes deserialized objects in form of JSON. To understand the user refer discussion at http://forums.activiti.org/content/custom-serialization-complex-process-variable
import java.util.Arrays;
import org.activiti.engine.impl.persistence.entity.VariableInstanceEntity;
import org.activiti.engine.impl.variable.DeserializedObject;
public class JsonizedObject extends DeserializedObject {
Object deserializedObject;
byte[] originalBytes;
VariableInstanceEntity variableInstanceEntity;
@ajjain
ajjain / JsonVariableType.java
Created December 5, 2013 10:14
Represents JSON variable type in Activiti. This supports serializing process variables as JSON strings as byte arrays. JSON serialization/deserialization uses Jackson APIs to transform.
import org.activiti.engine.ActivitiException;
import org.activiti.engine.impl.context.Context;
import org.activiti.engine.impl.persistence.entity.VariableInstanceEntity;
import org.activiti.engine.impl.variable.ByteArrayType;
import org.activiti.engine.impl.variable.ValueFields;
import org.codehaus.jackson.map.ObjectMapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
@ajjain
ajjain / JsonType.java
Created December 5, 2013 10:17
Markup interface which represents a process variable can be persisted in Activiti's hydration database as JSON.
/**
* @author ajjain
*
* Markup interface which represents a process variable can be persisted
* in Activiti's hydration database as JSON.
*
*/
public interface JsonType {
}
@ajjain
ajjain / Polymorphism.scala
Created December 18, 2013 03:59
Example for understanding polymorphism in Scala.
package learn.scala.polymorphism
trait List[T] {
def isEmpty: Boolean
def head: T
def tail: List[T]
}
class Nil[T] extends List[T] {
def isEmpty: Boolean = true
@ajjain
ajjain / book.sql
Last active August 29, 2015 14:03
PostgreSQL+MyBatis+Insert+Autogenerated ID
CREATE TABLE BOOK (
ID SERIAL PRIMARY KEY,
NAME VARCHAR (50) UNIQUE NOT NULL,
TITLE VARCHAR (100),
DESCRIPTION VARCHAR (200)
);
@ajjain
ajjain / BizService.java
Created June 26, 2014 04:31
MyBatis+Managed+Transaction
public class BizService {
private SqlSessionFactory sqlSessionFactory;
/**
* Initalize the
*
* @param config the config
*/
private void init(QueryEngineConfiguration config) {
InputStream inputStream;
@ajjain
ajjain / vector.R
Created September 8, 2015 12:23
Understanding vectors in R
# C stands for CONCAT and helps in creating vector
x <- c(1,2,3)
y1 <- c(T, F, T, F)
y2 <- c(TRUE, FALSE)
# sequence of numbers
z <- 1:100
# complex numbers
a <- c(1+2i, 3+4i)
@ajjain
ajjain / factor.R
Created September 8, 2015 12:24
Understanding Factors in R
# factor for categorical data can be ordered or unordered
# eg. gender (M, F), size (S, M, L, XL, XXL)
# (M, F) or (S, M, L, XL, XXL) are called levels
x <- factor(c("S", "M", "L", "XL", "XXL", "S", "XL", "XXL"))
# represent the class of x which is factor
class(x)
# strips out the class and shows the factors represents as integer
@ajjain
ajjain / na_nan.R
Created September 8, 2015 12:25
NA & NaN in R
x <- c(1,2,NA,3)
is.na(x)
is.nan(x)
y <- c(1,2,NaN,3)
is.na(y)
is.nan(y)
z <- c(1,2,NaN,NA)
is.na(z)