Skip to content

Instantly share code, notes, and snippets.

View babanin's full-sized avatar

Ivan Babanin babanin

View GitHub Profile
@babanin
babanin / Towards member patterns.md
Last active February 3, 2024 09:48
Towards member patterns

Document copied from here. Authored by Brian Goetz.


Towards member patterns

Time to check in on where things are in the bigger picture of patterns as class members. Note: while this document may have illustrative examples, you should

@babanin
babanin / ForBenchmarks.groovy
Last active September 3, 2017 18:48
Benchmarks different types of for-cycle in Groovy 2.4.7
package ib.groovy
import org.openjdk.jmh.annotations.Benchmark
import org.openjdk.jmh.annotations.Fork
import org.openjdk.jmh.annotations.Measurement
import org.openjdk.jmh.annotations.OutputTimeUnit
import org.openjdk.jmh.annotations.Scope
import org.openjdk.jmh.annotations.Setup
import org.openjdk.jmh.annotations.State
import org.openjdk.jmh.annotations.Warmup
import java.io.IOException;
import java.nio.file.DirectoryStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
<g:select id="type" name="type" from="${['All'] + types}" value="${selectedType}" />
// Compile with "-mavx2 -std=c99 -flax-vector-conversions -O3"
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
#include <immintrin.h>
#include <time.h>
#include <sys/time.h>
#define TEST_ITER 10000
package org.openjdk;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
import org.openjdk.jmh.annotations.Fork;
import org.openjdk.jmh.annotations.Measurement;
import org.openjdk.jmh.annotations.Mode;
import org.openjdk.jmh.annotations.OutputTimeUnit;
import org.openjdk.jmh.annotations.Param;
import org.openjdk.jmh.annotations.Scope;
@babanin
babanin / jetty-web.xml
Created November 29, 2014 20:25
Jetty Virtualhosts
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure.dtd">
<Configure class="org.eclipse.jetty.webapp.WebAppContext">
<Set name="contextPath">/</Set>
<Set name="virtualHosts">
<Array type="java.lang.String">
<Item>${YOUR_HOST_NAME}</Item>
<Item>${YOUR_HOST_NAME_2}</Item>
</Array>
import java.security.MessageDigest
import scala.io.Source
/**
* Created by Ivan Babanin (babanin@gmail.com) on 4/6/2014
*/
object MD5File {
def hash(filePath: String): String =
MessageDigest.getInstance("MD5").digest(Source.fromFile(filePath).map(_.toByte).toArray)
.map( 0xFF & _ )
Field value = Integer.class.getDeclaredField("value");
value.setAccessible(true);
value.set((Integer) 127, 0);
private static class LongCache {
private LongCache(){}
static final Long cache[] = new Long[-(-128) + 127 + 1];
static {
for(int i = 0; i < cache.length; i++)
cache[i] = new Long(i - 128);
}
}