Skip to content

Instantly share code, notes, and snippets.

View arialdomartini's full-sized avatar

Arialdo Martini arialdomartini

View GitHub Profile
@arialdomartini
arialdomartini / gist:10572039
Last active August 29, 2015 13:59
// Can you spot the memory leak?
public class Stack {
private Object[] elements;
private int size = 0;
private static final int DEFAULT_INITIAL_CAPACITY = 16;
public Stack() {
elements = new Object[DEFAULT_INITIAL_CAPACITY];
}
public void push(Object e) {
public Context SetMailTemplate(string template, string mailCategory)
{
IConfigurationSource configSource = ConfigurationSourceFactory.Create();
var logSettings = configSource.GetSection(LoggingSettings.SectionName) as LoggingSettings;
if (logSettings == null) return this;
var categorySource = logSettings.TraceSources.SingleOrDefault(t => t.Name.Equals(mailCategory));
if (categorySource == null) return this;
var emailListener = (from tRef in categorySource.TraceListeners
namespace Cart.UnitTests
{
       [TestFixture]
       public class MyTest
       {
              [Test]
              public void test_that_1_should_be_equal_to_2_or_sticazzi()
              {
                     Assert.That(1, Is.EqualTo(2).OrStiCazzi());
defun factorial(n)
if = n 1
1
n factorial(- n 1)
@arialdomartini
arialdomartini / gist:0a99802e2e086ea842b0
Created June 30, 2014 08:38
Rational in C#, extending + operator
public static Rational operator +(Rational i, Rational j)
{
return new Rational(i.numerator * j.denominator + i.denominator * j.numerator, i.denominator + j.denominator);
}
@arialdomartini
arialdomartini / gist:0efbdb853b5edd647ceb
Created July 16, 2014 20:43
Can you spot the memory leak?
iù semplice
public class Stack {
private Object[] elements;
private int size = 0;
private static final int DEFAULT_INITIAL_CAPACITY = 16;
public Stack() {
elements = new Object[DEFAULT_INITIAL_CAPACITY];
}
public void push(Object e) {
@arialdomartini
arialdomartini / docker-test.sh
Last active August 29, 2015 14:04
A strange behaviour of Docker's volumes
echo "A Volume not surviving the last container using it"
docker run -t -i --rm --name=foo -v /var/barbaz ubuntu:14.10 touch /var/barbaz/i-will-die
docker run -t -i --rm --name=foo -v /var/barbaz ubuntu:14.10 ls -l /var/barbaz/
echo "Volume content survives the last container using it"
mkdir localdirectory
docker run -t -i --rm --name=foo -v $PWD/localdirectory:/var/barbaz ubuntu:14.10 touch /var/barbaz/i-will-not-die
rm -fr localdirectory
mkdir localdirectory
docker run -t -i --rm --name=foo -v $PWD/localdirectory:/var/barbaz ubuntu:14.10 ls -l /var/barbaz/
@arialdomartini
arialdomartini / gist:a584ec038c89217b31e7
Last active August 29, 2015 14:05
Range Minimum Query with Segment Trees-like datastructure
object Sample {
def parts(numbers: Vector[Any]): (Vector[Any], Vector[Any]) =
numbers.splitAt(numbers.length / 2)
def buildTree(numbers: Vector[Any]): Vector[Any] =
numbers.length match {
case 1 => numbers
case _ => Vector(buildTree(parts(numbers)._1), buildTree(parts(numbers)._2))
}
foo_result = shell('/usr/bin/foo', ignore_errors = True)
if foo_result == 5:
shell('/usr/bin/bar')
;; With Ansible DSL
tasks:
- shell: /usr/bin/foo
register: foo_result
- hosts: web_servers
tasks:
- shell: /usr/bin/foo
register: foo_result
ignore_errors: True