This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
moshtel_web="https://camper-park-wacken.de" | |
md5=`curl -s -X GET $moshtel_web | md5sum | awk -F' ' '{print $1}'` | |
if [ ! -e /var/tmp/$md5 ] | |
then | |
osascript -e 'display notification "You should check out: '$moshtel_web'" with title "Moshtel Alarm"' | |
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@EnableWebMvc | |
@Configuration | |
@EnableCaching | |
public class AppConfig implements WebMvcConfigurer { | |
@Bean | |
public RateLimiter rateLimiter() throws IOException { | |
return new RateLimiter(proxyManager(), bucketConfiguration()); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public boolean preHandle( | |
HttpServletRequest request, | |
HttpServletResponse response, | |
Object handler) { | |
Map<String, String> pathVars = (Map<String, String>) | |
request.getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE); | |
if (!rateLimiter.tryAccess(pathVars.get(USER_ID))) { | |
response.setStatus(TOO_MANY_REQUEST); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class RateLimiter { | |
private final RedissonBasedProxyManager redissonBasedProxyManager; | |
private final BucketConfiguration bucketConfiguration; | |
public RateLimiter(RedissonBasedProxyManager redissonBasedProxyManager, | |
BucketConfiguration bucketConfiguration) { | |
this.redissonBasedProxyManager = redissonBasedProxyManager; | |
this.bucketConfiguration = bucketConfiguration; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// "x => x + 1" could be reduced to "_ + 1" using placeholder syntax. | |
> Some(10) flatMap(x => x + 1) | |
res0: Option[Int] = Some(45) | |
> Some(10) flatMap(x => None) | |
res0: Option[Nothing] = None | |
> List(Some(1), None, Some(3), None).map(a => \ | |
a.flatMap(b => Some(b + 1))) | |
res0: List[Option[Int]] = List(Some(2), None, Some(4), None) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
abstract class Option[+T] { | |
def flatMap[U](f: T => Option[U]) : Option[U] = this match { | |
case Some(x) => f(x) | |
case None => None | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(1 to m).flatMap(i => | |
(1 to n).filter(j => i > j) | |
map(k => (i, k))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ scala -Xprint:parser -e "for (i <- 1 to n; if i % 2 == 0) yield i" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(2,1), (3,1), (3,2), (4,1), (4,2), ... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for (i 1 to n; if i > j) yield (i, j) |
NewerOlder