Skip to content

Instantly share code, notes, and snippets.

View GavinRay97's full-sized avatar

Gavin Ray GavinRay97

View GitHub Profile
@Sintrastes
Sintrastes / EmulateMultiReceivers.kt
Created October 15, 2021 18:53
Example of how to emulate multiple recievers with bounded polymorphism in Kotlin
interface Logging {
fun log(message: String)
}
interface Prompt {
fun promptUser(): String
}
fun <Ctx> Ctx.exampleFn() where Ctx: Logging, Ctx: Prompt {
@jharmer95
jharmer95 / property.hpp
Last active May 14, 2023 17:06
Class emulating properties for C++
#include <iostream>
#include <memory>
#include <type_traits>
#include <utility>
namespace not_std
{
template<typename T>
constexpr T default_getter(const T& val) noexcept
{
@davidfowl
davidfowl / MinimalAPIs.md
Last active May 8, 2024 02:30
Minimal APIs at a glance

Understanding Comparative Benchmarks

I'm going to do something that I don't normally do, which is to say I'm going to talk about comparative benchmarks. In general, I try to confine performance discussion to absolute metrics as much as possible, or comparisons to other well-defined neutral reference points. This is precisely why Cats Effect's readme mentions a comparison to a fixed thread pool, rather doing comparisons with other asynchronous runtimes like Akka or ZIO. Comparisons in general devolve very quickly into emotional marketing.

But, just once, today we're going to talk about the emotional marketing. In particular, we're going to look at Cats Effect 3 and ZIO 2. Now, for context, as of this writing ZIO 2 has released their first milestone; they have not released a final 2.0 version. This implies straight off the bat that we're comparing apples to oranges a bit, since Cats Effect 3 has been out and in production for months. However, there has been a post going around which cites various compar

@mukel
mukel / DynamicJava.java
Created June 14, 2021 20:45
Compiling Java code dynamically and running it in Espresso.
import java.lang.reflect.Method;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import org.graalvm.polyglot.Context;
import org.graalvm.polyglot.Value;
@GuillaumeDua
GuillaumeDua / Concept-based polymorphism in modern Cpp.md
Last active May 4, 2024 09:30
Concept-based polymorphism in modern C++

Concept-based polymorphism in modern C++

Date 05-05-2021 - 10-17-2023
Revision R3
Author Guillaume Dua
Reviewers Loïc Joly, Antoine Morrier
@mayankmkh
mayankmkh / PrettyPrint.kt
Last active April 11, 2024 11:52
Pretty Print Kotlin Data Class
fun Any.prettyPrint(): String {
var indentLevel = 0
val indentWidth = 4
fun padding() = "".padStart(indentLevel * indentWidth)
val toString = toString()
val stringBuilder = StringBuilder(toString.length)
@danngreen
danngreen / Makefile-compilecommands.mk
Created November 24, 2020 20:45
Makefile command to generate compile_commands.json with entries for c++ headers
# Addresses an issue where language servers won't know what to do with header files
# since compile_commands.json typically only includes .cc/.cpp/.c files.
#
# Include this file from your main Makefile, or just paste the snippet in.
# To use:
# make compile_commands
# Requires bear and compdb
# bear [osx]: brew install bear
# compdb [see https://github.com/Sarcasm/compdb]: pip install compdb
@bokwoon95
bokwoon95 / comments.sql
Last active March 22, 2024 22:31
how to model threaded comments (e.g. reddit comments) in SQL with a simple 'ancestors' column
-- how to model threaded comments (e.g. reddit comments) in SQL with a simple 'ancestors' column
-- The comment tree:
-- [1]
-- / \
-- [2] [4]
-- / \ \
-- [3] [7] [6]
-- /
-- [5]
@webstrand
webstrand / 000~nonempty-validator.ts
Last active June 20, 2023 16:37
Examples of the <T>(foo: Validator<T>) pattern in typescript
/******************************************************************************
* Implementation of `Nonempty` validator which checks that the provided type
* has at least one defined property, excluding `{}`.
******************************************************************************/
type Nonempty<T extends { [key: string]: any }> = { [P in keyof T]: T }[keyof T];
declare function wantsNonempty<T extends { [key: string]: any }>(x: Nonempty<T>): true;
wantsNonempty({ x: 1 });
wantsNonempty({}); // error expected