Skip to content

Instantly share code, notes, and snippets.

View e5l's full-sized avatar

Leonid Stashevsky e5l

View GitHub Profile
class Timeouts {
class Config(var postRequestTimeout: Long = 5000L)
companion object : ApplicationFeature<ApplicationCallPipeline, Config, Unit> {
override val key: AttributeKey<Unit> = AttributeKey("Timeouts")
override fun install(pipeline: ApplicationCallPipeline, configure: Config.() -> Unit) {
val postTimeout = Config().apply(configure).postRequestTimeout
if (postTimeout <= 0) return
@e5l
e5l / build.gradle.kts
Created June 15, 2020 08:52
XML serialization with ktor client
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
kotlin("jvm") version "1.3.72"
kotlin("plugin.serialization") version "1.3.72"
application
}
group = "me.leonid"
version = "1.0-SNAPSHOT"
(function(root, factory) {
if (typeof define === 'function' && define.amd)
define(['exports', 'kotlin', 'ktor-utils', 'kotlinx-io', 'kotlinx-coroutines-core', 'ktor-http', 'kotlinx-coroutines-io'], factory);
else if (typeof exports === 'object')
factory(module.exports, require('kotlin'), require('ktor-utils'), require('kotlinx-io'), require('kotlinx-coroutines-core'), require('ktor-http'), require('kotlinx-coroutines-io'));
else {
if (typeof kotlin === 'undefined') {
throw new Error("Error loading module 'ktor-client-core'. Its dependency 'kotlin' was not found. Please, check whether 'kotlin' is loaded prior to 'ktor-client-core'.");
}
if (typeof this['ktor-utils'] === 'undefined') {
@e5l
e5l / build.gradle
Last active January 17, 2019 06:06
gradle publishing hacks
// 4.7
publishing {
publications {
foo {
gradleModuleMetadataFile = null
tasks.matching { it.name == "generateMetadataFileFor${name.capitalize()}Publication" }.all { onlyIf { false } }
}
}
}
@e5l
e5l / sort?.cpp
Last active February 13, 2018 06:06
Debug me
int s3(int *a,int s2,int e1,int s1,int e2,int* m1,int* m2);
int s4(int* a,int l){
int s=0, *m1=(int *)malloc(l*sizeof(int)), *m2=(int *)malloc(l*sizeof(int));
if(!m1&&!m2)return -1;
while (s<l) {
int i,s1,e1,s2,e2;
for(i=0;(i+s-1)<(l-1);i+=2*s){
s1=i;
@e5l
e5l / rational.hpp
Created November 16, 2017 15:17
Rational
#pragma once
#include <iostream>
#include <cstdlib>
class rational;
bool operator==(const rational &lhs, const rational &rhs);
bool operator!=(const rational &lhs, const rational &rhs);
// FILE: A.java
import kotlin.internal.*;
public class A {
public void foo(@DefaultNull Integer i) {}
public void bar(@DefaultNull Integer a) {}
public void bam(@DefaultNull Integer a) {}
// FILE: A.java
import kotlin.internal.*;
class A {
public void first(@DefaultValue(value = "42") int arg) {
}
}
// FILE: B.java
class B {
@e5l
e5l / latency.txt
Created February 28, 2017 13:53 — forked from jboner/latency.txt
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers
--------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us
Send 1K bytes over 1 Gbps network 10,000 ns 10 us
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD
Atom config sync