Skip to content

Instantly share code, notes, and snippets.

import javax.swing.*;
import java.awt.*;
import java.util.List;
import java.util.ArrayList;
import java.awt.geom.*;
import java.awt.image.BufferedImage;
public class DemoViewer {
public static void main(String[] args) {
package org.rogach.jopenvoronoi;
import java.io.*;
import java.util.*;
import java.awt.geom.Point2D;
import java.awt.Color;
// random polygon generator
// uses space partitioning algorithm, described here: http://www.geometrylab.de/applet-29-en#space
public class RandomPolygon {
@Rogach
Rogach / test.gradle
Last active February 2, 2023 15:18
searching for java8-openjfx build issue
ext.javaBinary = "/usr/lib/jvm/java-8-openjdk/bin/java"
def inStream = new java.io.BufferedReader(new java.io.InputStreamReader(new java.lang.ProcessBuilder(ext.javaBinary, "-version").start().getErrorStream()));
try {
String line = inStream.readLine();
while (line != null) {
if (line.contains("Runtime Environment (build ")) {
int ib = line.indexOf(" (build ");
if (ib != -1) {
String ver = line.substring(ib + 8, line.size() - 1);
project.ext.set("jdkRuntimeVersion", ver);
@Rogach
Rogach / input.tsv
Created March 1, 2021 11:36
issue when copying contents of a file into a variable
We can make this file beautiful and searchable if this error is corrected: No tabs found in this TSV file in line 0.
TTTфTфTффффTTTффTфффффTTTTфTTTффTTфTTфTTTфTффффT
ффTфTTTTTTфTTTTффффTTTфTффTTфффTфTTTфTфффTTTTTTT
фффTфTTTфффTфTфффффTффTффTTTфффTTфTффффTTTфффTфф
TTTфффTTффTфTфффTфффффффTTффTTфTфффTTффффTTфTффT
ффTTфTTфTфTTTфTфффффффффTфTTTффTфTTTTTфTTTTTTфTT
фффTфTффTфффTTTTффTTTфффTффTфTффTффTфTффTTфTTTфф
ффTфTфTTTTффTфTфффTTфффTфTфффTTTTффTTTTфTффTфффT
import sys
import math
range_min = int(sys.argv[1])
range_max = int(sys.argv[2])
def calculate_square_depth(range_min, range_max):
if range_max <= 3:
return 0
min_bound = math.ceil(range_min**0.5)
public class GetProperties {
public static void main(String[] args) {
System.out.println(System.getProperties());
}
}
import org.rogach.scallop._
import java.io.{Serializable, ByteArrayOutputStream, ByteArrayInputStream, ObjectOutputStream, ObjectInputStream}
val args = Array("--apples", "33")
private class ConfSerializationProxy(@transient private var orig: Conf) extends Serializable {
private def writeObject(out: ObjectOutputStream) {
out.defaultWriteObject()
out.writeObject(orig.args.toArray)
}
;; input is from https://adventofcode.com/2015/day/6
(def W 1000)
(def input (clojure.string/split-lines (slurp "d06.txt")))
(defmacro control-lights [lights x1 y1 x2 y2 f]
(let [i (gensym)]
`(doseq [ x# (range ~x1 (inc ~x2))
y# (range ~y1 (inc ~y2))
:let [ ~i (+ (* y# W) x#) ] ]
(def W 1000)
(def input (clojure.string/split-lines (slurp "d06.txt")))
(let [lights (boolean-array (* W W))]
(doseq [s input]
(let [ m (re-matches #"(turn on|turn off|toggle) (\d+),(\d+) through (\d+),(\d+)" s)
command (get m 1)
x1 (Integer/parseInt (get m 2))
y1 (Integer/parseInt (get m 3))
x2 (Integer/parseInt (get m 4))
y2 (Integer/parseInt (get m 5)) ]
@Rogach
Rogach / Test.scala
Last active October 5, 2018 12:27
scallop #137 bug
import org.rogach.scallop._
import java.io.{Serializable, ByteArrayOutputStream, ByteArrayInputStream, ObjectOutputStream, ObjectInputStream}
trait PropsArgument extends ScallopConf {
@transient val p: Map[String, String] = props[String]('D')
}
class TestConf(args: List[String]) extends ScallopConf(args) with Serialization with PropsArgument {
val apples = opt[Int]("apples")
verify()