Skip to content

Instantly share code, notes, and snippets.

View onacit's full-sized avatar

Jin Kwon onacit

  • WeMakePrice
  • Seoul, Korea
View GitHub Profile
@onacit
onacit / docker.gradle.sh
Last active November 10, 2021 12:38
Using docker for building a gradle project with alternative JDKs
#!/bin/sh
# https://gist.github.com/onacit/036c93befff929a1f43b7603aa0b65bb
if [ $# -lt 3 ]; then
echo "Usage: $0 <tag> <tasks...>, e.g. $0 6.0.1-jdk11 -Pprofile=local clean build"
echo "See https://hub.docker.com/_/gradle for available tags"
exit 1
fi
tag="$1"
shift
name=$(basename "$PWD")
@onacit
onacit / docker.maven.sh
Last active December 16, 2021 03:12
Using docker for building a maven project with alternative JDKs.
#!/bin/sh
# https://gist.github.com/onacit/9f79215aaf6bd8d59e78ed6a38b93889
# https://stackoverflow.com/questions/3545292/how-to-get-maven-project-version-to-the-bash-command-line
if [ $# -lt 2 ]; then
echo "Usage: $0 <tag> <phases...>, e.g. $0 3-jdk-11-openj9 clean install"
echo "See https://hub.docker.com/_/maven for available tags"
exit 1
fi
groupId=$(mvn help:evaluate -Dexpression=project.groupId | grep -v '\[')
artifactId=$(mvn help:evaluate -Dexpression=project.artifactId | grep -v '\[')
@onacit
onacit / SelectionSort.java
Last active October 24, 2021 06:21
Selection sort in Java
package p_0dd925d3768fcd4f79494ae32905dc1b;
import java.util.Comparator;
import java.util.List;
import static java.util.Objects.requireNonNull;
/**
* A class implements <a href="https://en.wikipedia.org/wiki/Selection_sort">Selection sort</a>.
*
@onacit
onacit / MontyHallProblem.java
Last active November 9, 2019 14:21
Run Monty Hall Problem with Random
import java.security.*;
import java.util.*;
import java.util.concurrent.atomic.*;
public class MontyHallProblem {
//private static final long COUNT = 1048576L;
private static final long COUNT = 30000L;
static { assert COUNT > 0L; }
private static final int DOORS = 3;
static { assert DOORS > 0; }
public static void main(final String... args) throws Exception {
@onacit
onacit / ChronoUnitMatrix.java
Last active December 2, 2018 08:51
Prints information from java.time.temporal.ChronoUnit.
import java.time.temporal.*;
public class ChronoUnitMatrix {
public static void main(final String... args) {
System.out.printf("%-10s%-6s%-6s%s\n", "name", "time", "date",
"duration (estimated) (seconds)");
System.out.printf("%-10s%-6s%-6s%s\n", "---------", "-----", "-----",
"---------------------------------------------------------------");
for (final ChronoUnit value : ChronoUnit.values()) {
@onacit
onacit / Fibonacci.java
Last active November 30, 2018 09:18
Get fibonacci number of given nth term.
import java.math.BigInteger;
public class Fibonacci {
public static void main(final String... args) {
final int n = Integer.parseInt(args[0]);
if (n < 0) {
throw new IllegalArgumentException("n(" + n + ") is negative");
}
if (n == 0) {
@onacit
onacit / main.c
Last active June 18, 2018 06:58
Main function of C
#include <assert.h>
#include <stdio.h>
/*
* 5.1.2.2.1 Program startup
* N1548
*/
int main(int argc, char *argv[]) {
// The value of argc shall be nonnegative.
assert(argc >= 0);