Skip to content

Instantly share code, notes, and snippets.

Avatar

Tagir Valeev amaembo

View GitHub Profile
@amaembo
amaembo / Search.java
Created Sep 21, 2020
Comparison of linear and binary search in Java
View Search.java
package com.com.example;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.BenchmarkMode;
import org.openjdk.jmh.annotations.CompilerControl;
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;
@amaembo
amaembo / MyClass.java
Created Sep 5, 2020
Multi-dimensional arrays
View MyClass.java
import java.lang.annotation.*;
import java.lang.reflect.*;
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE_USE)
@interface TA {
int value();
}
public class MyClass {
View PairMapSample.java
import java.util.Arrays;
import java.util.List;
import java.util.Spliterator;
import java.util.Spliterators;
import java.util.function.BiFunction;
import java.util.function.Consumer;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;
public class PairMapSample {
View MyEnum.java
import java.lang.annotation.*;
import java.lang.reflect.*;
import java.util.Arrays;
enum MyEnum {
A(0.0, 0, "");
MyEnum(@Foo("double annotated") double d,
int i,
@Foo("string annotated") String s) { }
@amaembo
amaembo / Test.java
Created May 19, 2020
Reified generics in Java
View Test.java
import java.util.*;
@SuppressWarnings("ALL")
class Test {
static class ReifiedList<T> extends AbstractList<T> {
private final List<T> delegate = new ArrayList<>();
private final Class<?> type;
@SafeVarargs
ReifiedList(@Deprecated T... unused) {
View AbstractEnumConverter.java
import java.util.concurrent.TimeUnit;
public class AbstractEnumConverter<T extends Enum<T>> {
private final Class<T> enumClass;
private final T[] values;
protected AbstractEnumConverter(Class<T> enumClass) {
assert enumClass.isEnum();
this.enumClass = enumClass;
this.values = enumClass.getEnumConstants();
@amaembo
amaembo / BenchmarkStreamConcat.java
Created Mar 31, 2020
Stream.concat vs StreamEx
View BenchmarkStreamConcat.java
package com.soebes.performance.streams;
import org.openjdk.jmh.annotations.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
View keybase.md

Keybase proof

I hereby claim:

  • I am amaembo on github.
  • I am tagir_valeev (https://keybase.io/tagir_valeev) on keybase.
  • I have a public key ASCH6kfJO8v94QIiMxjf6F-9bUZjiAGg5eoDfSUshwFNmAo

To claim this, I am signing this object:

View ToArrayTest.java
package com.example;
import org.openjdk.jmh.annotations.*;
import java.util.*;
import java.util.concurrent.*;import java.util.function.Supplier;import java.util.stream.Collectors;import java.util.stream.IntStream;
@Fork(3)
@Warmup(iterations=10, time=500, timeUnit=TimeUnit.MILLISECONDS)
@Measurement(iterations=10, time=500, timeUnit=TimeUnit.MILLISECONDS)
View February31.java
public class February31 {
public static final int[] kDaysInMonth = {
0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
};
boolean ValidateDateTime(DateTime time) {
if (time.year < 1 || time.year > 9999 ||
time.month < 1 || time.month > 12 ||
time.day < 1 || time.day > 31 ||
time.hour < 0 || time.hour > 23 ||
You can’t perform that action at this time.