Skip to content

Instantly share code, notes, and snippets.

View daniellansun's full-sized avatar

Daniel Sun daniellansun

View GitHub Profile
import java.time.*
import java.util.concurrent.*
import java.util.concurrent.atomic.*
def atomicInteger = new AtomicInteger()
def runnable = () -> {
atomicInteger.incrementAndGet()
}
def start = Instant.now()

Create Root CA (Done once)

Create Root Key

Attention: this is the key used to sign the certificate requests, anyone holding this can sign certificates on your behalf. So keep it in a safe place!

openssl genrsa -des3 -out rootCA.key 4096
@daniellansun
daniellansun / App.java
Created April 26, 2022 14:37 — forked from thomasdarimont/App.java
Example for defining a refreshable Groovy Script in Spring Boot with Java Config - at least thats the current state of affairs :)
package demo;
import java.util.concurrent.TimeUnit;
import org.springframework.aop.TargetSource;
import org.springframework.aop.framework.ProxyFactory;
import org.springframework.aop.support.DelegatingIntroductionInterceptor;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@daniellansun
daniellansun / DemoApplication.java
Created April 22, 2022 02:26 — forked from ehdez73/DemoApplication.java
Create Beans programatically with Spring Boot
package com.example;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
@daniellansun
daniellansun / SimpleFuture.java
Created May 5, 2021 13:40 — forked from klausbrunner/SimpleFuture.java
A very simple implementation of the Java Future interface, for passing a single value to some waiting thread. Uses a CountdownLatch to ensure thread safety and provide blocking-with-timeout functionality required by Future. Cancellation isn't supported.
public final class ResultFuture implements Future<Result> {
private final CountDownLatch latch = new CountDownLatch(1);
private Result value;
@Override
public boolean cancel(boolean mayInterruptIfRunning) {
return false;
}
@Override
@daniellansun
daniellansun / GenerateMultiplicationTable.groovy
Created November 7, 2020 16:10
Generate Multiplication Table with GINQ
GQ {
from v in (
from a in 1..9
innerjoin b in 1..9 on a <= b
select a as f, b as s, "$a * $b = ${a * b}".toString() as r
)
groupby v.s
select max(v.f == 1 ? v.r : '') as v1,
max(v.f == 2 ? v.r : '') as v2,
max(v.f == 3 ? v.r : '') as v3,
@daniellansun
daniellansun / UsesGroovyShell.groovy
Created December 28, 2019 17:09 — forked from itzg/UsesGroovyShell.groovy
Enabling Groovy invokedynamic ("indy") support in a Gradle build
// ....
def compilerConfig = new CompilerConfiguration()
compilerConfig.optimizationOptions.indy = true
def shell = new GroovyShell(compilerConfig)
// Show some new features of Groovy3
// The complete new feature list can be found at:
// https://github.com/danielsun1106/groovy-parser
@groovy.transform.CompileStatic
def helloGroovy3() {
File f = new File("D:/hello-groovy${1 + 2}.txt")
try (Writer out = new FileWriter(f)) { // try-with-resources
out <<
['hello', 'groovy3', 'Hello', 'Groovy3'].stream()
@daniellansun
daniellansun / CountLines.groovy
Last active February 20, 2019 23:40
Count the line count of source files
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0

Squashing Git Commits

The easy and flexible way

This method avoids merge conflicts if you have periodically pulled master into your branch. It also gives you the opportunity to squash into more than 1 commit, or to re-arrange your code into completely different commits (e.g. if you ended up working on three different features but the commits were not consecutive).

Note: You cannot use this method if you intend to open a pull request to merge your feature branch. This method requires committing directly to master.

Switch to the master branch and make sure you are up to date: