Skip to content

Instantly share code, notes, and snippets.

class Example extends Specification {
def "test"() {
given:
Cls cls = Spy(new Cls())
when:
cls.m()
then:
@attacco
attacco / gist:e878e3896d0ac0e809e8f671e7d42421
Created October 8, 2024 18:32
КВАС: решение с популярным сервисом для голосового общения
[discord]
*dis.gd
*discord-activities.com
*discord.co
*discord.com
*discord.design
*discord.dev
*discord.gg
*discord.gift
*discord.gifts
import java.time.Instant
import java.util.concurrent.ConcurrentHashMap
import java.util.concurrent.TimeUnit
import java.util.concurrent.atomic.AtomicLong
class LoadingCache<K : Any, V : Any>(
private val maxReuses: Int, // how many times it's possible to SEQUENTIALLY reuse previously cached value in case of loading failure
private val loader: (key: K, oldValue: V?) -> V,
private val ttlResolver: (state: State<V>, timestamp: Instant) -> Instant
) {
public class ResourceUtils {
// example: ${date:DD.MM}
private static final Pattern DATE_TIME_PLACEHOLDER_PATTERN =
Pattern.compile("\\$\\{(?<value>date:[\\w.:\\-\\s/\\\\]+)}");
// examples: ${number:N}
private static final Pattern NUMBER_PLACEHOLDER_PATTERN =
Pattern.compile("\\$\\{(?<value>number:[\\w.:\\-\\s/\\\\?]+)}");
private static final Map<String, Formatter> FORMATTERS = Stream.of(
// variant A:
if (fromDateTimeMs != null) {
where.and(timeColumn.goe(new Timestamp(fromDateTimeMs)));
}
if (tillDateTimeMs != null) {
where.and(timeColumn.lt(new Timestamp(tillDateTimeMs)));
}
// variant B:
Stream.of(
public static void main(String[] args) {
final Stream s1 = Stream.generate(new Supplier<String>() {
private final AtomicInteger cnt = new AtomicInteger();
@Override
public String get() {
sleep();
return "A" + String.valueOf(cnt.incrementAndGet());
}
});
@attacco
attacco / Homoglyphs.java
Created September 13, 2017 21:54
Homoglyphs directory.
import javax.annotation.Nullable;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
public class Homoglyphs {
private static final List<char[]> LIST = Arrays.asList(
prepare("! ǃ !"),
// first, create custom qualifier annotation
@Target({ElementType.METHOD, ElementType.ANNOTATION_TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Qualifier
public @interface CustomAnn {
Class<?> any();
}
// now create an annotation, that "inherits" from CustomAnn, specifying it's "any" property
@Target({ElementType.METHOD})
@attacco
attacco / install_instant_client.sh
Created July 18, 2017 13:49
Oracle Instant Client installation script
#!/bin/bash
export VERSION=11.2.0.4.0
export ORACLE_CLIENT=/usr/local/lib/share/oracle/$VERSION
mkdir -p $ORACLE_CLIENT
tar -xzf instantclient-basic-macos.x64-$VERSION.zip --strip-components=1 -C $ORACLE_CLIENT
tar -xzf instantclient-sqlplus-macos.x64-$VERSION.zip --strip-components=1 -C $ORACLE_CLIENT
cd $ORACLE_CLIENT
@attacco
attacco / URLWrapUtil.java
Created April 28, 2016 23:09
Method to wrap URL's in plain text to 'a href...' elements, like in html.
import java.util.Map;
import java.util.NavigableMap;
import java.util.TreeMap;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class URLWrapUtil {
private final static Pattern A_HREF_PATTERN = Pattern.compile("(?i)<a\\s+href\\s*=\\s*\".+\"\\s*>.+<\\s*/\\s*a\\s*>");
// Copied (and optimized) from android.util.Patterns#WEB_URL (SDK 23)