XOR two byte arrays in scala

This time just a little method for xor’ing to byte arrays in scala. Nothing to fancy 😉

 

GD Star Rating
loading...

Sliding iterator for scala

I’m falling more and more in love with scala’s collection api. There ist so many really awesome stuff already implemented that normally drives you mad when you have to implment by yourself.
I was writing a check that should check if a field contains a string that was produced by „stroking“ the keyboard. Just typing for example qwertzui instead of anything useful. So I added a method to check against those string vom q to p. But of course I also wanted to add the possibility to check against a substring with a given length of that string. There comes the sliding iterator into play:

 

GD Star Rating
loading...

Service flood / denial of service protection with scala and Google Guava

A common problem for webservices that are exposed to the public is the threat of beeing flooded or atttacked by a denial of service attack. To be honest I think that especially for distributed dos there is no real protection and even for dos the protection should be mainly in components like load balancers, firewalls, … and not in the application itself. But anyway it is useful to be able to handle that also in the application and at least that also provides a good way to restrict access to certain service endpoints in a given amount of time.

This solution is based on Google Guava RateLimiter and therefore works only within one application server instance. If you need such a solution of multiple instances Hazelcast or Redis might be good solutions for you. Both have an easy to use TTL feature.

Anyway here is my solution for a trait that can be easly mixed in any service class:

maven dependency:

scala code:

 

 

 

GD Star Rating
loading...