Skip to content

Instantly share code, notes, and snippets.

View hascode's full-sized avatar

Micha Kops hascode

View GitHub Profile
@hascode
hascode / WeakHashmapExample.java
Created April 24, 2018 10:13
Java - WeakReference and WeakHashMap examples
package net.seibertmedia;
import java.util.Map;
import java.util.WeakHashMap;
import java.util.concurrent.TimeUnit;
public class WeakHashmapExample {
public static void main(String[] args) throws InterruptedException {
Map<Person, String> map = new WeakHashMap<Person, String>();
Person p1 = new Person("Jeff1");
@hascode
hascode / Main.java
Created July 5, 2017 07:40
Java Externalizable Example
package com.hascode.sample;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.time.ZonedDateTime;
public class Main {

Overview of my Blog Articles at hascode.com

Introduction

@hascode
hascode / CustomExceptionMapper.java
Created February 27, 2015 13:07
Example JAX-RS Exception Mapper
@Provider
public class CustomExceptionMapper implements ExceptionMapper<CustomException> {
@Override
public Response toResponse(final CustomException exception) {
return Response.status(Status.BAD_REQUEST).entity(exception).type(MediaType.APPLICATION_JSON).build();
}
}
@hascode
hascode / pom.xml
Created January 2, 2015 12:12
Hamcrest + JUnit 4.12
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.hascode.tutorial</groupId>
<artifactId>hamcrest-tutorial</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-all</artifactId>
@hascode
hascode / memoization.js
Created October 15, 2014 07:36
JavaScript Memoization
var fib = function(n){
return (n<2) ? 1 : fib(n-1) + fib(n-2);
}
var calc = function(numbers){
var self = this;
numbers.forEach(function(n){
if(!self.cache){
self.cache = {};
}
@hascode
hascode / curry.js
Last active August 29, 2015 14:07
Javascript Currying
Function.prototype.curry = function(){
var func = this, args = Array.prototype.slice.call(arguments);
return function(){
return func.apply(this, args.concat(Array.prototype.slice.call(arguments)));
}
};
var add = function(a,b){
return a+b;
}
@hascode
hascode / pom.xml
Created August 22, 2014 06:14
Referencing information generated by atlas-create-home-zip
<plugin>
<groupId>com.atlassian.maven.plugins</groupId>
<artifactId>maven-jira-plugin</artifactId>
<version>${amps.version}</version>
<extensions>true</extensions>
<configuration>
[...]
<productDataPath>src/test/xml/generated-test-resources.zip</productDataPath>
</configuration>
@hascode
hascode / pom.xml
Created March 25, 2014 09:56
Maven Plugin Setup for phantomJS + Jasemine
<plugin>
<groupId>com.github.klieber</groupId>
<artifactId>phantomjs-maven-plugin</artifactId>
<version>0.2.1</version>
<executions>
<execution>
<goals>
<goal>install</goal>
</goals>
</execution>
@hascode
hascode / gist:8349080
Last active January 2, 2016 19:18
Maven Surefire/Failsave examples
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.16</version>
<configuration>
<excludes>
<exclude>it/**</exclude>
</excludes>