Skip to content

Instantly share code, notes, and snippets.

View tzachz's full-sized avatar

Tzach Zohar tzachz

View GitHub Profile
@tzachz
tzachz / gist:5047526
Created February 27, 2013 12:17
Dropwizard upstart file example
author "Your Name"
description "upstart script for sample-dw-service"
# respawn the job up to 5 times within a 10 second period.
# If the job exceeds these values, it will be stopped and
# marked as failed.
respawn
respawn limit 5 10
# move to this service's working directory
@tzachz
tzachz / build.gradle
Created February 27, 2013 12:59
Dropwizard gradle build file
// fetch the relevant plugin code
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'eu.appsatori:gradle-fatjar-plugin:0.2-rc1'
classpath 'com.kenshoo:gradle-fpm:+'
}
}
import ch.qos.logback.classic.Logger;
import ch.qos.logback.classic.LoggerContext;
import ch.qos.logback.classic.spi.ILoggingEvent;
import com.yammer.dropwizard.ConfiguredBundle;
import com.yammer.dropwizard.config.Bootstrap;
import com.yammer.dropwizard.config.Environment;
import com.yammer.dropwizard.logging.AsyncAppender;
import me.moocar.logbackgelf.GelfAppender;
import org.slf4j.LoggerFactory;
@tzachz
tzachz / init.pp
Last active December 14, 2015 07:18
Dropwizard service puppet code
# sets up a dropwizard-based service packaged as debian
# requires: puppetlabs-apt, puppetlabs-stdlib
class sample-dw-service (
$version='latest', # you can pass a specified version, default is latest
$db_url='' # this is how you pass environment-specific configuration - in this case, a DB URL
) {
# refresh apt
notify { "refreshing apt":
notify => Class['apt::update'],
@tzachz
tzachz / LogbackVerifier.java
Last active September 16, 2018 11:43
logback verifier
package com.kenshoo.test;
import ch.qos.logback.classic.Level;
import ch.qos.logback.classic.Logger;
import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.classic.spi.IThrowableProxy;
import ch.qos.logback.core.Appender;
import org.junit.rules.TestRule;
import org.junit.runner.Description;
import org.junit.runners.model.Statement;
@tzachz
tzachz / MyTest.java
Created July 22, 2013 07:22
logback verifier usage
import ch.qos.logback.classic.Level;
import com.kenshoo.test.LogbackVerifier;
import org.junit.Rule;
import org.junit.Test;
public class MyTest {
@Rule
public LogbackVerifier logbackVerifier = new LogbackVerifier();
@tzachz
tzachz / OddMockitoStuffTest.java
Created September 24, 2013 15:31
Confusing Mockito behavior with overriding interfaces
package com.kenshoo.rtb.tools;
import org.junit.Test;
import static junit.framework.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
/**
* Created by IntelliJ IDEA.
@tzachz
tzachz / spiderman.java
Created December 18, 2013 17:39
Spiderman exersize
public class Spiderman {
public int spiderman(int n) {
// we're going to calculate these for each floor, starting from first floor:
int waysToGetToThisFloorByJumpingTwoFloors = 0; // there's no -1 floor, so there's no way to jump two floors and get to first floor
int waysToGetToThisFloorDirectlyFromPreviousFloor = 1; // there's one way to get from 0 to 1
int totalWaysToGetToThisFloor = 0;
for (int floor=1; floor <= n; floor++) {
// total ways = sum of ways ending with a big jump (2 floors) and ways ending with a small jump (1 floor):
@tzachz
tzachz / tzachz.zsh-theme
Created March 15, 2015 15:26
My oh-my-zshell theme
local ret_status="%(?:%{$fg_bold[green]%}➜ :%{$fg_bold[red]%}➜ %s)"
PROMPT='⌚ %{$fg_bold[red]%}%*%{$reset_color%} ${ret_status}%{$fg_bold[green]%}%p %{$fg[cyan]%}%c %{$fg_bold[blue]%}$(git_prompt_info)%{$fg_bold[blue]%} % %{$reset_color%}'
ZSH_THEME_GIT_PROMPT_PREFIX="git:(%{$fg[red]%}"
ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%}"
ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg[blue]%}) %{$fg[yellow]%}✗%{$reset_color%}"
ZSH_THEME_GIT_PROMPT_CLEAN="%{$fg[blue]%})"
@tzachz
tzachz / H2JDBIRule.java
Last active March 20, 2020 23:01
Dropwizard JDBI JUnit Rule using H2 by default - based on https://gist.github.com/yunspace/9a50e11dbd8661271220
import com.codahale.metrics.MetricRegistry;
import io.dropwizard.db.DataSourceFactory;
import io.dropwizard.jackson.Jackson;
import io.dropwizard.jdbi.DBIFactory;
import io.dropwizard.setup.Environment;
import liquibase.Liquibase;
import liquibase.database.jvm.JdbcConnection;
import liquibase.exception.LiquibaseException;
import liquibase.resource.ClassLoaderResourceAccessor;
import org.junit.rules.ExternalResource;