Skip to content

Instantly share code, notes, and snippets.

@korzha
korzha / pattern.js
Last active September 15, 2022 17:01
//const pattern = 'XXXXXXXXXXXXIIXXXX'
const digitsRe = new RegExp('/^\d+$/')
function test(str) {
if (str.length == 0) return false
// part 1: check that first at most 12 characters are only numbers
let end = Math.min(12, str.length)
if !digitsRe.test(str.substring(0, end)) return false
// part 3: check that at most 4 characters after 12 digits and 2 any chars are only numbers
end = Math.min(12 + 2 + 4, str.length)
@korzha
korzha / Main.java
Created September 27, 2019 07:05
PINs generator problem
import java.util.Collection;
import java.util.Objects;
import java.util.TreeSet;
public class Main {
public static void main(String[] args) {
assertEquals("0,5,7,8,9", getPossiblePins("8"));
assertEquals("11,12,14,21,22,24,41,42,44", getPossiblePins("11"));
assertEquals("13,15,16,19,43,45,46,49,53,55,56,59,73,75,76,79", getPossiblePins("46"));
}
@korzha
korzha / install-adoptjdk-10.sh
Created September 27, 2018 15:22
Script to download and install AdoptOpenJDK 10 to /Library/Java/JavaVirtualMachines
#!/usr/bin/env bash
set -e
# Returns latest jdk 10 version, e.g. jdk-10.0.2+13
JDK=$(curl --silent "https://api.github.com/repos/AdoptOpenJDK/openjdk10-releases/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')
# 10.0.2+13
VERSION=$(basename "${JDK}" | awk -F"-" '{ print $2 }')
# 10.0.2
@korzha
korzha / Info.plist
Last active September 27, 2018 13:59
AdoptJDK10 mac os metadata file
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleExecutable</key>
<string>libjli.dylib</string>
<key>CFBundleIdentifier</key>
<string>net.adoptopenjdk.jdk10</string>
public class Scratch implements EntryPoint {
@Override
public void onModuleLoad() {
testStream(1, 2, 3);
}
private String createString(Integer n) {
return "" + n;
}
public static CompletableFuture<String> getUrlBytes(String url) {
CompletableFuture<String> future = new CompletableFuture<>();
final XMLHttpRequest req = new XMLHttpRequest();
req.open("GET", url, true);
req.setOnreadystatechange((e) -> {
if (req.status == 200) {
future.complete(req.response);
} else {
future.completeExceptionally(new Exception(req.statusText));
ArrayList<Throwable> throwables = new ArrayList<>();
onClose.forEach((runnable) -> {
try {
runnable.run();
} catch (Throwable e) {
throwables.add(e);
}
});
if (!throwables.isEmpty()) {
Throwable e = throwables.get(0);
#!/usr/bin/env bash
FILESTORE_DIR="$1"
if [ -z "$FILESTORE_DIR" ]; then
FILESTORE_DIR="`pwd`/filestore"
fi
function install_artifact() {
IFS=':' read -a array <<< "$1"
GROUP_ID="${array[0]}"
@Module(complete = false, library = true)
public class ProtocolModule {
@Provides
@Singleton
Executor provideExecutor(TaskExecutorImpl executor) {
return executor;
}
@Provides
public static String toPath(String... names) {
StringBuilder sb = new StringBuilder(getCharCount(names) + names.length - 1);
for (String s : names) {
sb.append(s).append(File.separator);
}
if (sb.length() > 0) {
sb.deleteCharAt(sb.length() - 1);
}
return sb.toString();
}