Skip to content

Instantly share code, notes, and snippets.

@bivas
bivas / docker-sh.sh
Created July 27, 2014 08:19
Place this in /etc/profile.d/ folder and you can open a shell in a running Docker container
#!/bin/bash
function docker-sh() {
local __PID=""
__PID=$(docker inspect --format "{{.State.Pid}}" $1)
local __EXIT=$?
if [ $__EXIT -eq 0 ]; then
nsenter --target $__PID --mount --uts --ipc --net --pid
fi
}
@bivas
bivas / Vagrantfile
Last active October 14, 2016 14:16
Vagrant file (CentOS65 based) with the ability to pass environment variables to your provisionening scripts
# -*- mode: ruby -*-
# vi: set ft=ruby :
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "centos65"
config.vm.box_url = "http://puppet-vagrant-boxes.puppetlabs.com/centos-65-x64-virtualbox-nocm.box"
config.vm.define "<your-vm-name>" do |vmname|
@bivas
bivas / ByteUnit.java
Created December 1, 2013 22:28
Helpful utility for transforming size units from/to. - Inspired by java.util.concurrent.TimeUnit Official definitions from http://en.wikipedia.org/wiki/Binary_prefix
package iam.bivas.commons.bytes;
public enum ByteUnit {
BYTES {
@Override public double convert(double amount, ByteUnit unit) { return unit.toBytes(amount); }
@Override public double toBytes(double amount) { return amount; }
@Override public double toKilobytes(double amount) { return amount / DK; }
@Override public double toKibibytes(double amount) { return amount / BK; }
@Override public double toMegabytes(double amount) { return toKilobytes(amount) / DK; }
@bivas
bivas / log.lua
Last active December 17, 2015 11:49
Lua logger module (inspired by log4j)
--[[
Lua log module
@author Eliran Bivas
Usage:
local log = require "log"
log.debug("some debug")
log.info("some info")
@bivas
bivas / DistanceUnit.java
Created February 24, 2013 13:01
Helpful utility for transforming distance units from/to. - Inspired by java.util.concurrent.TimeUnit
package iam.bivas.commons.distance;
public enum DistanceUnit {
FEETS {
@Override
public double toMeters(final double units) {
return units / METER_TO_FEET;
}
@Override
@bivas
bivas / DurationPattern.java
Created March 24, 2012 20:26
Human Readable Duration
long now = System.currentTimeMillis();
doSomeLongTask();
long duration = System.currentTimeMillis() - now;
@bivas
bivas / ComplexNumber.java
Created September 11, 2011 15:25
Adapter Pattern
package com.example.adapter;
public interface ComplexNumber {
double real();
double imaginary();
}
@bivas
bivas / FooBarZoo.java
Created September 7, 2011 10:57
Builder Pattern
public interface Foo {
Collection<Bar> getBars();
Zoo getZoo();
}
public interface Bar {}
public interface Zoo {}
@bivas
bivas / NotNullCacheEventListener.java
Created September 6, 2011 07:09
EhCache event listener for preventing caching of null values in data store
package com.example.cache;
import net.sf.ehcache.CacheException;
import net.sf.ehcache.Ehcache;
import net.sf.ehcache.Element;
import net.sf.ehcache.event.CacheEventListener;
final class NotNullCacheEventListener implements CacheEventListener {
public static final CacheEventListener INSTANCE = new NotNullCacheEventListener();
@bivas
bivas / AbstractFactory.java
Created August 30, 2011 12:39
Factory Pattern
package com.example.factory;
public interface CarFactory {
Car createCar();
}
public FordCarFactory implements CarFactory {
@Override
public Car createCar() {