Skip to content

Instantly share code, notes, and snippets.

View reevik's full-sized avatar
:octocat:

Erhan Bağdemir reevik

:octocat:
View GitHub Profile
#!/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
@EnableWebMvc
@Configuration
@EnableCaching
public class AppConfig implements WebMvcConfigurer {
@Bean
public RateLimiter rateLimiter() throws IOException {
return new RateLimiter(proxyManager(), bucketConfiguration());
}
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);
public class RateLimiter {
private final RedissonBasedProxyManager redissonBasedProxyManager;
private final BucketConfiguration bucketConfiguration;
public RateLimiter(RedissonBasedProxyManager redissonBasedProxyManager,
BucketConfiguration bucketConfiguration) {
this.redissonBasedProxyManager = redissonBasedProxyManager;
this.bucketConfiguration = bucketConfiguration;
}
// "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)
abstract class Option[+T] {
def flatMap[U](f: T => Option[U]) : Option[U] = this match {
case Some(x) => f(x)
case None => None
}
}
(1 to m).flatMap(i =>
(1 to n).filter(j => i > j)
map(k => (i, k)))
$ scala -Xprint:parser -e "for (i <- 1 to n; if i % 2 == 0) yield i"
(2,1), (3,1), (3,2), (4,1), (4,2), ...
for (i 1 to n; if i > j) yield (i, j)