Skip to content

Instantly share code, notes, and snippets.

@ptomaszek
ptomaszek / oracle_sequence_bump.sql
Created February 28, 2023 10:33
oracle sequence bump
DECLARE
V_VAL NUMBER;
BEGIN
FOR V_I IN 1..50
LOOP
EXECUTE IMMEDIATE 'SELECT BATCH_STEP_EXECUTION_SEQ.NEXTVAL FROM DUAL' into V_VAL;
END LOOP;
END;
-- or
echo 'export PATH=~/bin:$PATH' >> ~/.bash_profile
source ~/.bash_profile
@ptomaszek
ptomaszek / impersonate.sh
Created July 27, 2022 10:45
linux impersonate user run command
sudo -u otheruser bash -l
#or one-liner
sudo -n -u otheruser -- /usr/bin/bash -c "export JAVA_HOME=/apps/java/jdk1.8.0_281; cd /apps/hello/; ./install.sh"
@ptomaszek
ptomaszek / creating selfsigned.jks
Created July 27, 2022 06:41
Tomcat 8.5 self signed certificate HTTPS TLS SSL
jdk/bin/keytool -genkey -keyalg RSA -noprompt -alias tomcat -dname "CN=localhost, OU=NA, O=NA, L=NA, S=NA, C=NA" -keystore tomcat8/selfsigned.jks -validity 9999 -storepass changeme -keypass changeme
@ptomaszek
ptomaszek / healthcheck.sh
Last active June 21, 2022 11:56
health check bash - curl expecting http status code with retry and timeout
# Call page expecting particular HTTP resp code; if condition not met, retry every 15s for 2 minutes
HEALTH_CHECK_URL=https://example.com
EXPECTED_HEALTH_CHECK_HTTP_RESPONSE_CODE=200
timeout 120 bash -c 'while [[ "$(curl -s -o /dev/null -w ''%{http_code}'' '$HEALTH_CHECK_URL')" != '$EXPECTED_HEALTH_CHECK_HTTP_RESPONSE_CODE' ]]; do sleep 15; done' || false
echo $? # 0 for success, 1 for failure
@ptomaszek
ptomaszek / UglyLoggerReplacer.java
Last active March 18, 2022 12:10
Replace loggers with @slf4j from Lombok
import lombok.SneakyThrows;
import org.apache.commons.lang3.StringUtils;
import java.io.File;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
Similar to: https://www.reddit.com/r/bashonubuntuonwindows/comments/mgpla3/xfce4_works_when_xserver_is_in_multiple_windows/
Error:
/usr/bin/startxfce4: X server already running on display
Unable to open display.
xfce4-panel: Cannot open display: .
Solution:
@ptomaszek
ptomaszek / TreeNode.java
Last active July 11, 2021 15:23
Helps to build a TreeNode for some LeetCode challenges
/**
* Definition from LeetCode
*/
public class TreeNode {
int val;
TreeNode left;
TreeNode right;
TreeNode() {
}
@ptomaszek
ptomaszek / CacheableClientImpl.groovy
Last active January 13, 2021 17:45
Caffeine cache in Vert.x; mapping between Future and CompletableFuture;
import com.github.benmanes.caffeine.cache.AsyncCacheLoader
import com.github.benmanes.caffeine.cache.AsyncLoadingCache
import com.github.benmanes.caffeine.cache.Caffeine
import groovy.util.logging.Slf4j
import io.vertx.core.Context
import io.vertx.core.Future
import io.vertx.core.Promise
import io.vertx.core.Vertx
import java.time.Duration
@ptomaszek
ptomaszek / _Http2Server.groovy
Last active January 9, 2021 13:11
Vertx 3.9 - HTTP/2 Server and Client
//curl --write-out --http2 --insecure https://localhost:8083
import io.vertx.core.Vertx
import io.vertx.core.http.HttpServerOptions
import io.vertx.core.net.PemKeyCertOptions
def vertx = Vertx.vertx()
vertx
.createHttpServer(new HttpServerOptions()