Skip to content

Instantly share code, notes, and snippets.

View matey-jack's full-sized avatar

Robert Jack Will matey-jack

View GitHub Profile
@matey-jack
matey-jack / RestTemplateExtensions.kt
Last active November 14, 2019 10:19
Automatically append query string parameters during a call to Spring's RestTemplate
import org.springframework.http.ResponseEntity
import org.springframework.web.client.RestTemplate
/**
* This method behaves like 'getForEntity', but automatically extends the uriTemplate
* with the queryString part, adding only query parameters for which the value is not null.
* Map keys of the 'queryParams' will be used as keys in the queryString.
*
* See unit tests for excellent usage examples.
*
@matey-jack
matey-jack / UriComponentsBuilderEncodingTest.kt
Created November 7, 2019 17:16
Spring's UriComponentsBuilder -- get it encode optional characters is not quite trivial
import org.assertj.core.api.Assertions.assertThat
import org.assertj.core.api.Assertions.assertThatExceptionOfType
import org.junit.Test
import org.springframework.web.util.UriComponentsBuilder
import org.springframework.web.util.UriUtils
import java.nio.charset.StandardCharsets.UTF_8
class UrlTests {
@Test
fun weakEncode() {
@matey-jack
matey-jack / dl-list-mini.fs
Last active October 25, 2024 07:37 — forked from anonymous/dllist.rs
Simple doubly-linked list in safe Rust
//! A doubly-linked list in 50 LOCs of stable and safe Rust.
// Backup-fork of https://play.rust-lang.org/?gist=c3db81ec94bf231b721ef483f58deb35
use std::cell::RefCell;
use std::rc::{Rc, Weak};
use std::fmt::Display;
// The node type stores the data and two pointers.
//
// It uses Option to represent nullability in safe Rust. It has zero overhead
// over a null pointer due to the NonZero optimization.
@matey-jack
matey-jack / issues.md
Last active October 27, 2019 12:23
my skillset applied to Deno

TypeScript side of things:

  • none yet

Rust side:

  • Stringify for Log: denoland/deno#3165
  • CLI argument parsing: denoland/deno#3138 (after script name treat like after -- and always pass to script. then the assignment of args to deno/script will not depend on whether Deno knows the arg, but only on the position.) and denoland/deno#3011 (after -- not even script name should be fetched from args, Deno REPL instead entered)
  • using TypeScript language service in REPL: denoland/deno#3112

Docs and Website:

  • none yet
@matey-jack
matey-jack / bla.tf
Last active May 24, 2019 16:01
S3-Website with CDN and Custom Domain via Terraform
sdr
fun Project.getElasticMqInstanceByName(name: String) =
elasticmq().instances.getByName(serverName).elasticMqInstance
open class StartElasticMq
@Inject constructor(name: String) {
init {
group = "elasticmq"
description = "Starts the $name ElasticMQ Server Instance, if not running"
}
@matey-jack
matey-jack / Dart.md
Last active January 25, 2019 21:14
different languages – different results

Giving a different result on the exact same program is pretty confusing and the exact opposite of what Dart-lang stands for until now, namely simplicity and consistency.

If Dart-lang were ever to introduce optional semicolons then the only way out of not disagreeing with any of the above languages is to not allow the above expression to compile in the first place.

Looks like the current proposal for no-semicolons-Dart actually goes the Kotlin way: https://github.com/dart-lang/language/blob/terminating-tokens/working/terminating-tokens/feature-specification.md

@matey-jack
matey-jack / Readme.md
Last active January 26, 2019 18:24
Streaming in NodeJs: Processing a file much larger than available RAM

To try this out:

wget https://www.fec.gov/files/bulk-downloads/2018/indiv18.zip
unzip indiv18.zip
node find-most-frequent-name.js itcont.txt

The interesting thing is that while other solutions to the problem require to increase NodeJs' memory limits, we can even restrict the limit and use less memory:

node --max-old-space-size=300 find-most-frequent-name.js itcont.txt

@matey-jack
matey-jack / fun.spec.ts
Last active September 1, 2018 22:46
Four ways to define functions in TypeScript
import "jest";
// C-style declared function with block body
function increment_block(i: number): number {
return i + 1;
}
// original JavaScript inline function
const increment_var_keyword = function(i: number): number {
return i + 1;
@matey-jack
matey-jack / FunctionTest.kt
Last active September 1, 2018 16:34
Four ways to define functions in Kotlin
package i_introduction._4_Lambdas
import org.junit.Assert
import org.junit.Test
class FunctionTest {
// C-style declared function with block body
fun inc_block(i: Int): Int {
return i + 1
}