Skip to content

Instantly share code, notes, and snippets.

View sureshg's full-sized avatar
🚀
☕️

Suresh sureshg

🚀
☕️
View GitHub Profile
@bric3
bric3 / IsATTY.java
Created June 8, 2021 15:42
Allows to determine if standard stream are connected to a terminal. Calls native isatty C function, and dynamically build the wrapper code.
/*
* MIT License
*
* Copyright (c) 2021 Brice Dutheil <[email protected]>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
@petrbouda
petrbouda / HttpInvocation.java
Last active June 22, 2024 19:00
Retry Mechanism for JDK HTTP Client
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.net.http.HttpResponse.BodyHandler;
import java.time.Duration;
import java.util.concurrent.CompletableFuture;
@normanmaurer
normanmaurer / Http3Server.java
Created December 1, 2020 09:28
Http3Server on top of netty
/*
* Copyright 2020 The Netty Project
*
* The Netty Project 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:
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@xian
xian / ConsoleFormatters.kt
Last active October 22, 2020 03:31
Chrome console formatters for Kotlin maps, sets, and lists
@file:Suppress("ObsoleteKotlinJsPackages")
package baaahs.util
import kotlin.browser.window
object ConsoleFormatters {
fun install() {
window.asDynamic().devtoolsFormatters = arrayOf(
map, set, list
// Using a hypothetical channel API, I assume I have channel `in` with a 4096-wide buffer,
// and a channel `out` writing to Kafka.
// lookupNodeInRedis and processOnServer have semaphores of, say, 16 and 8, to *globally* limit
// concurrent use of those resources.
var processingQueue = new BufferedChannel(50); // this buffer bounds the number of processing threads
// Consume and process input
Thread.startVirtualThread(() -> {
@DasBrain
DasBrain / Output.txt
Created April 15, 2020 13:33
Classes that have a public void close() but don't implement AutoCloseable
com/sun/jdi/connect/spi/Connection
com/sun/jndi/dns/BaseNameClassPairEnumeration
com/sun/jndi/dns/DnsClient
com/sun/jndi/dns/DnsContext
com/sun/jndi/dns/Resolver
com/sun/jndi/ldap/AbstractLdapNamingEnumeration
com/sun/jndi/ldap/LdapCtx
com/sun/jndi/ldap/LdapReferralContext
com/sun/jndi/ldap/LdapSchemaCtx
com/sun/jndi/ldap/ext/StartTlsResponseImpl
@androidfred
androidfred / kotlin_dsl.md
Last active February 27, 2021 01:26
Kotlin DSLs

Kotlin in Action: DSLs

General purpose programming language

  • imperative (sequence of stateful, ordered steps that describe how to do something)
  • wide scope
  • Java, Bash etc
  • potential for "runtime errors"

DSL (Domain Specific Language)

  • declarative (describes what something is, not how to do it)
@elizarov
elizarov / DeepRecursiveFunction.kt
Last active March 25, 2024 00:40
Defines recursive function that keeps its stack on the heap (productized version)
import kotlin.coroutines.*
import kotlin.coroutines.intrinsics.*
/**
* Defines deep recursive function that keeps its stack on the heap,
* which allows very deep recursive computations that do not use the actual call stack.
* To initiate a call to this deep recursive function use its [invoke] function.
* As a rule of thumb, it should be used if recursion goes deeper than a thousand calls.
*
* The [DeepRecursiveFunction] takes one parameter of type [T] and returns a result of type [R].
@naturalwarren
naturalwarren / CoinbaseRxJava2CallAdapterFactory.kt
Last active March 16, 2022 04:58
A Kotlin-esque API for Retrofit.
/**
* Copyright 2019 Coinbase, Inc.
*
* Licensed 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
*
* Unless required by applicable law or agreed to in writing,
/*
* Copyright (C) 2018 Square, Inc.
*
* Licensed 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
*
* Unless required by applicable law or agreed to in writing, software