Skip to content

Instantly share code, notes, and snippets.

@fadi-botros
fadi-botros / BenchmarkDependencyInjection.cpp
Created September 25, 2021 16:04
Quick-Benchmarking C++ unique_ptr vs callbacks when trying to use interfaces and dependency injection
#include <memory>
template<typename Parameter>
class Consumer {
public:
virtual void call(const Parameter &obj) const = 0;
virtual ~Consumer() {}
};
template<typename Callable, typename Parameter>
@fadi-botros
fadi-botros / KotlinCoroutinesTry.kt
Created June 3, 2021 07:44
A Kotlin Coroutine snippet trying to simulate what happens in Spring WebFlux
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.withContext
import java.util.concurrent.Executor
import java.util.concurrent.Executors
import kotlin.coroutines.suspendCoroutine
// Simulate what may happen in Spring WebFlux, where a Spring call your functions in their executors
suspend fun resumeOnSpecificJavaExecutor(javaExecutor: Executor) = suspendCoroutine<Int> {
javaExecutor.execute { it.resumeWith(Result.success(1)) }
#include <iostream>
#include <optional>
#include <string>
#include <memory>
// Protocol oriented approach for lazy initialization.
// Would be better of course when Concepts would be released.
// Demonstrated in int, std::unique_ptr, and std::optional
template<typename T>
@fadi-botros
fadi-botros / ManualLayoutView.swift
Created June 6, 2019 21:24
Swift trying to use manual layout
import UIKit
class TryView: UIView {
let label: UILabel
let textField: UITextField
required init?(coder: NSCoder) {
fatalError("Not implemented")
}
@fadi-botros
fadi-botros / results.json
Created May 1, 2018 19:03
results.json when trying TechEmpower Framework Benchmark script on the code. https://gist.github.com/fadi-botros/b8276bb5e2b83a63045877aeb7415f34
{
"environmentDescription": "(unspecified, hostname = tfb-all)",
"git": null,
"cachedQueryIntervals": [
1,
10,
20,
50,
100
],
@fadi-botros
fadi-botros / main.swift
Created May 1, 2018 18:27
Trying doing TechEmpower Framework Benchmark on SwiftNIO (only JSON and Plain text)
import Foundation
import NIO
import NIOHTTP1
struct Message: Codable {
var message: String
}
let dateFormatter: DateFormatter = {
let ret = DateFormatter.init()